How to enable backup in I18n using globalize2

So the problem. In my application, globalize2 returns a NIL string if there is no translation on any record, instead of returning to default_locale. I wonder how to enable subtle functionality? Has anyone understood this?

+3
source share
3 answers

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

Then in your .rb environment:

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

using: "en-US" as the 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]
+10
source

In the latest i18n gem (0.7.0), I found it necessary to define backup locales such as 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

config.i18n.fallbacks = true config/environments/*.rb.

+1

(i18n gem version 0.4x ).

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

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

Source: https://habr.com/ru/post/1730214/


All Articles