Error messages in other languages?

How can one change the messages that are shown in the flash for
validates… to different languages?

Roman H. wrote:

How can one change the messages that are shown in the flash for
validates… to different languages?

I am sure I can’t be the first one who wants to use the validation
methods with error messages that are not in English?

Is there a package for other languages or is it possible to override the
built-in message texts somehow?

Roman H. wrote:

Is there a package for other languages or is it possible to override the
built-in message texts somehow?

There are some docs for ruby on rails :
http://api.rubyonrails.org/

For example validates_length_of
(http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000814)

suggests, for example,

validates_length_of :last_name, :maximum=>30, :message=>“less than %d
if you don’t mind”

where :message can be redefined.

The default error messages can also be added to, or changed, see the
documentation for ActiveRecord::Errors

http://api.rubyonrails.org/classes/ActiveRecord/Errors.html

Regards,

Chris

On Nov 2, 2006, at 10:38 AM, Roman H. wrote:

Roman H. wrote:

How can one change the messages that are shown in the flash for
validates… to different languages?

I am sure I can’t be the first one who wants to use the validation
methods with error messages that are not in English?

Is there a package for other languages or is it possible to
override the
built-in message texts somehow?

http://www.agilewebdevelopment.com/plugins/localization_simplified

Roman H. wrote:

built-in message texts somehow?

Have a look here:
http://wiki.rubyonrails.org/rails/pages/Internationalization and at the
Globalize plugin. I haven’t yet use it (or any of the other options, but
believe there’s a fairly active community, including a dedicated group:

http://www.ruby-forum.com/forum/20

HTH

http://www.agilewebdevelopment.com/plugins/localization_simplified

This simple localization is great, but it still uses my english model
field names in validation error messages. Any way of overriding those?

TIA
Nick

I don’t see a way of overriding the model field names. instead, just
build your own error_messages_for method as a application helper.

just have a look at the source of error_messages_for() in the API
docs, its really simple. and instead of using the model field names,
include the translated name in the validation message like :
validates_length_of :last_name, :maximum=>30, :message=>“Last Name
has to be less than %d”

your own error_messages_for() in y<our ApplicationHelper could look
something like this:

e.g. (very simple example):

def my_error_messages_for(object)
message = String.New
object.errors.each do |attr,msg|
message << “#{msg}
\n”
end
message
end

(attr would be the model field name producing the error, msg would be
the message set with :message in the validation)

Roman H. wrote in post #160733:

How can one change the messages that are shown in the flash for
validates… to different languages?

Hi ,

Me too come across a situation like getting validation messages in
different languages .And done that successfully.

Here is an example :

/app/config/locales/models/en.yml

Models

en:
activerecord:
errors:
models:
Modelname:
blank: “FirstName cannot be blank!”

Similarly create a file for other language with blank message in
different lang.

And in your model for eg

you r having a
validates_presence_of :fieldname1
By default validates_presence_of gives you the message as cant be blank
which is now will be replaced by “FirstName cannot be blank!”
(customised)

– Aruna

Nic wrote in post #209083:

http://www.agilewebdevelopment.com/plugins/localization_simplified

This simple localization is great, but it still uses my english model
field names in validation error messages. Any way of overriding those?

It is possible, but I don’t remember how off the top of my head.
There’s been some discussion of this before, so if you search the list
archives, you’ll probably find what you need.

TIA
Nick

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This simple localization is great, but it still uses my english model

field names in validation error messages. Any way of overriding those?

elmer.yml

activerecord:
errors:
models:
rabbit: wabbit
attributes:
rescription: descwiption
language: wanguage

Radhames Brito wrote in post #956359:

This simple localization is great, but it still uses my english model

field names in validation error messages. Any way of overriding those?

elmer.yml

activerecord:
errors:
models:
rabbit: wabbit
attributes:
rescription: descwiption
language: wanguage

Gweat example!

Best,

Marnen Laibow-Koser
http://www.marnen.org
removed_email_addre[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs