Rails区域设置回退在生产环境中不起作用

问题描述 投票:3回答:2

我有一个rails 3.2应用程序。它有2个语言环境ko&en。 ko是默认值,但如果它不可用,我希望它回退到en。后备工作在开发环境中,但不在生产环境中。

[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.localt #=> :ko
I18n.t("ttt") #=> "TTT" (Works fine)


**In production console:**

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

我错过了什么?

谢谢。

他自己

ruby-on-rails locale fallback rails-i18n
2个回答
5
投票

如果您在生产/暂存环境中注释掉config.i18n.fallbacks = true,它将按预期工作。


0
投票

即使这个问题/答案很老,我也会在这里找到我的案例(Rails 5.X)。在application.rb中,设置应如下所示

config.i18n.default_locale = :en

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

有了这个,所有对config.i18n.fallbacks = true的引用都应该从不同的环境中删除。

© www.soinside.com 2019 - 2024. All rights reserved.