Forum: Ruby on Rails How to use gettext in plugins?

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.
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-09 07:36
I use rails-engine as a plugin of the application and I want to localize
the validate message from the plugin:

validates_length_of :login, :within => 3..40, :on => :create, :message
=> N_("%{fn} is too short (min is %d characters)")

It can not display the according language,where should i set it?
I have tried to add
require 'gettext/rails'
GetText.bindtextdomain("myd2d")
to init_engine.rb or somewhere else,it can not work still.

Thanks
Charlie
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 unknown (Guest)
on 2006-05-09 09:07
(Received via mailing list)
Hi charlie,

At first, did you fix your previous problem?

http://www.ruby-forum.com/topic/64942#new

If not, fix the problem first.
Because it may cause this problem.

Then,
a similer problem that "validates_lenth_of doesn't translate anything"
are reported by other person today. So I'll investigate it ASAP.

But if you have other informations about this.
Report it more detail as you can, please.
For example, validation in your model(not plugins) works,
or every other messages are localized correctly, etc.


On Tue May 09 14:36:51 JST 2006
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-09 09:32
Hi, the previous problem you mentioned has been fixed,I use cookie to
set local and it can work,however if i directly set local using the api
that i used before,it can not work.
I am still working this problem,and now I am clear that it is the reason
of validates_lenth_of 's not working well,but other validates can work
in
PLUGINS,eg:validates_uniqueness_of,validates_confirmation_of,validates_presence_of
sometimes validates_lenth_of can translate,but sometimes not,i am still
summarizing the rules.

unknown wrote:
> Hi charlie,
>
> At first, did you fix your previous problem?
>
> http://www.ruby-forum.com/topic/64942#new
>
> If not, fix the problem first.
> Because it may cause this problem.
>
> Then,
> a similer problem that "validates_lenth_of doesn't translate anything"
> are reported by other person today. So I'll investigate it ASAP.
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-09 09:49
I have tested the validates_lenth_of translation both in activemodels
and plugins,and i think it has some bugs:

validates_length_of :login, :minimum => 5, :on => :create, :message =>
N_("%{fn} is too short (min is %d characters)")

if the string above include "%d",then validates_length_of string will
not be translated by gettext,or else it can be done.

Thanks
Charlie


charlie wrote:
> Hi, the previous problem you mentioned has been fixed,I use cookie to
> set local and it can work,however if i directly set local using the api
> that i used before,it can not work.
> I am still working this problem,and now I am clear that it is the reason
> of validates_lenth_of 's not working well,but other validates can work
> in
> PLUGINS,eg:validates_uniqueness_of,validates_confirmation_of,validates_presence_of
> sometimes validates_lenth_of can translate,but sometimes not,i am still
> summarizing the rules.
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2006-05-09 18:54
(Received via mailing list)
Hi,


On Tue, 9 May 2006 09:49:15 +0200
charlie <blogyingfeng@gmail.com> wrote:

> I have tested the validates_lenth_of translation both in activemodels
> and plugins,and i think it has some bugs:
>
> validates_length_of :login, :minimum => 5, :on => :create, :message =>
> N_("%{fn} is too short (min is %d characters)")
>
> if the string above include "%d",then validates_length_of string will
> not be translated by gettext,or else it can be done.

Thanks for reporting.

I fixed them. Could you try it and report the result?

1. Get the newest rails.rb Revison 1.34 from:
http://rubyforge.org/cgi-bin/viewcvs.cgi/gettext/l...

2. Replace this file to your rails.rb
(e.g. /usr/lib/ruby/gems/1.8/gems/gettext-1.5.0/lib/gettext/rails.rb)

3. Try validates_length_of at models.
4. Then try validates_length_of at plugins.
2e5a77bf26f7cab677f33537c8495fbf?d=identicon&s=25 charlie (Guest)
on 2006-05-10 03:14
Masao Mutoh wrote:
> Hi,
> Thanks for reporting.
> I fixed them. Could you try it and report the result?

Hi,I have tested ant it works well now,very grateful!

Charlie
This topic is locked and can not be replied to.