2
votes

I've updated to Rails 4.0.2 and I got the deprecation warning:

[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.

To get rid of the warning, I decided to set:

I18n.config.enforce_available_locales = true
config.i18n.default_locale = :es

in my config/application.rb file.

It worked on Development but when I deploy my work to Heroku I get following error:

-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       :es is not a valid locale
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n.rb:288:in `enforce_available_locales!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n/config.rb:32:in `default_locale='
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.9/lib/i18n.rb:35:in `default_locale='
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:41:in `block in initialize_i18n'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:34:in `each'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:34:in `initialize_i18n'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/i18n_railtie.rb:15:in `block in <class:Railtie>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `call'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/config/environment.rb:5:in `<top (required)>'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:250:in `block in run_tasks_blocks'
       /tmp/build_e6bd0f83-f9f7-45ad-9d98-13384d9403dc/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'

Any ideas how to avoid this error?

Thanks

2
Do you have a config/locales/es.yml file?Ari
Yes, I have config/locales/es.yml and also locale file for devise (devise.es.yml) and simple_form (simple_form.es.yml)Alex Bibiano

2 Answers

7
votes

I think it should work if you set config.i18n.available_locales = [:es] first.

1
votes

This bug:

The reason is due to a bug with locales that have the language-country format. The good news is that it has been fixed already. This was reported in Github with Issue 13164 and fixed with pull request 229.

Read this for more info

config.i18n.enforce_available_locales = boolean

if you use false:
this skip the locale validation don't care about locales
if you use true:
want the application to raise an error if an invalid locale is passed (or) want to default to the new Rails behaviors (or) care about locale validation