class I18n::Backend::LazyLoadable
Public Class Methods
# File lib/i18n/backend/lazy_loadable.rb, line 66 def initialize(lazy_load: false) @lazy_load = lazy_load end
Public Instance Methods
Parse the load path and extract all locales.
Calls superclass method
# 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 loading is not supported in the lazy context.
Calls superclass method
# 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
Returns whether the current locale is initialized.
Calls superclass method
# File lib/i18n/backend/lazy_loadable.rb, line 71 def initialized? if lazy_load? initialized_locales[I18n.locale] else super end end
Calls superclass method
# File lib/i18n/backend/lazy_loadable.rb, line 107 def lookup(locale, key, scope = [], options = EMPTY_HASH) if lazy_load? I18n.with_locale(locale) do super end else super end end
Clean up translations and uninitialize all locales.
Calls superclass method
# File lib/i18n/backend/lazy_loadable.rb, line 80 def reload! if lazy_load? @initialized_locales = nil @translations = nil else super end end
Protected Instance Methods
Load translations from files that belong to the current locale.
# File lib/i18n/backend/lazy_loadable.rb, line 121 def init_translations file_errors = if lazy_load? initialized_locales[I18n.locale] = true load_translations_and_collect_file_errors(filenames_for_current_locale) else @initialized = true load_translations_and_collect_file_errors(I18n.load_path) end raise InvalidFilenames.new(file_errors) unless file_errors.empty? end
# File lib/i18n/backend/lazy_loadable.rb, line 133 def initialized_locales @initialized_locales ||= Hash.new(false) end