Reputation: 10350
In our Rails 4.2 app views, there is I18n
error whenever there is no key found in zh-CN
file:
translation missing: zh-CN.no key
Here is in local.rb under config/initializers/:
I18n.default_locale = 'zh-CN' if Rails.env.production? || Rails.env.development?
We would like to turn off this error and prevent it from showing on views. There is a post about the error for Rails 3. However the solutions are not working with Rails 4.2. Also config.i18n.fallbacks = false/true
does not do the trick.
Upvotes: 0
Views: 3177
Reputation: 316
We can config I18n callbacks in Rails application. For example, when zh-CN
translation missing, I18n will fallback to en
. Configuration in my Rails 4.2.2 application like below:
config/application.rb
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
config.i18n.default_locale = :"zh-CN"
config.i18n.fallbacks = true
config/initializers/i18n.rb
Rails.configuration.after_initialize do
I18n.fallbacks.map(:"zh-CN" => :en)
end
Reference doc:
Upvotes: 0
Reputation: 11689
You must add both a fallback locale and a fallback language.
config.i18n.default_locale = :en
config.i18n.fallbacks = true
This should force I18n
to fallback to english. I use it extensively on a Rails 4.1 app, I'm not sure if something changed over it for 4.2 though.
Upvotes: 4