我正在使用 I18n-js,我的客户端 I18n.t 调用在生产中运行时都返回翻译丢失消息。
在开发和测试中一切正常。
这个问题的根源似乎在于资产管道。
I18n.load_path 不包含我的任何翻译(运行 bin/rake assets:precompile 时)它只包含以下路径:
["/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activesupport-3.2.3/lib/active_support/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activemodel-3.2.3/lib/active_model/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activerecord-3.2.3/lib/active_record/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/actionpack-3.2.3/lib/action_view/locale/en.yml"]
这些看起来像是来自 gems 的默认 activesupport、activemodel、activerecord 和 actionpack 翻译...
但是,在开发和生产中运行 bin/rails 控制台时,我的翻译路径确实按预期设置:
1.9.3p125 :002 > I18n.load_path
=> ["/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activesupport-3.2.3/lib/active_support/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activemodel-3.2.3/lib/active_model/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/activerecord-3.2.3/lib/active_record/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/actionpack-3.2.3/lib/action_view/locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/carrierwave-0.6.1/lib/carrierwave/validations/../locale/en.yml",
"/home/chris/.rvm/gems/ruby-1.9.3-p125@Project/gems/devise-2.0.4/config/locales/en.yml",
"/media/sf_code/Project/config/locales/active_record.en.yml",
"/media/sf_code/Project/config/locales/project.en.yml"]
事实上,I18n 文档指出:“默认语言环境是 :en,所有来自 config/locales/*.rb,yml 的翻译都是自动加载的。”
我也尝试在 application.rb 中指定
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
但仍然没有喜悦。
任何人都知道什么会导致仅在运行 assets:precompile 时才设置 I18n.load_path ?
感谢您的任何想法