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.


In reply to Problems using gettext in perl. by cowboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.