Modify Devise reset password error text - ruby-on-rails

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"

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

Modify error messages for validation with an option

I have already modified quite a few option error messages as shown below
en:
activerecord:
attributes:
user:
name: "Name"
email: "E-mail address"
password: "Password"
password_confirmation: "Password confirmation"
errors:
messages:
blank: "%{attribute} is required"
taken: "%{attribute} is already taken"
invalid: "%{attribute} is not valid"
models:
user:
attributes:
password:
confirmation: "%{attribute} doesn't match confirmation"
Yet, I don't know how I can modify the error message for the length when it's not within a specified range. I know it's possible to do so (http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models) but I don't know how?
Thanks,
I found these tags in my app. One of those should work for you!
equal_to: must be equal to %{count}
greater_than: must be greater than %{count}
greater_than_or_equal_to: must be greater or equal to %{count}
less_than: must be less than %{count}
less_than_or_equal_to: must be less or equal than %{count}
too_long:
one: 'is to short (max than: 1 character)'
other: 'is to long (max than: %{count} characteres)'
too_short:
one: 'is to short (min: 1 character)'
other: 'is to short (min: %{count} characteres)'
wrong_length:
one: doesn't have the right length (1 character)
other: doesn't have the right length (%{count} characteres)
other_than: must be different than %{count}

Translate devise labels in registration?

I want to translate my labels in registration form, but I can't see what is the schema to follow in my .es locale. It wont work with "registrations". Someone knows? I can't find a correct answer in all the internet. Thanks
.es locale
devise:
registrations:
name: "Nombre"
email: "Email"
password: "Contraseña"
password_confirmation: "Recordarme"
It's done via active record translations
es:
activerecord:
attributes:
user:
password: "Contraseña"
email: "Email"
password_confirmation: "Recordarme"

How can I change devise alert message for password_confirmation

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"

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