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::Translator)
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

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
# File 'lib/i18n/backend/translate.rb', line 20

def translate(locale, key, options = {})
  result = super(locale, key, options)
  return nil if result.kind_of?(String) and result.empty?
  return result unless result.kind_of?(Hash)
  return nil unless result[:t] or result[:translation] or result[:default]

  tr = result[:translation] || result[:t]
  tr = result[:default] if tr.to_s.empty?

  return nil if tr.to_s.empty?

  values = options.except(*I18n::Backend::Base::RESERVED_KEYS)

  tr = resolve(locale, key, tr, options)
  tr = interpolate(locale, tr, values) if values

  tr
end