Today I battled a subtle problem which surfaced when our Rails application was updated from Rails 4.012 to 4.0.13.
Several tests started failing with I18n::InvalidLocale
errors.
After some debugging I found that the following line of configuration
config/application.rb
was not being respected:
I18n.enforce_available_locales = false
This line was introduced when the application was upgraded to Rails 4.0.2 a year ago. At the time, as this stackoverflow question highlights, the following deprecation warning message advised to do this:
[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.
However, as I digged deeper into the Rails 4.0.13
changes, I
found that they included this
commit,
which changed the behaviour of setting i18n configuration values. It now
ignores I18n.enforce_available_locales = false
.
The solution is to follow the relevant section of the Rails Guides and configure as follows:
config.i18n.enforce_available_locales = false
It’s a subtle change that caught us out.
Previous post: Preparing to speak at RubyConf AU
More recently: Loving Legacy Code
© 2025 Keith Pitty, all rights reserved.