在Rails应用程序中组织区域设置文件 [英] Organization of Locale Files in rails app

查看:89
本文介绍了在Rails应用程序中组织区域设置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I currently have the following 4 files in my config/locales of my root application:

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

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

In my application.rb which resides in a spec/dummy folder for testing the application gem I have the following line of code which seems to be retrieving the translations as expected:

# 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

我现在想向我的locales文件夹的文件结构介绍结构,但是当我添加其他文件夹并更改 application.rb 中的加载路径时,出现翻译找不到错误.这是我的尝试:

I now wish to introduce to structure to the file structure of my locales folder but when I add the additional folders and change the load path in the application.rb I am getting translation not found errors. Here is my attempt:

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

Attempt at including structure in config/locales of my root application:

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

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

And my load path in the application.rb changed to:

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

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

According to the following rails guide: http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-domain-name

推荐答案

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

To test the host application you need to change the i18n.load_path to the config folder of your main app and not the dummy spec for testing purposes. Code as follows:

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

这篇关于在Rails应用程序中组织区域设置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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