Class: GettextI18nRails::Backend
- Inherits:
-
Object
- Object
- GettextI18nRails::Backend
- 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
-
#backend ⇒ Object
Returns the value of attribute backend.
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#initialize(*args) ⇒ Backend
constructor
A new instance of Backend.
- #method_missing(method, *args) ⇒ Object
- #translate(locale, key, options) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
36 37 38 |
# File 'lib/gettext_i18n_rails/backend.rb', line 36 def method_missing(method, *args) backend.send(method, *args) end |
Instance Attribute Details
#backend ⇒ Object
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_locales ⇒ Object
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 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gettext_i18n_rails/backend.rb', line 16 def translate(locale, key, ) flat_key = flatten_key key, if FastGettext.key_exist?(flat_key) raise "no yet build..." if [:locale] _(flat_key) else if self.class.translate_defaults [*[:default]].each do |default| #try the more specific key first e.g. 'activerecord.errors.my custom message' flat_key = flatten_key default, return FastGettext._(flat_key) if FastGettext.key_exist?(flat_key) #try the short key thereafter e.g. 'my custom message' return FastGettext._(default) if FastGettext.key_exist?(default) end end backend.translate locale, key, end end |