【发布时间】:2015-06-20 17:29:06
【问题描述】:
我有以下 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
【问题讨论】:
-
我将此作为全球化问题交叉发布:github.com/globalize/globalize/issues/362
标签: ruby-on-rails ruby ruby-on-rails-4 globalize