Class: Sgtn::I18nBackend

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

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_localesObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/singleton-client/i18n_backend.rb', line 40

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

#initialized?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/singleton-client/i18n_backend.rb', line 22

def initialized?
  @initialized ||= true
end

#load_translationsObject



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

#reload!Object



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

def reload!; end

#store_translationsObject



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, 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



38
# File 'lib/singleton-client/i18n_backend.rb', line 38

def translations; end