module I18n::Backend::Fallbacks
def extract_string_or_lambda_default!(options)
def extract_string_or_lambda_default!(options) defaults = Array(options[:default]) if index = find_first_string_or_lambda_default(defaults) options[:default] = defaults[0, index] defaults[index] end end
def find_first_string_or_lambda_default(defaults)
def find_first_string_or_lambda_default(defaults) defaults.each_with_index { |default, ix| return ix if String === default || Proc === default } nil end
def translate(locale, key, options = {})
only when it's a Symbol. When the default contains a String or a Proc
The default option takes precedence over fallback locales
usual.
locales it will then raise a MissingTranslationData exception as
the given options. If it does not find any result for any of the
(depends on the fallbacks implementation) until it finds a result with
locale :"de-DE" it might try the locales :"de-DE", :de and :en
locale given by I18n.fallbacks for the given locale. E.g. for the
Overwrites the Base backend translate method so that it will try each
def translate(locale, key, options = {}) return super if options[:fallback] default = extract_string_or_lambda_default!(options) if options[:default] options[:fallback] = true I18n.fallbacks[locale].each do |fallback| begin result = super(fallback, key, options) return result unless result.nil? rescue I18n::MissingTranslationData end end options.delete(:fallback) return super(locale, nil, options.merge(:default => default)) if default raise(I18n::MissingTranslationData.new(locale, key, options)) end