Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Problems using gettext in perl.

by cowboy (Friar)
on Jul 13, 2006 at 19:01 UTC ( [id://561042]=perlquestion: print w/replies, xml ) Need Help??

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
    Interesting question! The problem may not be with the modules, but with gettext itself. What editor are you using? And, is it setup for .po files? For example, in Emacs, some config changes should be made. I would also check to see that libintl is present and properly linked. There's a multititude of tweaks that can be done to gettext. See:

    http://www.iro.umontreal.ca/translation/HTML/gettext.html#Files

      I used kbabel for the .po file. msgfmt liked the file, msgunfmt gives me what I'd expect back from the .mo file. I've been through the documentation you linked a few times with no luck yet. Thanks for the reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://561042]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-18 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found