目前,我有一些语言环境子目录,这些子目录已在配置中正确设置
config/application.rb
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
Run Code Online (Sandbox Code Playgroud)
我已经有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"
Run Code Online (Sandbox Code Playgroud)
现在,我在SAME子目录“ locales / admin”中添加了两个其他语言环境文件(与以前的文件非常相似...)。
# =============
config/locales/admin/sheet.en.yml
en:
sheet:
title: Sheet
config/locales/admin/sheet.fr.yml
fr:
sheet:
title: Table
Run Code Online (Sandbox Code Playgroud)
我重新启动服务器...并尝试成功获得新添加的翻译
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"
Run Code Online (Sandbox Code Playgroud)
两种语言都缺少翻译?所以我猜在我检查Rails.application.config.i18n.load_path时,application.rb配置文件中的子目录定义有问题,并且新添加的文件不在路径中。
"..../config/locales/admin/dashboard.en.yml",
"..../config/locales/admin/dashboard.fr.yml",
Run Code Online (Sandbox Code Playgroud)
但不是
"..../config/locales/admin/sheet.en.yml",
"..../config/locales/admin/sheet.fr.yml",
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议
小智 5
看来此问题已被检测到,并且与“春季”过程有关。
# https://github.com/rails/spring/issues/408
# rafaelfranca May 28
I think you got this error because you added the locale file after you
started the spring process for your environment, so when you add the
file it is not loaded inside the spring process. When you change the
application.rb the spring process is reloaded and your locale is now
working.
Run Code Online (Sandbox Code Playgroud)
我更改了application.rb中的一行(添加了一个空白行...),而不是重新启动服务器,然后找到了新的翻译
拉斐尔表示Rails控制台应重新启动弹簧
Any rails command starts springs. rails console, rails generate,
rails server. You can stop the spring process with spring stop.
Run Code Online (Sandbox Code Playgroud)
因此,在添加新的语言环境文件之后,最好在重新启动服务器之前停止spring
spring stop
rails server ( or rails console )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1190 次 |
| 最近记录: |