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
- RUBY19 =
(RUBY_VERSION > "1.9")
- @@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
29 30 31 |
# File 'lib/gettext_i18n_rails/backend.rb', line 29 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
14 15 16 |
# File 'lib/gettext_i18n_rails/backend.rb', line 14 def available_locales FastGettext.available_locales || [] end |
#translate(locale, key, options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gettext_i18n_rails/backend.rb', line 18 def translate(locale, key, ) if gettext_key = gettext_key(key, ) translation = plural_translate(gettext_key, ) || FastGettext._(gettext_key) interpolate(translation, ) else result = backend.translate(locale, key, ) (RUBY19 and result.is_a?(String)) ? result.force_encoding("UTF-8") : result end end |