-->

在Rails应用程序语言文件的组织(Organization of Locale Files in

2019-07-29 12:42发布

目前,我有我的根应用程序的我的配置/区域设置以下4个文件:

-en.yml
-de.yml
-simple_form.en.yml
-simple_form.de.yml

在我的application.rb中驻留在一个投机/虚拟文件夹用于测试应用程序的宝石我有这似乎是检索翻译预期以下代码行:

# 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

我现在想介绍给结构的文件结构的我的语言环境中的文件夹,但是当我在application.rb中添加其他文件夹和改变负载路径我越来越没有发现翻译错误。 这里是我的尝试:

尝试在包括我的根应用程序的配置/区域设置结构:

-views
  -en.yml
  -de.yml
-models
  -en.yml
  -de.yml
-forms
  -simple_form.en.yml
  -simple_form.de.yml

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

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

根据下面的导轨导向: http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-domain-name

Answer 1:

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

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


Answer 2:

我有一个类似的问题,我解决它通过加入这一行到我的application.rb中的配置:

# load the subfolders in the locales
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]


Answer 3:

The following options all worked for me

config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.yml"]

config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**' '*.{rb,yml}').to_s]

After restarting the webserver of course...



Answer 4:

config/application.rb

module PointsProject
  class Application < Rails::Application
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
  end
end

Rails中对国际指南: http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-domain-name



文章来源: Organization of Locale Files in rails app