module I18n::Backend::Simple::Implementation
def available_locales
def available_locales init_translations unless initialized? translations.inject([]) do |locales, (locale, data)| locales << locale unless (data.keys - [:i18n]).empty? locales end end
def init_translations
def init_translations load_translations @initialized = true end
def initialized?
def initialized? @initialized ||= false end
def lookup(locale, key, scope = [], options = {})
into multiple keys, i.e. currency.format is regarded the same as
nested translations hash. Splits keys or scopes containing dots
eiher key is nil, or locale, scope or key do not exist as a key in the
Looks up a translation from the translations hash. Returns nil if
def lookup(locale, key, scope = [], options = {}) init_translations unless initialized? keys = I18n.normalize_keys(locale, key, scope, options[:separator]) keys.inject(translations) do |result, _key| _key = _key.to_sym return nil unless result.is_a?(Hash) && result.has_key?(_key) result = result[_key] result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol) result end end
def reload!
def reload! @initialized = false @translations = nil super end
def store_translations(locale, data, options = {})
translations will be overwritten by new ones only at the deepest
This uses a deep merge for the translations hash, so existing
Stores translations for the given locale in memory.
def store_translations(locale, data, options = {}) locale = locale.to_sym translations[locale] ||= {} data = data.deep_symbolize_keys translations[locale].deep_merge!(data) end
def translations
def translations @translations ||= {} end