[Rails] how to override rails errors messages?

Johan Sörensen johans at gmail.com
Tue Jan 18 22:44:27 GMT 2005


Which error messages are you referring to? 
If you mean the ones created by the validation macros, then there's a
parameter for your own message, eg:

validates_uniqueness_of :username, { :message => "Användarnamnet är
redan registrerat" }

and if you're using english column names (ie "username" which, in for
example swedish, would be "användarnamn") you can either create a
lookup table in your model that "translates" the attribute name for
display purposes, or as in the above example, simply take the easy
road and pass the field/attribute name in the error message. Then you
can output it in you view with something like this:

<% if @post.errors.count > 0 %>
  <h3>The following errors was found</h3>
  <ul>
  <% @post.errors.each do |attr_name, message| %>
    <li><%= message %></li>
  <% end %>
  </ul>
<% end %>

This means of course that you'll have to pass the attribute name in
every error message, but to my knowledge that is the easiest way.


However, if you where talking about a full-on localization module
there doesn't seem to be anything done together with rails yet, apart
from the yaml implemention in RForum (as alexey said)

-- johan

On Mon, 17 Jan 2005 01:35:13 +0100, olivier hericord <hangonsoft at free.fr> wrote:
> hi,
> 
> how can i override rails errors mesages (that are in english) to
> display them in an other language?
> 
> thanks
> 
> hangon
> 
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> 


-- 
Johan Sørensen
Professional Futurist
www.johansorensen.com


More information about the Rails mailing list