Module: I18n::Backend::Fallbacks

Defined in:
lib/i18n/backend/fallbacks.rb

Instance Method Summary collapse

Instance Method Details

#translate(locale, key, options = {}) ⇒ Object

Overwrites the Base backend translate method so that it will try each locale given by I18n.fallbacks for the given locale. E.g. for the locale :“de-DE” it might try the locales :“de-DE”, :de and :en (depends on the fallbacks implementation) until it finds a result with the given options. If it does not find any result for any of the locales it will then raise a MissingTranslationData exception as usual.

The default option takes precedence over fallback locales, i.e. it will first evaluate a given default option before falling back to another locale.



40
41
42
43
44
45
46
47
48
# File 'lib/i18n/backend/fallbacks.rb', line 40

def translate(locale, key, options = {})
  I18n.fallbacks[locale].each do |fallback|
    begin
      result = super(fallback, key, options) and return result
    rescue I18n::MissingTranslationData
    end
  end
  raise(I18n::MissingTranslationData.new(locale, key, options))
end