Filip
Filip

Reputation: 742

How to enable fallback in I18n with globalize2

So that's the problem. In my application globalize2 returns a NIL string if there's no translation on some record, instead of falling back to default_locale. I wonder how to enable thin functionality? Does anyone figured that out?

Upvotes: 3

Views: 1728

Answers (3)

Paweł Gościcki
Paweł Gościcki

Reputation: 9594

In latest i18n gem (0.7.0) I have found it necessary to define fallback locales like this (in config/application.rb):

# Custom I18n fallbacks
config.after_initialize do
  I18n.fallbacks = I18n::Locale::Fallbacks.new(at: :"de-DE", ch: :"de-DE", gb: :"en-US")
end

You also need to set config.i18n.fallbacks = true in all config/environments/*.rb files.

Upvotes: 1

Zubin
Zubin

Reputation: 9712

This worked for me (i18n gem version 0.4x didn't work).

# config/environment.rb
config.gem 'i18n', :version => '0.3.7'

# config/initializers/i18n.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

Upvotes: 0

Joris
Joris

Reputation: 617

Install sven fuchs's i18n library from http://github.com/svenfuchs/i18n

Then, in your environment.rb :

require "i18n/backend/fallbacks" 
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

using :"en-US" as a default locale:

I18n.default_locale = :"en-US" 
I18n.fallbacks[:ca] # => [:ca, :"en-US", :en]
I18n.fallbacks :dk => [:"se-FI", :"fi-FI"] # => [:dk, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en]

Upvotes: 10

Related Questions