Class: I18n::Backend::LazyLoadable
- Defined in:
- lib/i18n/backend/lazy_loadable.rb
Defined Under Namespace
Classes: FilenameIncorrect
Constant Summary
Constants included from Simple::Implementation
Constants included from Transliterator
Transliterator::DEFAULT_REPLACEMENT_CHAR
Instance Method Summary collapse
-
#available_locales ⇒ Object
Parse the load path and extract all locales.
-
#eager_load! ⇒ Object
Eager loading is not supported in the lazy context.
-
#initialize(lazy_load: false) ⇒ LazyLoadable
constructor
A new instance of LazyLoadable.
-
#initialized? ⇒ Boolean
Returns whether the current locale is initialized.
- #lookup(locale, key, scope = [], options = EMPTY_HASH) ⇒ Object
-
#reload! ⇒ Object
Clean up translations and uninitialize all locales.
Methods included from Simple::Implementation
#store_translations, #translations
Methods included from Base
#exists?, #load_translations, #localize, #store_translations, #translate
Methods included from Transliterator
Constructor Details
#initialize(lazy_load: false) ⇒ LazyLoadable
Returns a new instance of LazyLoadable.
66 67 68 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 66 def initialize(lazy_load: false) @lazy_load = lazy_load end |
Instance Method Details
#available_locales ⇒ Object
Parse the load path and extract all locales.
99 100 101 102 103 104 105 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 99 def available_locales if lazy_load? I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }.uniq else super end end |
#eager_load! ⇒ Object
Eager loading is not supported in the lazy context.
90 91 92 93 94 95 96 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 90 def eager_load! if lazy_load? raise UnsupportedMethod.new(__method__, self.class, "Cannot eager load translations because backend was configured with lazy_load: true.") else super end end |
#initialized? ⇒ Boolean
Returns whether the current locale is initialized.
71 72 73 74 75 76 77 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 71 def initialized? if lazy_load? initialized_locales[I18n.locale] else super end end |
#lookup(locale, key, scope = [], options = EMPTY_HASH) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 107 def lookup(locale, key, scope = [], = EMPTY_HASH) if lazy_load? I18n.with_locale(locale) do super end else super end end |
#reload! ⇒ Object
Clean up translations and uninitialize all locales.
80 81 82 83 84 85 86 87 |
# File 'lib/i18n/backend/lazy_loadable.rb', line 80 def reload! if lazy_load? @initialized_locales = nil @translations = nil else super end end |