Ruby On RailsWhile using Rails in my projects I’ve came up with the need to display error messages in my native language, Portuguese.
So following my last plugin on plural rules in Rails models, I’ll now quickly explain how to add custom messages to any Rails application.

Quite simply create a file called messages.rb in your /config directory (or anywhere you want) and write the following:

module ActiveRecord
class Errors
@@default_error_messages = {
:inclusion => “não está contido na lista”,
:exclusion => “está reservado”,
:invalid => “é invalido”,
:confirmation => “é diferente da confirmação”,
:accepted => “deve ser aceito”,
:empty => “não pode estar vazio”,
:blank => “não pode estar em branco”,
:too_long => “é muito longo (no máximo %d caracteres)”,
:too_short => “é muito curto (o mínimo são %d caracteres)”,
:wrong_length => “tem comprimento errado (só %d caracteres)”,
:taken => “já está a ser utilizado”,
:not_a_number => “não é um número”
}
end
end

All ActiveRecord messages are overwritten, now we just need to tell our app to call the file with the code, go to your /config/environment.rb and insert the following line:

require “#{RAILS_ROOT}/app/config/messages”

That should do the trick. Manik Juneja, a Technopreneur and blogger from Delhi explained in his blog how to further customize your messages, head down to his blog for more detailed explanation.

On another note, I’ll be announcing a new Ruby on Rails project soon. :)
I’ve had some problems with the site and all the content was deleted so during the weekend I’m going to try my best to rewrite everything.