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