Local backups in Rails 4 do not work

I create a Rails 4 site for a client in Singapore, Malaysia, Taiwan and China.

Language code for Chinese-speaking Malay zh-MY.

I would like to save the basic set of language files zh-CN(Simplified Chinese) and zh-MYreturn to zh-CN.

The simple meaning zhis wrong, because zh-TW(traditional Chinese) is what Taiwan uses, and zh-CNthere are big differences between it.

So, here is my config/application.rbfile according to the Rails manual .

require File.expand_path('../boot', __FILE__)

require 'rails/all'
require "i18n/backend/fallbacks"

module MyAwesomeApp
  class Application < Rails::Application
    I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

    # all translations from config/locales/**/*.rb,yml are auto loaded.
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

    # The default locale is :en
    config.i18n.default_locale = :en

    # See http://guides.rubyonrails.org/i18n.html#localized-views for a discussion of
    # how language codes fall-back.
    config.i18n.available_locales = [:en, :'zh-CN', :'zh-TW', :'en-SG', :'en-MY', :'zh-MY']
    I18n.fallbacks.map(:'zh-MY' => :'zh-CN')
  end
end

But that just doesn't work.

When I actually set the locale :zh-MY, it does not return to :zh-CN, but to:en

What am I missing?

: puts "I18n.fallbacks #{I18n.fallbacks}" I18n.fallbacks {}. , I18n.fallbacks.map .

I18n.fallbacks[:'zh-MY'] , I18n.fallbacks, [:"zh-MY", :zh, :"zh-CN", :en]

binding.pry application controller :

[1] pry(#<ServicesController>)> I18n.locale
=> :"zh-MY"
[2] pry(#<ServicesController>)> I18n.fallbacks
=> {:en=>[:en], :"zh-MY"=>[:"zh-MY", :zh, :en]}

, - Rails set_locale, I18n.fallbacks reset .

+4
1

, , , , .

require File.expand_path('../boot', __FILE__)

require 'rails/all'
require "i18n/backend/fallbacks"

Bundler.require(*Rails.groups)

module MyAwesomeApp
  class Application < Rails::Application
    # all translations from config/locales/**/*.rb,yml are auto loaded.
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

    # The default locale is :en
    config.i18n.default_locale = :en

    # See http://guides.rubyonrails.org/i18n.html#localized-views for a
    # mostly correct discussion of how language codes fall-back.
    config.i18n.available_locales = [:en, :'zh-CN', :'zh-TW', :'en-SG', :'en-MY', :'zh-MY']
    config.i18n.fallbacks = {:'zh-MY' => :'zh-CN'}
  end
end

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) config.i18n.fallbacks = {:'zh-MY' => :'zh-CN'}, I18n.fallbacks.map(:'zh-MY' => :'zh-CN') .

, , 3- :

[1] pry(#<ServicesController>)> I18n.fallbacks
=> {:en=>[:en], :"zh-MY"=>[:"zh-MY", :zh, :"zh-CN", :en]}

, .

+5

All Articles