# Ruby-gettext rails.mo issue

**URL:** <https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167>\
**Category:** Rails I18n\
**Created:** [December 3, 2006, 11:45am UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167 "2006-12-03T11:45:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 11:45am UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/1 "2006-12-03T11:45:40Z")

</div>

I’m glad that I found this list. Trying my first steps  
with Rails, I found out that ruby-gettext is best suited  
for my i18n needs. There’s one problem, though:

I’ve done a first rough custom translation of rails.po.  
(The language I need is not shipped with ruby-gettext).  
It works fine if I install the corresponding rails.mo  
file into a system locale directory, i.e., into  
/usr/lib/ruby/gems/1.8/gems/gettext-1.8.0/data/locale/eo.

However, I suppose that my webspace provider won’t put  
a file into a system directory only for me. So I tried  
to put the file into RAILS\_ROOT/locale/eo. But as it turns  
out, ruby-gettext is not interested in the file if I put  
it there.

Any hints?

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 1:48pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/2 "2006-12-03T13:48:33Z")

</div>

Hi Malte,

the directory in which ruby-gettext creates the .mo files should be  
the right directory.

If I convert the po-file from

APP\_ROOT/po/xxx.pot  
APP\_ROOT/po//xxx.po

ruby-gettext creates an mo-file in

APP\_ROOT/locale//LC\_MESSAGES/rails.mo

(where tag is like de\_DE or en\_GB).  
And it works fine.

Here is my rakefile:

require ‘gettext/utils’  
namespace:gettext do  
desc “Update pot/po files to match new version.”  
task :updatepo do  
GetText.update\_pofiles(“de”, Dir.glob(“app/\*\*/\*.{rb,rhtml}”),  
“xxx 1.0”)  
end

desc “Create mo-files for L10n”  
task :makemo do  
GetText.create\_mofiles(true, “po”, “locale”, “%s/LC\_MESSAGES”)  
end  
end

rake gettext:updatepo  
rake gettext:makemo

Don’t forget to insert

init\_gettext “rails”

into your ApplicationController.

You can also add a path using:

add\_default\_local\_path(“…/locale/%{tag}/LC\_MESSAGES/%{name}.mo”)

May that helps.

Am 03.12.2006 um 11:45 schrieb Malte M.:

