加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – Rails 4引擎自动加载引擎的i18n语言环境文件吗?

发布时间:2020-12-16 19:05:11 所属栏目:百科 来源:网络整理
导读:我有一个关于Rails引擎的问题,在Rails指南中没有提到Rails引擎.我希望能在这里得到它. 我有一个引擎,例如,名为my_engine,还有一个名为my_app的应用程序. 出于开发目的,在my_app的Gemfile中,我只是简单地将my_engine包含在以下行中,使用:file key. #my_app/G
我有一个关于Rails引擎的问题,在Rails指南中没有提到Rails引擎.我希望能在这里得到它.

我有一个引擎,例如,名为my_engine,还有一个名为my_app的应用程序.

出于开发目的,在my_app的Gemfile中,我只是简单地将my_engine包含在以下行中,使用:file key.

#my_app/Gemfile
...
gem "my_engine",:path => "./../my_engine"
...

和my_engine结构是这样的:

.
├── Gemfile
├── Gemfile.lock
├── app
│ ├── ...
|   |...
|
├── config
│ ├── locales
│ │ └── models
│ │     └── products
│ │         ├── en.yml
│ │         └── zh-TW.yml
│ └── routes.rb
├── lib
│ ├── my_engine
│ │ ├── engine.rb
│ │ └── version.rb
│ ├── my_engine.rb
│ └── tasks
│     └── my_engine_tasks.rake

我发现当我尝试检查my_app下的I18n.load_path时,没有任何单一路径指向my_engine,这意味着,my_app不会加载my_engine的语言环境事务.

>>rails console
Loading development environment (Rails 4.0.2)
2.1.0 :001 >I18n.load_path.each { |x| puts x }

我是否遗漏了一些关于在my_engine中加载语言环境的配置或一些重要步骤?

解决方法

我正在使用
Rails 4.1.6

我在Gemfile中安装了我的引擎

gem 'core',path: "core"

当我检查我的负载路径

I18n.load_path.find_all { |p| p.match("core") }.each { |p| puts p }

我看到我的引擎中包含了语言环境

/absolute_path/core/config/locales/de.yml

/absolute_path/core/config/locales/en.yml

因此默认rails正在加载您的引擎区域设置

它也在文档中提到过

http://edgeapi.rubyonrails.org/classes/Rails/Engine.html

Then ensure that this file is loaded at the top of your config/application.rb (or in your Gemfile) and it will automatically load models,controllers and helpers inside app,load routes at config/routes.rb,load locales at config/locales/,and load tasks at lib/tasks/.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读