Forum: Ruby on Rails Gettext and rails

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.
Albert R. (Guest)
on 2006-02-27 21:28
(Received via mailing list)
Hi

Im using the newest GetText gem, and Im having problems with classes
outside rails, they don't get translated. For example: I have a class
representing access in my app, and it is not a ActiveRecord, just a
normal class. When require 'gettext' and include it in the class, I can
use the _('') methods fine. They get picked upp by rake updatepo. But
they dont get translated in my app. I then tried adding the line -
bindtextdomain("myapp") but I couldnt get it to work, it claimed there
was no such method. What am I doing wrong here?

Regards,
Albert
unknown (Guest)
on 2006-02-28 03:44
(Received via mailing list)
Hi Albert,

On Tue Feb 28 04:25:15 JST 2006
Albert R. <removed_email_address@domain.invalid> wrote:

> Hi
>
> Im using the newest GetText gem, and Im having problems with classes
> outside rails, they don't get translated. For example: I have a class
> representing access in my app, and it is not a ActiveRecord, just a
> normal class. When require 'gettext' and include it in the class, I can
> use the _('') methods fine. They get picked upp by rake updatepo. But
> they dont get translated in my app. I then tried adding the line -
> bindtextdomain("myapp") but I couldnt get it to work, it claimed there
> was no such method. What am I doing wrong here?

It may be a bug of Ruby-GetText.
I would like to investigate it.
Could you send your app or a sample code to me directly?
Albert R. (Guest)
on 2006-03-02 15:11
(Received via mailing list)
Hi folks

Masao solved the problem I had, and I'll post the solution here for you:

In every module that you need translations add this at the top:

helper GetText::Rails
include GetText::Rails
extend GetText::Rails

Then if you do the init_gettext in your application.rb you should be all
set. Child classes get the extension automatically, so you only need to
edit the ancestor class.

In our app, we solve the DRY conundrum by making a module like this:

module Translate
helper GetText::Rails
include GetText::Rails
extend GetText::Rails
end

And include this in every class instead of the three lines above. Minor
change, but makes it easier to handle changes in the gettext api.

Also, we noticed that ActionMailer::Base dont get the gettext goodies,
so include this somewhere to make it join the multilingual club:

module ActionMailer #:nodoc:
class Base
helper GetText::Rails
include GetText::Rails
extend GetText::Rails
end
end

Regards,
Albert / http://albert.delamednoll.se
Masao M. (Guest)
on 2006-03-02 15:17
(Received via mailing list)
Hi Albert,

On Thu, 02 Mar 2006 14:11:09 +0100
Albert R. <removed_email_address@domain.invalid> wrote:

> Hi folks

> Also, we noticed that ActionMailer::Base dont get the gettext goodies,
> so include this somewhere to make it join the multilingual club:
>
> module ActionMailer #:nodoc:
> class Base
> helper GetText::Rails
> include GetText::Rails
> extend GetText::Rails
> end
> end

I'll add this feature to next release of ruby-gettext.

Thanks so much!
Masao
Kristian H. (Guest)
on 2006-03-02 15:50
(Received via mailing list)
> In our app, we solve the DRY conundrum by making a module like this:
>
> module Translate
> helper GetText::Rails
> include GetText::Rails
> extend GetText::Rails
> end
>

Just a small remark. In module Translation don't call `helper' I think
that's a call to a Rails-method.

;)

/Kristian
This topic is locked and can not be replied to.