rails custom validation messages i18n
I did not find on the net how to override the “{attribute} {message}” format of validation error messages. It is no use in my language. Sometimes I need a different order or specific message. The way I managed to do it using rails 2.3.4 is:
- use validation message in model, for example:
validates_presence_of :login, :message => :login_blank
- Define the message in your locale in the yml, (en.yml, pl.yml or whatever yours is) under the tree (this example is for “pl” locale):
pl:
(...)
activerecord:
(...)
errors:
(...)
full_messages:
login_blank: "My custom message hahaha!"
(...)
I found this by looking at: RAILS_HOME/activerecord/lib/active_record/validations.rb and the comment to generate_full_message method