develooper Front page | perl.i18n | Postings from October 2003

Re: xgettext and parameter reordering

Thread Previous | Thread Next
Christophe Chisogne
October 7, 2003 03:18
Re: xgettext and parameter reordering
Message ID:
Autrijus Tang wrote:
>> gives wrong ..%2\\$d.. with src code like "..%2$d.."
> I think you mean "%2\$d"? If that's the case, it can be fixed.

Yes, I really mean gives wrong ..%2\\$d.. with src code like "..%2\$d.."

But it can't be fixed, now I think better, due to different syntaxes
    --- already does the Right Thing :

1. std xgettext want(ed) translatable strings between dble quotes
    as there is(was) no native Perl support. To use xgettext, src
    code must be like

    src: _("...") or gettext("...") to use std ("old") xgettext

2. gettext catalogs files (.po) always uses "..." to surround strings
    and force escaping \ with \\. With a "..%1\d.." in .po catalog,
    msgfmt refuse to make the .mo file saying
    "file.po:x:y: invalid control sequence". So we end up with
    "..%1\\$d.." in catalog if we want \ in it. But then, no translation
    take place, the correct syntax beeing only "..%1$d.." in .po file:

    .po: "..%1\\$d.." invalid, must use "..%1$d.." to get translations

3. in Perl, a $ inside " must be escaped with \ to avoid substitutions.

     perl: "..%1$d.." invalid, must use "..%1\$d.." or '..%1$d..'

We clearly see incompatibilities here.

To get std gettext translation with param reordering in Perl, we can
NOT use the double quotes (") in Perl src code: in fact
does the right thing by replacing \ with \\ when using " in src code,
as required by the GNU .po catalogs syntax.

In brief, to get translation with param reordering in Perl
using std GNU gettext lib:

1. Mark src code strings with '..%1$d..' syntax (no double quotes)
2. To extract them, use which does the Right Thing (tm)
    xgettext with Perl support (only in CVS for now)

I'm asking myself if all this shouldnt be documented somewhere,
along with different options to do "automatic" i18n in Perl
(std gettext, Maketext, Maketext::Lexicon, libintl-perl, whatever)

Time to add entries for "See Also" in perllocale(1) ?

Locale::TextDomain aka libintl-perl


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About