Rails国际化:i18n查找嵌套的语言环境目录
我正在尝试使用嵌套文件结构组织我的本地化文件,以便更容易查找。
我跟着
在rails app中组织Locale文件
你如何在Rails中构建i18n yaml文件?
但是我的翻译版本丢失了: en.view.fruits.apple
。 我认为Rails试图只查找locales/en.yml
文件中的翻译但不locales/en.yml
子目录,尽管我已将它们包括在内。
配置/ application.rb中:
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
我的语言环境目录:
|locales |-en.yml |-views |--en.yml
区域设置/查看/ en.yml:
en: fruits: apple: "apple"
意见/ fruit.html.haml:
= I18n.t('views.fruits.apple')
问题解决了
在我的views / fruit.html.haml中
代替
= I18n.t('views.fruits.apple')
它应该是
= I18n.t('fruits.apple')
因为所有子文件夹都是预加载的
配置/ application.rb中
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
不要忘记你需要重新启动服务器!!