Class: SgtnClient::I18nBackend

Inherits:
Object
  • Object
show all
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

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_localesObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/sgtn-client/i18n_backend.rb', line 36

def exists?(locale, key, options)
  !!(translate(locale, key, options) { nil })
end

#initialized?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sgtn-client/i18n_backend.rb', line 18

def initialized?
  @initialized ||= true
end

#load_translationsObject



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, options) end

#reload!Object



30
# File 'lib/sgtn-client/i18n_backend.rb', line 30

def reload!; end

#store_translationsObject



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, options)
  flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, options[:scope], '.')
  values = options.except(*I18n::RESERVED_KEYS)
  Translation.translate(flat_key, @component, locale, **values) { nil }
end

#translationsObject



34
# File 'lib/sgtn-client/i18n_backend.rb', line 34

def translations; end