I am using I18n-js, and my client side I18n.t calls all return a translation missing message when running in production.
All is ok in development and test.
The root of this issue appears to be in the asset pipeline.
I18n.load_path does not contain any of my translations (when running bin/rake assets:precompile) it only contains 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"]
These look like the default activesupport, activemodel, activerecord and actionpack translations from the gems...
My translation paths do however get set as expected when running bin/rails console in 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"]
Indeed the I18n documentation states: "The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded."
I've also tried specifying in application.rb
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
But still no joy.
Anyone have any idea what could cause I18n.load_path not to be set only when running assets:precompile?
Thanks for any ideas
rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
This is actually due to a asset configuration flag that you probably have set in your config/application.rb.
config.assets.initialize_on_precompile = false
The rake assets:precompile rake task checks for this flag, and if found to be false, only loads the assets group and does not fully initialize the application. In turn, application locales are not added to the I18n.load_path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With