cowboy has asked for the wisdom of the Perl Monks concerning the following question:
I'm having problems getting gettext to work. I've tried both Locale::gettext and Locale::TextDomain. The translation never happens, I always get 'Baz' back. Below is the code for both my attempts.
The locale datafile contains a msgid Baz which translates to 'New Baz'
/home/cowboy/locale/x/LC_MESSAGES/test.mo
Attempt 1 (Locale::gettext)
use strict; use Locale::gettext; use POSIX qw(:locale_h); setlocale( LC_ALL, 'x' ); my $d = Locale::gettext->domain('test'); $d->dir('/home/cowboy/locale'); print $d->get('Baz') . "\n";
Second attempt (Locale::TextDomain)
use strict; use Locale::TextDomain('test','/home/cowboy/locale'); use POSIX qw(:locale_h); setlocale( LC_ALL, 'x' ); print $__{'Baz'} . "\n";
Any help would be greatly appreciated. I'm not tied to these modules, or even gettext if a better alternative is suggested.
Update: using strace on the execution of the programs, the first one does not seem to even attempt to look in the directory I specified, instead, trying /usr/lib/locale. The second does a stat on the file, but doesn't actually attempt to open it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problems using gettext in perl.
by Khen1950fx (Canon) on Jul 13, 2006 at 20:05 UTC | |
by cowboy (Friar) on Jul 13, 2006 at 20:35 UTC |