Class: SgtnClient::I18nBackend
- Inherits:
-
Object
- Object
- SgtnClient::I18nBackend
- Defined in:
- lib/sgtn-client/i18n_backend.rb
Overview
When integrating Singleton in a client application that is already using [I18n::Backend (www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/), it would be useful to have Singleton override the said module in order to minimize necessary changes. Here is a common usage:
I18n::Backend::Simple.include(I18n::Backend::Fallbacks) # add fallbacks behavior to current backend
I18n.backend = I18n::Backend::Chain.new(Sgtn::I18nBackend.new(component_name), I18n.backend)
I18n.enforce_available_locales=false # disable available locales check
I18n.default_locale = :en
Instance Method Summary collapse
- #available_locales ⇒ Object
- #eager_load! ⇒ Object
- #exists?(locale, key, options) ⇒ Boolean
-
#initialize(component) ⇒ I18nBackend
constructor
A new instance of I18nBackend.
- #initialized? ⇒ Boolean
- #load_translations ⇒ Object
- #localize(locale, object, format, options) ⇒ Object
- #reload! ⇒ Object
- #store_translations ⇒ Object
- #translate(locale, key, options) ⇒ Object
- #translations ⇒ Object
Constructor Details
#initialize(component) ⇒ I18nBackend
Returns a new instance of I18nBackend.
14 15 16 |
# File 'lib/sgtn-client/i18n_backend.rb', line 14 def initialize(component) @component = component end |
Instance Method Details
#available_locales ⇒ Object
26 27 28 |
# File 'lib/sgtn-client/i18n_backend.rb', line 26 def available_locales SgtnClient.config.available_locales(@component).to_a end |
#eager_load! ⇒ Object
32 |
# File 'lib/sgtn-client/i18n_backend.rb', line 32 def eager_load!; end |
#exists?(locale, key, options) ⇒ Boolean
36 37 38 |
# File 'lib/sgtn-client/i18n_backend.rb', line 36 def exists?(locale, key, ) !!(translate(locale, key, ) { nil }) end |
#initialized? ⇒ Boolean
18 19 20 |
# File 'lib/sgtn-client/i18n_backend.rb', line 18 def initialized? @initialized ||= true end |
#load_translations ⇒ Object
22 |
# File 'lib/sgtn-client/i18n_backend.rb', line 22 def load_translations(*) end |
#localize(locale, object, format, options) ⇒ Object
46 |
# File 'lib/sgtn-client/i18n_backend.rb', line 46 def localize(locale, object, format, ) end |
#reload! ⇒ Object
30 |
# File 'lib/sgtn-client/i18n_backend.rb', line 30 def reload!; end |
#store_translations ⇒ Object
24 |
# File 'lib/sgtn-client/i18n_backend.rb', line 24 def store_translations(*) end |
#translate(locale, key, options) ⇒ Object
40 41 42 43 44 |
# File 'lib/sgtn-client/i18n_backend.rb', line 40 def translate(locale, key, ) flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, [:scope], '.') values = .except(*I18n::RESERVED_KEYS) Translation.translate(flat_key, @component, locale, **values) { nil } end |
#translations ⇒ Object
34 |
# File 'lib/sgtn-client/i18n_backend.rb', line 34 def translations; end |