Class: Rails::Pseudoloc::Backend

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rails/pseudoloc/backend.rb

Overview

An I18n::Backend that pseudolocalizes all translations requested of it and delegates to another backend for the actual translations and localizations.

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ Backend

Creates a pseudolocalized backend that gets all its translations from ‘backend`.



13
14
15
16
17
# File 'lib/rails/pseudoloc/backend.rb', line 13

def initialize(backend)
  super(backend)

  @codec = Codec.new
end

Instance Method Details

#translate(locale, key, options = {}) ⇒ Object

Pseudolocalizes the translation returned from the actual backend.



20
21
22
23
24
# File 'lib/rails/pseudoloc/backend.rb', line 20

def translate(locale, key, options = {})
  value = __getobj__.translate(locale, key, options)

  value.is_a?(String) ? @codec.encode(value) : value
end