关于 i18n 文件,Rails 4.0 似乎存在一些加载问题
理想情况下,I18n 负载路径应该是 3+
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activesupport-4.0.0/lib/active_support/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activemodel-4.0.0/lib/active_model/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activerecord-4.0.0/lib/active_record/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/actionpack-4.0.0/lib/action_view/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/carrierwave-0.9.0/lib/carrierwave/locale/en.yml
/Users/joshianiket22/carrierwave_tester/config/locales/en.yml
在 Rails 4.0 中看到了什么
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activesupport-3.2.11/lib/active_support/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activemodel-3.2.11/lib/active_model/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/activerecord-3.2.11/lib/active_record/locale/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/actionpack-3.2.11/lib/action_view/locale/en.yml
/Users/joshianiket22/workspace/zenjavi/carrierwave_tester/config/locales/en.yml
/Users/joshianiket22/.rvm/gems/ruby-1.9.3-p327@rails3_2/gems/carrierwave-0.9.0/lib/carrierwave/validations/../locale/en.yml
可以清楚地看到两者之间的区别,在特定于应用程序的 en.yml 之后加载了carrierwave en.yml,这就是你的问题
我建议没有简单的方法,除非您更改 rails 应用程序中的 load_paths 以及如何设法按预期更改 load_paths 的顺序
我已经在这里提出了拉取请求。完全敬畏 Carrierwave 的家伙来决定它
哈克解决方案:
我之前没有给你这个解决方案,但如果你想要它那么糟糕,你可以做什么
在 lib 目录中定义一个文件(比如说 auto_load_i18n.rb)并将 lib 路径分配给 autoload(在application.rb中)
config.autoload_paths += %w(#{config.root}/lib)
里面auto_load_i18n.rb
写这个
I18n.load_path.delete(Rails.root.join("config/locales/en.yml").to_s)
I18n.load_path << Rails.root.join("config/locales/en.yml").to_s
并要求在您的顶部的 lib 文件application_controller.rb
require 'auto_load_i18n'
class ApplicationController < ActionController::Base
我想那时一切都会好起来的
您现在可以理解为什么我不将其作为可能的解决方案:)
希望这有帮助