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:
A. use validation message in model, for example:

  validates_presence_of     :login, :message => :login_blank

B. 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

This entry was posted on Mon, 16 Nov 2009 18:23:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment .
Tags , ,


Comments

Leave a response

Leave a comment

Please enter the outcome of the equation:
Draw_image