How to silence "I18n.enforce_available_locales" deprecation warnings

Updated . Posted . Visible to the public.

Before Rails 3.2.14, when supplying an invalid locale to I18n, it would fall back to its config.i18n.default_locale (which is :en by default). Eventually, this will be changed to raise an error by default -- for now, it shows a deprecation warning.

Since Rails 3.2.14 and 3.2.15 did not include security updates, you might not have applied them and probably now encounter these deprecation warnings after upgrading to 3.2.16 Show archive.org snapshot (or 4.0.2):

[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.

As a quick fix, put the following code into your config/application.rb to restore the previous behavior and make the warning go away. Make sure to put it above all other config.i18n calls, or the warning might not disappear.

config.i18n.enforce_available_locales = false

If the warning still sticks around, try saying I18n.enforce_available_locales = false instead.

However, you may actually want to raise an error on unsupported locales. If possible, set to true and see if that works for you:

config.i18n.enforce_available_locales = true

For details, see the linked Stack Overflow post.

Arne Hartherz
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2013-12-05 08:58)