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)
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.i18n.default_locale = :en
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 .