Module: I18n::Backend::Fallback::Implementation

Included in:
I18n::Backend::Fallback
Defined in:
lib/exvo_globalize/backend/fallback.rb

Instance Method Summary collapse

Instance Method Details

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

add the simplest possible fallback to the I18n.default_locale for missing translations by using super() with I18n.default_locale for a second lookup



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/exvo_globalize/backend/fallback.rb', line 8

def translate(locale, key, default_options = {})

  if defined?(I18n::MissingTranslation)

    # i18n gem >= 0.6.0 (so we need to CATCH the exception)
    result = catch(:exception) do
      super(locale, key, default_options)
    end

    if result.is_a?(MissingTranslation)
      super(I18n.default_locale, key, default_options)
    else
      result
    end

  elsif defined?(I18n::MissingTranslationData)

    # i18n gem ~> 0.5.0 (so we need to RESCUE from the exception)
    begin
      super(locale, key, default_options)
    rescue I18n::MissingTranslationData
      super(I18n.default_locale, key, default_options)
    end

  else
    fail "Incompatible i18n gem version detected. OMG sky is falling..."
  end
end