Devise: Devise is not using my devise.en.yml file; using it's own instead

Created on 18 Sep 2015  路  4Comments  路  Source: heartcombo/devise

Hi there,

I've configured my authentication keys to look up :email as well as another key, I'll call it :account_id. In the form I'm setting the account_id in a hidden field. When authentication fails, the flash message says "Invalid email, account_id, or password". I want to exclude the 'account_id' from that message, so I have my devise.en.yml file read as follows:

en:
    devise:
        failure:
          ...
          invalid: 'Invalid email or password.'
          ...

Unfortunately no matter what I do I cannot get devise to read this file, it insists upon using it's native devise.en.yml file. Is this a bug or am I missing a configuration?

Thanks

Most helpful comment

I ran into this issue specifically with the :invalid key. In my case the issue was not with the translation files themselves, but there was another error key that also generate the same message as :invalid. In my particular case :not_found_in_database - this key will be used instead of :invalid under certain circumstances.

This key was added in 4.5.0, so this can happen to anyone upgrade to 4.5.0 or later.

All 4 comments

There's nothing special, as long as it's in your locale folder and the app is restarted after the file is added, it should work.

You'll need to provide us with more information on how to reproduce the problem, if possible an example app, to investigate. Thanks!

@jmarchello I am having the same problem, were you able to find a way to fix the issue? I can change some of the messages and have them take effect, for example "unauthenticated", but "invalid" will not pick up my changes from the devise.en.yml file.

Edit: it turns out I had to make the change in config/locales/en.yml, not devise.en.yml. For anyone else wondering.

To customize messages shown in english,

  1. Go to config/locales/devise.en.yml and change the message you want to display.
  2. Add the name of your devise resource (it's _user_ by default) in your yml file before the key/value pairs you want to change.
    For example:
en:
 devise:
   failure:
     user: #this is the line you add
       already_authenticated: "Custom already authenticated message."
       inactive: "Custom account not active message."
   sessions:
     user: # your devise resource
       signed_in: "Custom signed in message"
       signed_out: "Custom signed out message"

Source: Devise README

Remember indentations in yml files are important, check everything is in order, and use spaces instead of tabs.

I ran into this issue specifically with the :invalid key. In my case the issue was not with the translation files themselves, but there was another error key that also generate the same message as :invalid. In my particular case :not_found_in_database - this key will be used instead of :invalid under certain circumstances.

This key was added in 4.5.0, so this can happen to anyone upgrade to 4.5.0 or later.

Was this page helpful?
0 / 5 - 0 ratings