# File lib/i18n/backend/fallbacks.rb, line 55 55: def extract_string_default!(options) 56: defaults = Array(options[:default]) 57: if index = find_first_string_default(defaults) 58: options[:default] = defaults[0, index] 59: defaults[index] 60: end 61: end
# File lib/i18n/backend/fallbacks.rb, line 63 63: def find_first_string_default(defaults) 64: defaults.each_index { |ix| return ix if String === defaults[ix] } 65: nil 66: end
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 only when it’s not a String. When default contains String it is evaluated after fallback locales.
# File lib/i18n/backend/fallbacks.rb, line 40 40: def translate(locale, key, options = {}) 41: default = extract_string_default!(options) if options[:default] 42: 43: I18n.fallbacks[locale].each do |fallback| 44: begin 45: result = super(fallback, key, options) 46: return result unless result.nil? 47: rescue I18n::MissingTranslationData 48: end 49: end 50: 51: return super(locale, nil, options.merge(:default => default)) if default 52: raise(I18n::MissingTranslationData.new(locale, key, options)) 53: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.