我有以下 I18n-Setup
config.i18n.available_locales = [:de, :en]
config.i18n.fallbacks = true
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :de
我有一个基于 URL 的语言环境开关:
# routes.rb
scope '(:locale)/', locale: /en|de/, defaults: {locale: 'de'} do
resources :programmes
root 'programmes#portal'
end
在我的 ApplicationController 中,我将语言环境设置为before_filter
# application_controller.rb
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
在我的application.rb
config.i18n.available_locales = [:de, :en]
config.i18n.fallbacks = true
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :de
我对我的两种语言都有一个后备(/app/initializers/globalize.rb
):
Globalize.fallbacks = {:en => [:en, :de], :de => [:de, :en]}
我的development.rb
和production.rb
在 I18n 设置方面没有区别。
现在我遇到了以下问题:
- 我有一个只翻译成的记录
EN
- 在我的开发环境中使用 locale =
DE
回退到英文标题作品 - 但是,在生产环境中,此回退不起作用。
我不清楚为什么这在生产环境中不起作用。
更新:在我的生产环境的生产控制台中,回退似乎也有效:
irb(main):005:0* I18n.locale
=> :de
irb(main):006:0> p=Programme.find(1289)
=> #<Programme id: 1289, created_at: "2014-07-08 09:58:21", ....>
irb(main):007:0> p.title
=> "English Title"
irb(main):008:0> I18n.locale = :en
=> :en
irb(main):009:0> p.title
=> "English Title"
irb(main):010:0> I18n.locale = :something-undefined
=> :something-undefined
irb(main):011:0> p.title
=> nil
irb(main):012:0> I18n.default_locale
=> :de