Class: GettextI18nRails::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext_i18n_rails/backend.rb

Overview

translates i18n calls to gettext calls

Constant Summary collapse

@@translate_defaults =
true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Backend

Returns a new instance of Backend.



8
9
10
# File 'lib/gettext_i18n_rails/backend.rb', line 8

def initialize(*args)
  self.backend = I18n::Backend::Simple.new(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



25
26
27
# File 'lib/gettext_i18n_rails/backend.rb', line 25

def method_missing(method, *args)
  backend.send(method, *args)
end

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



6
7
8
# File 'lib/gettext_i18n_rails/backend.rb', line 6

def backend
  @backend
end

Instance Method Details

#available_localesObject



12
13
14
# File 'lib/gettext_i18n_rails/backend.rb', line 12

def available_locales
  FastGettext.available_locales || []
end

#translate(locale, key, options) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/gettext_i18n_rails/backend.rb', line 16

def translate(locale, key, options)
  if gettext_key = gettext_key(key, options)
    translation = FastGettext._(gettext_key)
    interpolate(translation, options)
  else
    backend.translate locale, key, options
  end
end