# Translating a validtion flash

**URL:** <https://www.ruby-forum.com/t/translating-a-validtion-flash/99097>\
**Category:** Rails\
**Created:** [January 30, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097 "2006-01-30T23:52:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 30, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/1 "2006-01-30T23:52:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 30, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/2 "2006-01-30T23:54:21Z")

</div>

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](mailto:removed_email_address@domain.invalid) wrote:

> redirect\_to(…)  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 12:06am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/3 "2006-01-31T00:06:25Z")

</div>

Thank you for your quick reply…  
It works 🙂

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?

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 12:06am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/4 "2006-01-31T00:06:31Z")

</div>

You might find this useful: [http://wiki.rubyonrails.org/rails/pages/](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](http://lists.rubyonrails.org/mailman/listinfo/rails)

Cheers!  
–Dave.

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 12:33am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/5 "2006-01-31T00:33:44Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 12:12am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/6 "2006-01-31T00:12:49Z")

</div>

Dave T. wrote:

> You might find this useful: [http://wiki.rubyonrails.org/rails/pages/](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/](http://www.globalize-rails.org/wiki/)  
But I hoped to solve my problem without the use of a plugin.

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 12:45am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/7 "2006-01-31T00:45:50Z")

</div>

Hi,

On Tue, 31 Jan 2006 00:12:49 +0100  
Johan Van M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That’s what I was looking for.  
> I also noticed this project: [http://www.globalize-rails.org/wiki/](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](http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#Models)

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 1:16am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/8 "2006-01-31T01:16:05Z")

</div>

Hi,

On Tue, 31 Jan 2006 00:06:25 +0100  
Johan Van M. [removed\_email\_address@domain.invalid](mailto: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](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://manuals.rubyonrails.com/read/chapter/105)  
[http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html](http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html)

---

<div class="post-metadata">

**Author:** ![papacostas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@papacostas](https://www.ruby-forum.com/u/papacostas)\
**Post date:** [January 31, 2006, 9:48am UTC](https://www.ruby-forum.com/t/translating-a-validtion-flash/99097/9 "2006-01-31T09:48:27Z")

</div>

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.
