class I18n::Backend::LocaleExtractor
I18n.backend = I18n::Backend::LazyLoadable.new(lazy_load: false) # default
# In other environments, such as production and CI
I18n.backend = I18n::Backend::LazyLoadable.new(lazy_load: true)
# In test environments
accessor:
You can configure lazy loaded backends through the initializer or backends
abide by the format. If paths can’t be matched to the format, an error is raised.
Simple backend, with an additional check that the paths being loaded
When the mode is set to false, the backend behaves exactly like the
Note: This backend should only be enabled in test environments!
The backend has two working modes: lazy_load and eager_load.
translation files until the current locale actually requires them.
The implementation uses this assumption to defer the loading of
“files/locales/fr/translation.yml”
“files/locales/french/translation.yml”
“files/locales/en-translation.unsupported”
“files/locales/translation-file”
Invalid files that won’t be selected by this backend:
“files/locales/fr.po” (Selected for locale “fr”)
“files/locales/en_translation.yml” (Selected for locale “en”)
Valid files that will be selected by this backend:
Examples:
d) the locale identifier and optional proceeding text is separated by an underscore, ie. “_”.
c) the filename starts with the locale identifier
b) the filename ends in a supported extension (ie. .yml, .json, .po, .rb)
a) the filename is in the I18n load path
Specifically, a translation file is considered to belong to a locale if:
current locale by pattern matching against their path name.
identifies which translation files from the load path belong to the
translations at a time (ex. A Rails workload). The implementation
particularly useful when the application only refers to a single locales’
applications with many translations for many different locales. It’s
performance incentive in local development and test environments for
loads the translations that belong to the current locale. This offers a
implementation avoids loading all translations up front. Instead, it only
Backend that lazy loads translations based on the current locale. This
def locale_from_path(path)
def locale_from_path(path) name = File.basename(path, ".*") locale = name.split("_").first locale.to_sym unless locale.nil? end