instance method translate

Ruby on Rails 2.3.18

Since v2.3.18 Last seen in v2.3.18

Signature

translate(locale, key, options = {})

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.

Parameters

locale req
key req
options opt = {}
Source
# File activesupport/lib/active_support/vendor/i18n-0.4.1/i18n/backend/fallbacks.rb, line 40
      def translate(locale, key, options = {})
        default = extract_string_default!(options) if options[:default]

        I18n.fallbacks[locale].each do |fallback|
          begin
            result = super(fallback, key, options)
            return result unless result.nil?
          rescue I18n::MissingTranslationData
          end
        end

        return super(locale, nil, options.merge(:default => default)) if default
        raise(I18n::MissingTranslationData.new(locale, key, options))
      end

Defined in activesupport/lib/active_support/vendor/i18n-0.4.1/i18n/backend/fallbacks.rb line 40 · View on GitHub · Improve this page · Find usages on GitHub

Defined in I18n::Backend::Fallbacks

Type at least 2 characters to search.

↑↓ navigate · open · esc close