How can I change devise alert message for password_confirmation - ruby-on-rails

I am trying to change the alert message from the standard "doesn't match Password" to "The passwords do not match" but I can't figure out how to do it. I've already tried adding the following to my devise.en.yml file:
activerecord:
errors:
models:
user:
attributes:
password:
confirmation: "hey you billy"
blank: "cannot be blank."
invalid: "this password be invalid yo"
but this does not work. The blank message works but confirmation does not. Does anyone know how to fix this?

Try setting 'confirmation' on the 'password_confirmation' attribute instead;
activerecord:
errors:
models:
user:
attributes:
password_confirmation:
confirmation: "The passwords do not match"

Related

how to locale field Devise?

I used gem Devise for authentication in my application . I want to change label text for below input
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
but I can not find this field for standard renaming either in the service files or in the devise locale
how to locale this field ?
presently
check-box "Remember me"
_
need
check-box "Запомнить меня"
en.yml
en:
activerecord:
attributes:
user:
email: Email
password: Password
remember_me: Remember me
create new file for any other locale and add translated text for that language
de.yml
de:
activerecord:
attributes:
user:
email: "email in de"
password: "Password in de"
remember_me: "Remember me in de"
You can read more about devise translation here
Here is the very useful site for translations - https://www.localeapp.com/projects/377/translations/5250293?in_locale=5291

Rails translation displaying translation name in front of translation string in browser

In my locale file, there is the following translation:
de:
activerecord:
errors:
models:
user:
attributes:
email:
taken: "Die E-Mail Adresse wird bereits benutzt."
When i open the desired page in my browser, the error message looks like the following:
Email Die E-Mail Adresse wird bereits benutzt.
So does anybody know why there is another "Email" in front of the translated string?
The correct yml structure should be:
de:
activerecord:
models:
user: Dude
attributes:
user:
email: "mail"
errors:
template:
header:
one: "1 error prohibited this %{model} from being saved"
other: "%{count} errors prohibited this %{model} from being saved"
body: "There were problems with the following fields:"
errors:
format: ! '%{attribute} %{message}'
messages:
taken: "Email Die E-Mail Adresse wird bereits benutzt."
Note that there are two "errors" keys, one inside activerecord and another one outside. Use the later for validation messages.
You could get a more full detailed translation file from https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml
You might find the devise translation file at https://github.com/mcasimir/devise-i18n-views/blob/master/locales/en.yml
For my projects, I usually have several translation files for each language:
rails.en.yml: messages used by rails (inspired by the svenfuchs file)
devise.en.yml: messages related to authentication (from the devise project itself)
en.yml: messages I create on my views that doesn't belong to other gems (gems like "simple_form" usually have also their own file)
Edit
From the Rails Internationalization guide, validation messages will be searched in this order:
activerecord.errors.models.user.attributes.name.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.name.blank
errors.messages.blank
So it's correct to use what you posted on the question:
de:
activerecord:
errors:
models:
user:
attributes:
email:
taken: "http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models"

Modify Devise reset password error text

Using the Devise GEM, when a user password is reset they are allowed to set a new password. If the entered passwords do not match or if the password is too short, you get default messages:
•Password doesn't match confirmation
•Password is too short (minimum is 8 characters)
How/where can I change the text of these error messages?
Add this to your config/locals/en.yml and change it to what you want
en:
activerecord:
errors:
models:
user:
attributes:
password:
confirmation: "Password does not match"
too_short: "is too short (minimum is %{count} characters)"
attributes:
user:
password: "Password"

Rails I18n Pluralization Error

I wanted to set a custom error message for when an email was already taken so I edited the config/locales/en.yml file. It looked like this:
en:
activerecord:
models:
user:
email:
taken: "already being used"
When I submit the form with email in it, I get this error:
translation data {:email=>{:taken=>"already being used"}} can not be used with :count => 1
I've only just started looking into i18n so this may be a really simple mistake but I can't find an answer.
Try:
en:
activerecord:
errors:
models:
user:
attributes:
email:
taken: "already being used"
See section 5.1.1 in Rails Guide.
Hope this helps!

All possible model validation errors

I have got a form with a bunch of fields and model validations.
How can I return all possible validation errors that can be raised?
I need it to write locales for all of them.
I want to get a list like this:
password blank
password too_short
password confirmation
login blank
login invalid
email blank
email too_short
email invalid
etc
Basically what Pablo says, except that the page on the rails docs doesn't show how to override the messages for a particular model and field. here's an example from one of my apps:
activerecord:
errors:
full_messages:
format: "{{message}}"
#define standard error messages, which we can overide on per model/per attribute basis further down
messages:
inclusion: "{{attribute}} is not included in the list"
exclusion: "{{attribute}} is reserved"
invalid: "{{attribute}} is invalid"
confirmation: "{{attribute}} doesn't match confirmation"
accepted: "{{attribute}} must be accepted"
empty: "{{attribute}} can't be empty"
blank: "{{attribute}} can't be blank"
too_long: "{{attribute}} is too long (maximum is {{count}} characters)"
too_short: "{{attribute}} is too short (minimum is {{count}} characters)"
wrong_length: "{{attribute}} is the wrong length (should be {{count}} characters)"
taken: "{{attribute}} has already been taken"
not_a_number: "{{attribute}} is not a number"
greater_than: "{{attribute}} must be greater than {{count}}"
greater_than_or_equal_to: "{{attribute}} must be greater than or equal to {{count}}"
equal_to: "{{attribute}} must be equal to {{count}}"
less_than: "{{attribute}} must be less than {{count}}"
less_than_or_equal_to: "{{attribute}} must be less than or equal to {{count}}"
odd: "{{attribute}} must be odd"
even: "{{attribute}} must be even"
record_invalid: "Validation failed: {{errors}}"
models:
quiz:
blank: "{{attribute}} can not be blank"
user_session:
blank: "{{attribute}} can not be blank"
attributes:
login:
invalid: "Please enter your user name"
password:
invalid: "Please note that passwords are case sensitive"
I've also changed the basic format for error messages, as sometimes i didn't want the field name shoved at the start of the message. So, i changed
errors:
format: "{{attribute}} {{message}}"
to
errors:
format: "{{message}}"
Which is why i then specify {{attribute}} in my subsequent errors, to put it back in in most but not all cases.
Note also that i'm using the old syntax of {{var}} rather than %{var}. The same principles apply though.
The latest rails translations are at: rails-i18n.
ActiveRecord errors are under lang:errors and lang:active_record in each .yaml.
Also in your application under config/locales/en.yml is the default.

Resources