Module: I18n::Backend::Translate
- Defined in:
- lib/i18n/backend/translate.rb
Overview
It is highly recommended to use Translator wit Fallback plugin
I18n::Backend::Simple.send(:include, I18n::Backend::Translate)
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
notice that Translator have to be included BEFORE Fallback otherwise the fallback will get Hash (even with empty translation) and won’t work.
Instance Method Summary collapse
-
#translate(locale, key, options = {}) ⇒ Object
wrapper which can work with both format the simple and the Translator’s.
Instance Method Details
#translate(locale, key, options = {}) ⇒ Object
wrapper which can work with both format the simple and the Translator’s
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/i18n/backend/translate.rb', line 20 def translate(locale, key, = {}) raise InvalidLocale.new(locale) unless locale entry = key && lookup(locale, key, [:scope], ) entry = translate_to_i18n(entry) if .empty? entry = resolve(locale, key, entry, ) else count, default = .values_at(:count, :default) values = .except(*RESERVED_KEYS) entry = entry.nil? && default ? default(locale, key, default, ) : resolve(locale, key, entry, ) end throw(:exception, I18n::MissingTranslation.new(locale, key, )) if entry.nil? entry = entry.dup if entry.is_a?(String) entry = pluralize(locale, entry, count) if count entry = translate_to_i18n(entry) # after pluralization there can be enhanced format entry = entry.dup if entry.is_a?(String) entry = interpolate(locale, entry, values) if values #throw(:exception, I18n::MissingTranslation.new(locale, key, options)) if entry.to_s.empty? entry end |