Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails locale fallbacks are not working in production env

I have a rails 3.2 application. It has 2 locales ko & en. ko is the default but I want it to fallback to en if it's not available. The fallback works in development env but not in production env.

[config/application.rb]
    config.i18n.default_locale = :ko
    config.i18n.fallbacks = [:en]

[config/environments/production.rb]
  config.i18n.fallbacks = true


[config/locales/en.yml]
  ttt: TTT

[config/locales/ko.yml]
  (ttt is not defined)


**In development console:**

I18n.locale #=> :ko
I18n.t("ttt") #=> "TTT" (Works fine)


**In production console:**

I18n.locale #=> :ko
I18n.t("ttt") #=> "translation missing: ko.ttt" (Not working)

What am I missing?

like image 812
Sam Kong Avatar asked Dec 25 '22 22:12

Sam Kong


2 Answers

If you comment out config.i18n.fallbacks = true in your production / staging environments it works as expected.

like image 138
Juanda Avatar answered Jan 16 '23 10:01

Juanda


Even if this question/answer is quite old, I will let here what I found for my case (Rails 5.X). The settings should look like this in application.rb

config.i18n.default_locale = :en

config.i18n.available_locales = %i(en de)
config.i18n.fallbacks = {
  de: :en
}

And with that, all the references to config.i18n.fallbacks = true should be removed from the different environments.

like image 44
Cris R Avatar answered Jan 16 '23 08:01

Cris R