Class: Sgtn::I18nBackend
- Inherits:
-
Object
- Object
- Sgtn::I18nBackend
- Defined in:
- lib/singleton-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 17 18 19 20 |
# File 'lib/singleton-client/i18n_backend.rb', line 14 def initialize(component) @component = component @translation = Class.new do include SgtnClient::Translation::Implementation include Sgtn::Pseudo end.new end |
Instance Method Details
#available_locales ⇒ Object
30 31 32 |
# File 'lib/singleton-client/i18n_backend.rb', line 30 def available_locales SgtnClient.config.available_locales(@component).to_a end |
#eager_load! ⇒ Object
36 |
# File 'lib/singleton-client/i18n_backend.rb', line 36 def eager_load!; end |
#exists?(locale, key, options) ⇒ Boolean
40 41 42 |
# File 'lib/singleton-client/i18n_backend.rb', line 40 def exists?(locale, key, ) !!translate(locale, key, ) end |
#initialized? ⇒ Boolean
22 23 24 |
# File 'lib/singleton-client/i18n_backend.rb', line 22 def initialized? @initialized ||= true end |
#load_translations ⇒ Object
26 |
# File 'lib/singleton-client/i18n_backend.rb', line 26 def load_translations(*) end |
#localize(locale, object, format, options) ⇒ Object
50 |
# File 'lib/singleton-client/i18n_backend.rb', line 50 def localize(locale, object, format, ) end |
#reload! ⇒ Object
34 |
# File 'lib/singleton-client/i18n_backend.rb', line 34 def reload!; end |
#store_translations ⇒ Object
28 |
# File 'lib/singleton-client/i18n_backend.rb', line 28 def store_translations(*) end |
#translate(locale, key, options) ⇒ Object
44 45 46 47 48 |
# File 'lib/singleton-client/i18n_backend.rb', line 44 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
38 |
# File 'lib/singleton-client/i18n_backend.rb', line 38 def translations; end |