问题描述
我正在尝试使用嵌套文件结构来组织我的本地化文件,以便于查找.
I am trying to organize my localization files with a nested file structure so that it is easier to look up.
我关注了
但是我缺少翻译:en.view.fruits.apple
.我认为Rails试图仅在locales/en.yml
文件中查找翻译,但不在子目录中查找,尽管我已将它们包括在内.
but I am getting a translation missing: en.view.fruits.apple
. I think that Rails is trying to only look up the translation in locales/en.yml
file but not the sub-directories although, I have included them.
config/application.rb:
config/application.rb:
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
我的语言环境目录:
|locales
|-en.yml
|-views
|--en.yml
语言环境/视图/en.yml:
locales/views/en.yml:
en:
fruits:
apple: "apple"
views/fruit.html.haml:
views/fruit.html.haml:
= I18n.t('views.fruits.apple')
推荐答案
问题已解决
在我的views/fruit.html.haml
in my views/fruit.html.haml
代替
= I18n.t('views.fruits.apple')
应该是
= I18n.t('fruits.apple')
因为所有子文件夹都是从
since all the sub-folders are preload from
config/application.rb
config/application.rb
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
别忘了您需要重新启动服务器!!
And don't forget you need to restart your server !!
这篇关于Rails国际化:i18n使用嵌套的语言环境目录查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!