Forum: Ruby on Rails Translating a validtion flash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Johan Van M. (Guest)
on 2006-01-31 00:52
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.
M Daggett (Guest)
on 2006-01-31 00:54
(Received via mailing list)
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
>


--
Johan V. (Guest)
on 2006-01-31 01:06
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?
Dave T. (Guest)
on 2006-01-31 01:06
(Received via mailing list)
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.
Johan V. (Guest)
on 2006-01-31 01:12
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.
Alain R. (Guest)
on 2006-01-31 01:33
(Received via mailing list)
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_valida...


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
Masao M. (Guest)
on 2006-01-31 01:45
(Received via mailing list)
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-...
Masao M. (Guest)
on 2006-01-31 02:16
(Received via mailing list)
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-screen...

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
Johan V. (Guest)
on 2006-01-31 10:48
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.
This topic is locked and can not be replied to.