Ruby-gettext rails.mo issue

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?

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
[email protected]
http://rubyforge.org/mailman/listinfo/railsi18n-discussion


Thomas B.
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

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

Hi Malte,

ok, I misunderstood your problem :slight_smile:

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 :slight_smile:

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


Thomas B.
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

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. :slight_smile:

@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 :wink: And keep up the great work
you do on your Ruby libraries.

Malte

Hi,

On Sun, 3 Dec 2006 15:15:00 +0100
“Malte M.” [email protected] 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.

Hi,

On Sun, 3 Dec 2006 19:57:40 +0100
“Malte M.” [email protected] 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 :wink: 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.