Does Rails 4 create an i18n kernel autoload engine?

I have a question about the Rails engine, which is not mentioned in the Rails manual on the Rails engine. I hope to get it here.

I have one engine, for example, my_engine and one application called my_app.

for development purposes, in my_app Gemfile, I simply include my_engine with the following line using: file key.

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

and my_engine structure is as follows:

 . β”œβ”€β”€ 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 

And I found that although I am trying to check the I18n.load_path in my_app, there is no waypoint to my_engine, which means that my_app is not loading my_engine locale transactions.

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

Are you missing any configuration or some important steps for loading locales in my_engine?

+7
ruby ruby-on-rails-4 rails-engines
source share
2 answers

I use

 Rails 4.1.6 

and I mounted my engine like this inside a gemfile

 gem 'core', path: "core" 

when i check download paths

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

I see locales included in my engine

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

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

since by default the rails load the locales of your engine

it is also mentioned in the documentation

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

Then make sure 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 the application, load routes in config / routes.rb, load locales in config / locales / and load tasks into lib / tasks /.

+2
source share

All methods declared in the Application Controller are visible from anywhere. Specify the application whose language should be loaded with the code:

 # on my_app/app/controller/application_controller.rb class ApplicationController < ActionController::Base before_filter :set_locale def set_locale I18n.locale = request.headers['HTTP_ACCEPT_LANGUAGE'].split(',')[0].split('-')[0] end 

Hope this helps you Randy Marsh.

0
source share

All Articles