Rails国际化:i18n使用嵌套的语言环境目录查找 [英] Rails Internationalization: i18n look up with nested locales directories

查看:116
本文介绍了Rails国际化:i18n使用嵌套的语言环境目录查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用嵌套文件结构来组织我的本地化文件,以便于查找.

I am trying to organize my localization files with a nested file structure so that it is easier to look up.

我关注了

在Rails应用程序中组织区域设置文件

如何在Rails中构造i18n yaml文件?

但是我缺少翻译: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使用嵌套的语言环境目录查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