views:

85

answers:

1

Using --extract-all with xgettext does not work with plurals. Using the answer to I18n C++ hello world with plurals as the C++ code here are two tests using xgettext.

cat >helloplurals.cxx <<EOF
// hellopurals.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main (){
    setlocale(LC_ALL, "");
    bindtextdomain("helloplurals", ".");
    textdomain( "helloplurals");
    for (int ii=0; ii<5; ii++)
        printf(ngettext("Hello world with %d moon.\n", "Hello world with %d moons.\n", ii), ii);
EOF
xgettext --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals.pot helloplurals.cxx
xgettext --extract-all --package-name helloplurals --package-version 1.1 --default-domain helloplurals --output helloplurals-ea.pot helloplurals.cxx

The one without --extract-all works as expected including the handling of plurals:

#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgid_plural "Hello world with %d moons.\n"
msgstr[0] ""
msgstr[1] ""

When --extract-all is added to the command line the resulting POT file does not. Instead there are separate entries:

#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moon.\n"
msgstr ""

#: helloplurals.cxx:10
#, c-format
msgid "Hello world with %d moons.\n"
msgstr ""

String literals that are passed directly to the gettext() like functions properly handle plural messages as shown in the first example use of xgettext.

For string literals that are not passed directly to one of the gettext() like functions the use of the option --extract-all with xgettext can be used to produce the entries in a POT file.

How does one get the handling of string literals that are not passed directly to the gettext() like functions in source that also contains plural string literals that are passed directly to gettext() like function to produce the plural entries: msgid_plural and msgstr[]?

+1  A: 

I don't think xgettext supports that. If you pass --extract-all, it will ignore any context where a string occurs. You may consider reporting this as bug.

I would recommend to mark up all strings explicitly, anyway. There is good tool support to do that fairly quickly.

Martin v. Löwis