【发布时间】:2015-09-09 10:13:06
【问题描述】:
目前我有一些语言环境子目录,在配置中设置正确
config/application.rb
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
我已经有 2 个语言环境文件,我可以轻松获得翻译:
config/locales/admin/dashboard.en.yml
en:
dashboard:
title: Dashboard
config/locales/admin/dashboard.fr.yml
fr:
dashboard:
title: Tableau de bord
irb(main):014:0> I18n.locale = :en
=> :en
irb(main):015:0> I18n.t("dashboard.title")
=> "Dashboard"
irb(main):016:0> I18n.locale = :fr
=> :fr
irb(main):017:0> I18n.t("dashboard.title")
=> "Tableau de bord"
现在我在 SAME 子目录“locales/admin”中添加了 2 个其他语言环境文件(与之前的非常相似...)
# =============
config/locales/admin/sheet.en.yml
en:
sheet:
title: Sheet
config/locales/admin/sheet.fr.yml
fr:
sheet:
title: Table
我重新启动了服务器...并尝试成功获取新添加的翻译
irb(main):010:0> I18n.locale = :en
=> :en
irb(main):011:0> I18n.t("sheet.title")
=> "translation missing: en.sheet.title"
irb(main):012:0> I18n.locale = :fr
=> :fr
irb(main):013:0> I18n.t("sheet.title")
=> "translation missing: fr.sheet.title"
两种语言都缺少翻译?所以我猜 application.rb 配置文件中的子目录定义有问题,因为我检查了 Rails.application.config.i18n.load_path ,并且新添加的文件不在路径中..
"..../config/locales/admin/dashboard.en.yml",
"..../config/locales/admin/dashboard.fr.yml",
但不是
"..../config/locales/admin/sheet.en.yml",
"..../config/locales/admin/sheet.fr.yml",
感谢您的建议
【问题讨论】:
标签: ruby-on-rails-4 rails-i18n