Search code examples
ruby-on-railsdeviseinternationalizationlocaledeprecated

Devise looking for wrong locale on Rails 4.0.2


I've just 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

in my config/application.rb file.

It worked pretty well on Development, all tests passed, and I was happy... Then I deployed my work in a staging server and it crashed!

Devise is looking for a locale :pt. All I have is a locale :pt-BR. I set it in my application.rb:

config.i18n.default_locale = 'pt-BR'

I don't know why devise is looking for :pt only. My locales in the config folder are: pt-BR.yml and devise.pt-BR.yml.

I tried to change the file name from devise.pt-BR.yml to devise.pt.yml (and inside from pt-BR to pt) and it worked.

I had to go back and set:

I18n.config.enforce_available_locales = false

to make it work.

I have two questions:

1 - Why this is not happening on the tests and on development?

2 - Why Devise is asking for :pt, if I'm setting the default locale as :pt-BR in my config?

Thanks in advance


Solution

  • Add devise-i18n to your Gemfile to get the pt-BR locale file for the Devise strings. This fixes the production problem.

    As for why you're not seeing the issue in development, it may be because you're not triggering the specific I18n.t lookup - you need to narrow it down. Some Devise string is triggering this, and I suspect it won't cause an error until that string gets looked up. You need to narrow down the exact set of actions that causes the issue. If it's failing on startup, there might be some production eager loading going on that triggers the issue.