# Gettext and rails

**URL:** <https://www.ruby-forum.com/t/gettext-and-rails/74319>\
**Category:** Rails\
**Created:** [February 27, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319 "2006-02-27T20:28:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Albert\_R](https://www.ruby-forum.com/u/Albert_R)\
**Post date:** [February 27, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319/1 "2006-02-27T20:28:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Albert\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Albert\_R](https://www.ruby-forum.com/u/Albert_R)\
**Post date:** [February 28, 2006, 2:44am UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319/2 "2006-02-28T02:44:55Z")

</div>

Hi Albert,

On Tue Feb 28 04:25:15 JST 2006  
Albert R. [removed\_email\_address@domain.invalid](mailto: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?

---

<div class="post-metadata">

**Author:** ![Albert\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Albert\_R](https://www.ruby-forum.com/u/Albert_R)\
**Post date:** [March 2, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319/3 "2006-03-02T14:11:40Z")

</div>

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](http://albert.delamednoll.se)

---

<div class="post-metadata">

**Author:** ![Albert\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Albert\_R](https://www.ruby-forum.com/u/Albert_R)\
**Post date:** [March 2, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319/4 "2006-03-02T14:17:05Z")

</div>

Hi Albert,

On Thu, 02 Mar 2006 14:11:09 +0100  
Albert R. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![Albert\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@Albert\_R](https://www.ruby-forum.com/u/Albert_R)\
**Post date:** [March 2, 2006, 2:50pm UTC](https://www.ruby-forum.com/t/gettext-and-rails/74319/5 "2006-03-02T14:50:51Z")

</div>

> 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
