The I18n boot path is not set when running "bin / rake assets: precompile"!

I use I18n-js, and the client side I18n.t calls the entire returned message a missing translation at startup during production.

Everything is in order to develop and test.

The root of this problem seems to be in the asset pipeline.

I18n.load_path does not contain any of my translations (when running bin / rake assets: precompile) it contains only the following paths:

["/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activesupport-3.2.3/lib/active_support/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activemodel-3.2.3/lib/active_model/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activerecord-3.2.3/lib/active_record/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/actionpack-3.2.3/lib/action_view/locale/en.yml"] 

They look like the default activesupport, activemodel, activerecord and actionpack gem transfers ...

My translation paths, however, are set as expected when starting the bin / rails console during development and production:

 1.9.3p125 :002 > I18n.load_path => ["/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activesupport-3.2.3/lib/active_support/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activemodel-3.2.3/lib/active_model/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/activerecord-3.2.3/lib/active_record/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/actionpack-3.2.3/lib/action_view/locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/carrierwave-0.6.1/lib/carrierwave/validations/../locale/en.yml", "/home/chris/.rvm/gems/ ruby-1.9.3-p125@Project /gems/devise-2.0.4/config/locales/en.yml", "/media/sf_code/Project/config/locales/active_record.en.yml", "/media/sf_code/Project/config/locales/project.en.yml"] 

In fact, the I18n documentation says: "Default language: en and all translations from config / locales / *. Rb, yml are automatically loaded."

I also tried specifying in application.rb

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

But there is still no joy.

Does anyone know what could cause the I18n.load_path parameter to not be set only when resources start: precompile?

Thanks for any ideas.

+6
source share
3 answers

This is actually related to the asset configuration flag, which you probably set in config / application.rb.

 config.assets.initialize_on_precompile = false 

Rake assets: pre-compilation rake sets this flag, and if it is found to be false, it loads only a group of assets and does not fully initialize the application. In turn, application locales are not added to the I18n.load_ path.

+3
source

Have you defined the default locale? If not, you can do this by adding this line to your config / application.rb

 config.i18n.default_locale = :fr 

Perhaps you should add this line to your production.rb too to enable locale backups for I18n:

 config.i18n.fallbacks = true 

Then, be careful that you do not have tab indents in your locale file, but only space indents.

A locale is not an asset, assets are just js, css and images, so there is no connection between compiling assets and locales.

0
source

This is because i18n.js not compiled or processed in public/assets , so you need to add the following line to config/environments/production.rb

 config.assets.precompile += %w( i18n.js en_locale.js fr_locale.js ) 

Then, run the rake assets:precompile , you notice that the public/assets/i18n-MD5.js Now there and ready to serve.

0
source

Source: https://habr.com/ru/post/912913/


All Articles