> However, I suppose that my webspace provider won’t put  
> Railsi18n-discussion mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/railsi18n-discussion](http://rubyforge.org/mailman/listinfo/railsi18n-discussion)

* * *

Thomas B.  
[b-simple.de](http://b-simple.de) - Ruby on Rails, Java EE, Entwicklung, Coaching  
fon: +49(40)411 622 35 mobil: +49(173)23 911 43  
fax: +49(40)411 622 36 email: thomas.baustert(at)[b-simple.de](http://b-simple.de)

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/3 "2006-12-03T15:15:00Z")

</div>

Moin Thomas, thanks for your reply. I’m afraid your advice did  
not really help me. Maybe I should try and state the point of  
my problem clearer.

Thomas B. wrote:

> Don’t forget to insert
> 
> init\_gettext “rails”
> 
> into your ApplicationController.

Basically, Gettext is working for me (translating e.g. table  
names), which means that I have done this already. The thing  
which does not work is only related to my rails.mo file,  
generated from rails.po. This is po/rails.pot in the ruby-  
gettext source directory. It contains default messages for  
rails Ã la “%{num} errors prohibited this %{record} from being  
saved”.

> You can also add a path using:
> 
> add\_default\_local\_path("…/locale/%{tag}/LC\_MESSAGES/%{name}.mo")

Actually, when the application is running, the path is set right:

$ ls locale/eo/LC\_MESSAGES/  
eventoj.mo rails.mo

$ ./script/console  
Loading development environment.  
irb\> ApplicationController.add\_default\_locale\_path ‘foo’  
=\> [“foo”,  
“/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%{name}.mo”,  
“/usr/share/locale/%{locale}/LC\_MESSAGES/%{name}.mo”,  
“/usr/local/share/locale/%{locale}/LC\_MESSAGES/%{name}.mo”]

But it seems that these directories are not searched for rails.mo.  
(Note that it works for eventoj.mo, the mo file for my application.)  
Instead, rails.mo is in (for me)  
/usr/lib/ruby/gems/1.8/gems/gettext-1.8.0/data/locale/\*/LC\_MESSAGES,  
and found therein. My problem is that I do not want to put my custom  
translation there, but do not understand how to tell Gettext that it  
is somewhere else.

Hope we’ll get this done.

Malte

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/4 "2006-12-03T17:44:59Z")

</div>

Hi Malte,

ok, I misunderstood your problem 🙂

I puts rails.mo into:

RAILS\_ROOT/locale/de\_DE/

for example and it’s found.

The following dirs of your apps seems to be searched:

data/locale/de-de/LC\_MESSAGES/rails.mo  
data/locale/de\_DE/LC\_MESSAGES/rails.mo  
data/locale/de/LC\_MESSAGES/rails.mo  
data/locale/de-de/rails.mo  
data/locale/de\_DE/rails.mo  
data/locale/de/rails.mo  
locale/de-de/rails.mo  
locale/de\_DE/rails.mo

Don’t know why

locale//LC\_MESSAGES is not in the path, but data/locale/…  
Maybe Masao can give us a hint 🙂

Does is work for you?

Am 03.12.2006 um 15:15 schrieb Malte M.:

> > add\_default\_local\_path(“…/locale/%{tag}/LC\_MESSAGES/%{name}.mo”)  
> > "/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%  
> > is somewhere else.  
> > [http://rubyforge.org/mailman/listinfo/railsi18n-discussion](http://rubyforge.org/mailman/listinfo/railsi18n-discussion)

* * *

Thomas B.  
[b-simple.de](http://b-simple.de) - Ruby on Rails, Java EE, Entwicklung, Coaching  
fon: +49(40)411 622 35 mobil: +49(173)23 911 43  
fax: +49(40)411 622 36 email: thomas.baustert(at)[b-simple.de](http://b-simple.de)

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/5 "2006-12-03T19:57:40Z")

</div>

Masao M. wrote:

> ## environment.rb:
> 
> require ‘gettext’  
> GetText.add\_default\_locale\_path("/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%{name}.mo")
> 
> ## require ‘gettext/rails’

I changed that to the following:

* * *

## require ‘gettext’ include GetText add\_default\_locale\_path("/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%{name}.mo") require ‘gettext/rails’

and it works. It means to include GetText at the toplevel, because  
ApplicationController does not exist yet when environment.rb is  
executed, but it works. 🙂

@Thomas: You’re right, if I put rails.mo into locale/eo/ instead of  
locale/eo/LC\_MESSAGES/, then it is found. Actually, that is a nice  
solution, too, and I think I will choose this one. Hm, if this is  
a bug, then its source seems to be around line 200 of gettext/rails.rb.  
Maybe the line

locale\_path = File.join(caller[0].split(/app.controllers/)[0] +  
“locale”)

should read

locale\_path = File.join(caller[0].split(/app.controllers/)[0],  
“locale”, “LC\_MESSAGES”)

instead? Anyway, thank you both for solving my problem!

> BTW, I think the best way to support your language is  
> to include your language in Ruby-GetText-Package.  
> If you help me, I can include your language to my official package.  
> #Ask me directly if you are interested in it.

I’ll send you the po file as soon as I consider it finished. I’ll forget  
this, so please remind me eventually 😉 And keep up the great work  
you do on your Ruby libraries.

Malte

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 3, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/6 "2006-12-03T18:19:04Z")

</div>

Hi,

On Sun, 3 Dec 2006 15:15:00 +0100  
“Malte M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > add\_default\_local\_path(“…/locale/%{tag}/LC\_MESSAGES/%{name}.mo”)  
> > “/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%{name}.mo”,
> 
> Hope we’ll get this done.

The GetText.add\_default\_locale\_path methods should be called before  
bindtextomain “rails”.  
It means, you need to call it before requiring ‘gettext/rails’.

How about adding this code to the bottom of environment.rb(though I  
don’t test it) ?:

## environment.rb:

require ‘gettext’  
GetText.add\_default\_locale\_path(“/home/malte/Krakel/eventoj/locale/%{locale}/LC\_MESSAGES/%{name}.mo”)

## require ‘gettext/rails’

BTW, I think the best way to support your language is  
to include your language in Ruby-GetText-Package.  
If you help me, I can include your language to my official package.  
#Ask me directly if you are interested in it.

Regards,  
Masao.

---

<div class="post-metadata">

**Author:** ![Malte\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@Malte\_M](https://www.ruby-forum.com/u/Malte_M)\
**Post date:** [December 4, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/ruby-gettext-rails-mo-issue/78167/7 "2006-12-04T18:39:56Z")

</div>

Hi,

On Sun, 3 Dec 2006 19:57:40 +0100  
“Malte M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> locale\_path = File.join(caller[0].split(/app.controllers/)[0],  
> “locale”, “LC\_MESSAGES”)
> 
> instead? Anyway, thank you both for solving my problem!

No. the locale\_path is the topdir of the locale path.  
So, it becomes both of topdir/#{lang}/locale/foo.mo,  
topdir/#{lang}/locale/LC\_MESSAGES/foo.mo.  
#See gettext/textdomain.rb for more details.

> > BTW, I think the best way to support your language is  
> > to include your language in Ruby-GetText-Package.  
> > If you help me, I can include your language to my official package.  
> > #Ask me directly if you are interested in it.
> 
> I’ll send you the po file as soon as I consider it finished. I’ll forget  
> this, so please remind me eventually 😉 And keep up the great work  
> you do on your Ruby libraries.

I’ll send you the newest version of po files.

Thanks in advance.  
Masao.
