Translating a validtion flash


#1

I’m a belgian Rails user (Dutch is my native language). I wondered if
it is possible to translate error messages (generated by validators).

I know how to create my own error messages:

def method
content
rescue
logger.error(…)
flash[:notice] = 'My own error message"
redirect_to(…)

But where can I find the validator’s .rb files, so I can change them?

Johan.


#2

Hi Johan,
you can append a :message=> parameter to any validation to override
the default message.

On 1/30/06, Johan Van M. removed_email_address@domain.invalid wrote:

redirect_to(…)
http://lists.rubyonrails.org/mailman/listinfo/rails


#3

Thank you for your quick reply…
It works :slight_smile:

Although I’m facing another problem now:

because my MySQL column names are in english, I get error messages which
mix english and dutch:

“english column name + dutch errormessage”

Could I use dutch column names? I guess table names HAVE to be english
(plurar form of the model’s class). What about columns?


#4

You might find this useful: http://wiki.rubyonrails.org/rails/pages/
OverridingRailsMessagesInAnotherLanguage.

However, AFAIK, Rails still doesn’t have a good story when it comes to
i18n. I’m not sure how you would dynamically change the messages based
on the user’s locale.

On Monday, January 30, 2006, at 2:53 PM, M Daggett wrote:


I am Mark Daggett and I approve this message.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Cheers!
–Dave.


#5

Johan

> I'm a belgian Rails user (Dutch is my native language).  I

wondered if
> it is possible to translate error messages (generated by
validators).

My workaround is to :

  • translate the validation error message with the
    custom_validation_messages
    plugin

  • hide what cannot be translated with css

=>
step 1: in the css:

  #errorExplanation h2, div#errorExplanation p  {
      display:none;		/* UGLY WORKAROUND, because the msg is in 

English*/
}

step 2: install the plugin
http://estound.com/svn/rails/plugins/custom_validation_messages/

step 2: in the model, translate

   validates_presence_of :first_name, :message => "[Le prénom est

manquant]"

(notice the ‘[’ and ‘]’: it’s the plugin convention to override
completely the error message, instead of appending)

Alain


#6

Dave T. wrote:

You might find this useful: http://wiki.rubyonrails.org/rails/pages/
OverridingRailsMessagesInAnotherLanguage.

However, AFAIK, Rails still doesn’t have a good story when it comes to
i18n. I’m not sure how you would dynamically change the messages based
on the user’s locale.

Thanks,

That’s what I was looking for.
I also noticed this project: http://www.globalize-rails.org/wiki/
But I hoped to solve my problem without the use of a plugin.


#7

Hi,

On Tue, 31 Jan 2006 00:12:49 +0100
Johan Van M. removed_email_address@domain.invalid wrote:

That’s what I was looking for.
I also noticed this project: http://www.globalize-rails.org/wiki/
But I hoped to solve my problem without the use of a plugin.

Ruby-GetText-Package has already support this.

See:
http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#Models


#8

Hi,

On Tue, 31 Jan 2006 00:06:25 +0100
Johan Van M. removed_email_address@domain.invalid wrote:

Could I use dutch column names? I guess table names HAVE to be english
(plurar form of the model’s class). What about columns?

Ruby-GetText-Package has already supported this.

See the screenshot page below, there have already exist dutch
translation.
You can find the column names are translated in dutch(compare screenshot
in English)
http://www.yotabanana.com/hiki/ruby-gettext-screenshot.html#Dutch

I think you need to try it ;).

There are 2 tutorials:
http://manuals.rubyonrails.com/read/chapter/105
http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html


#9

Dear Masao M.,

Thank you for your help.
I will be using gettext in the future.

You wrote a wonderfull tutorial, and the screenshots are great too!

Johan.