在rails app中组织Locale文件

Jay*_*Jay 17 locale internationalization load-path ruby-on-rails-3 i18n-gem

我目前在我的root应用程序的config/locales中有以下4个文件:

-en.yml
-de.yml
-simple_form.en.yml
-simple_form.de.yml
Run Code Online (Sandbox Code Playgroud)

在我的application.rb中,它驻留在spec/dummy文件夹中以测试应用程序gem我有以下代码行,它似乎正在按预期检索翻译:

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :de
Run Code Online (Sandbox Code Playgroud)

我现在希望引入结构到我的locales文件夹的文件结构但是当我添加其他文件夹并更改application.rb中的加载路径时,我得到翻译未找到错误.这是我的尝试:

尝试在我的根应用程序的config/locales中包含结构:

-views
  -en.yml
  -de.yml
-models
  -en.yml
  -de.yml
-forms
  -simple_form.en.yml
  -simple_form.de.yml
Run Code Online (Sandbox Code Playgroud)

我在application.rb中的加载路径更改为:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
Run Code Online (Sandbox Code Playgroud)

根据以下rails指南:http: //guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-domain-name

Joh*_*ely 12

要测试主机应用程序,您需要将i18n.load_path更改为主应用程序的config文件夹,而不是用于测试目的的虚拟规范.代码如下:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.i18n.default_locale = :en
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,字符串是:`config.i18n.load_path + = Dir [Rails.root.join('config','locales','**','*.{rb,yml}').to_s]` (6认同)

ABr*_*wne 8

我有一个类似的问题,我通过将此行添加到我的application.rb配置解决了它:

# load the subfolders in the locales
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
Run Code Online (Sandbox Code Playgroud)