Here is how to localize the Rails error messages that come from a model’s validation methods. Add the following example statements to the file config/environment.rb (example shows Dutch localization strings)
# Nederlandse error messages
ActiveRecord::Errors.default_error_messages[:inclusion] = " is niet opgenomen in de lijst"
ActiveRecord::Errors.default_error_messages[:exclusion] = " is niet toegestaan in de lijst"
ActiveRecord::Errors.default_error_messages[:invalid] = " is ongeldig"
ActiveRecord::Errors.default_error_messages[:confirmation] = " is niet gelijk aan de bevestiging"
ActiveRecord::Errors.default_error_messages[:accepted] = " moet geaccepteerd worden"
ActiveRecord::Errors.default_error_messages[:empty] = " mag niet leeg zijn"
ActiveRecord::Errors.default_error_messages[:blank] = " mag niet leeg zijn"
ActiveRecord::Errors.default_error_messages[:too_long] = " is te lang (max is %d tekens)"
ActiveRecord::Errors.default_error_messages[:too_short] = " is te kort(min is %d tekens)"
ActiveRecord::Errors.default_error_messages[:wrong_length] = " heeft de verkeerde lengte (moet %d tekens zijn)"
ActiveRecord::Errors.default_error_messages[:taken] = " is al in gebruik"
ActiveRecord::Errors.default_error_messages[:not_a_number] = " is geen getal"
Reload your webserver after saving the file.
OK…But How to change the localisation on the fly to make a multilingual app?
Also, how to supply a noun here? Saying ”Name is al in gebruik” is not fully localized sollution. There must be a way to supply our own Name. Don’t forget that there are names of days of week and months too.
see also OverridingRailsMessagesInAnotherLanguage
—
Try Ruby-GetText it has already have a solution to localize “Name”.
http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#Models
*It also localizes the default error messages.
Screenshots in many languages are also available:
http://www.yotabanana.com/hiki/ruby-gettext-screenshot.html
GlobaLite localization made simple and lite. Read more would do that for you. If your language is not supported, you can easily edit/create a yml language file and don’t have to mess up with the code.