Topic: Ruby language dependent or independent

Hi All,

I am Mitesh Jain,
1) I am displaying an error message to my user as "Invalid user name or password" but my user does not understand English he wants the message to be displayed in German. How can i change it.

Thanking you
Mitesh Jain

Re: Ruby language dependent or independent

I'm assuming you want to change the error messages of the built-in validation methods.

When you use a validation method, you can specify a custom error message on a case by case basis through the optional message param. For instance:

validates_acceptance_of :eula, :message => "must be abided"

Otherwise, you could try editing the ActiveRecord::Errors.default_error_messages hash so changes affect all validations. This is what the hash contains:

>> y ActiveRecord::Errors.default_error_messages
---
:invalid: is invalid
:wrong_length: is the wrong length (should be %d characters)
:confirmation: doesn't match confirmation
:taken: has already been taken
:accepted: must be accepted
:not_a_number: is not a number
:blank: can't be blank
:inclusion: is not included in the list
:too_long: is too long (maximum is %d characters)
:empty: can't be empty
:exclusion: is reserved
:too_short: is too short (minimum is %d characters)

Try putting German translations (the following courtesy of babelfish) at the end of config/environments.rb:
ActiveRecord::Errors.default_error_messages.merge!(
  :not_a_number => 'nicht ist eine zahl',
  :exclusion    => 'ist reserviert'
)

Vincent Woo Ruby on Rails Blog

Re: Ruby language dependent or independent

vwoo wrote:

I'm assuming you want to change the error messages of the built-in validation methods.

When you use a validation method, you can specify a custom error message on a case by case basis through the optional message param. For instance:

validates_acceptance_of :eula, :message => "must be abided"

Otherwise, you could try editing the ActiveRecord::Errors.default_error_messages hash so changes affect all validations. This is what the hash contains:

>> y ActiveRecord::Errors.default_error_messages
---
:invalid: is invalid
:wrong_length: is the wrong length (should be %d characters)
:confirmation: doesn't match confirmation
:taken: has already been taken
:accepted: must be accepted
:not_a_number: is not a number
:blank: can't be blank
:inclusion: is not included in the list
:too_long: is too long (maximum is %d characters)
:empty: can't be empty
:exclusion: is reserved
:too_short: is too short (minimum is %d characters)

Try putting German translations (the following courtesy of babelfish) at the end of config/environments.rb:
ActiveRecord::Errors.default_error_messages.merge!(
  :not_a_number => 'nicht ist eine zahl',
  :exclusion    => 'ist reserviert'
)

No,it is not validation messages it is some thing like while uplaoding a excel file i have messages like "Value is invalid at row 5" but there are almost 20 errors of this type and all this error messages are given in English how can i change it to German,

Is there any method which has an option called language which will change all the messages from English to German.

Re: Ruby language dependent or independent

Someone can certainly correct me if I am wrong, but I believe a manual operation will be the quickest and easiest (if not only) option.