简体   繁体   English

Rails控制台未加载所有语言环境

[英]Rails console not loading all the locales

I've a project with carious locale files, organized in subdirectories depending of the model they correspond. 我有一个带有龋齿语言环境文件的项目,该文件根据它们对应的模型按子目录进行组织。

To make Rails load all of them, I've set this option in config/application.yml: 为了使Rails都加载它们,我已经在config / application.yml中设置了这个选项:

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

Now, executing rails console and writing something that requires the last locale file added (config/locale/email/en.yml), I get this: 现在,执行Rails控制台并编写一些需要添加最后一个语言环境文件(config / locale / email / en.yml)的内容,我得到以下信息:

Loading development environment (Rails 4.1.6)
2.1.3 :001 > I18n.t("email.footer_text")  
  => "translation missing: en.email.footer_text" 
2.1.3 :002 > translations = I18n.backend.send(:translations);
2.1.3 :003 > translations[:en][:email]  
  => nil

But, if I do it from a controller (with some help of puts command), it prints the locale string good. 但是,如果我从控制器执行此操作(在puts命令的帮助下),它将很好地打印语言环境字符串。

PD: In the console, it loads all the rest of locales, except the last added. PD:在控制台中,它将加载除最后添加的语言环境以外的所有其他语言环境。 I've tried to delete an old one, and the console (after a restart) gives me an error because the locale I've deleted doesn't exist. 我试图删除一个旧的,并且控制台(重启后)给我一个错误,因为我删除的语言环境不存在。

Is there any kind of cache that I should clean? 我应该清理任何缓存吗?

Why the console remembers that a deleted file used to exist if I've restarted the console after deleting the file? 如果控制台删除文件后重新启动控制台,控制台为何还记得该文件曾经存在过?

您应该首先在rails控制台中手动加载语言环境:

2.1.3 :001 > I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM