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

Re: xgettext and parameter reordering

Thread Previous | Thread Next
From:
Christophe Chisogne
Date:
October 7, 2003 03:18
Subject:
Re: xgettext and parameter reordering
Message ID:
3F8292C8.6020302@publicityweb.com
Autrijus Tang wrote:
>>xgettext.pl 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
xgettext.pl gives wrong ..%2\\$d.. with src code like "..%2\$d.."

But it can't be fixed, now I think better, due to different syntaxes
    --- xgettext.pl 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: xgettext.pl 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
    xgettext.pl which does the Right Thing (tm)
      or
    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::gettext, http://www.gnu.org/manual/gettext/
Locale::Maketext
Locale::Maketext::Lexicon, http://www.autrijus.org/webl10n/webl10n.html
Locale::TextDomain aka libintl-perl
...

Christophe


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About