bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] Peculiar behaviour with msgfmt xml single file mode


From: Indiana
Subject: [bug-gettext] Peculiar behaviour with msgfmt xml single file mode
Date: Mon, 29 May 2017 13:02:43 -0400

I am not sure whether this is a bug, an error in my use of the tool, or me
misunderstanding what this functionality is supposed to be, but the behaviour
I observe using the gettext tools to translate XML files is very peculiar.

When I merge a catalogue of translations with the untranslated source XML, I
expect to get an XML file identical to the source except with all the English
messages replaced with the translated messages. Instead, what I get is an XML
file with the translated messages *added* to the source English messages.

Here's how I produce the behaviour:

1)  Create `messages.xml` using the example in the documentation
    
(https://www.gnu.org/software/gettext/manual/html_node/Preparing-ITS-Rules.html)
2)  Create `messages.its` and `messages.loc` from the same documentation, and
    put them both in directory `its`.
3)  Generate the PO template:
        xgettext --output messages.pot --its its/messages.its messages.xml
4)  Create a translation in directory `translations`. For the example here,
    `fr.po`, where the one string "A translatable string" is translated as
    "Une chaîne traduisible".
5)  Merge the translations:
        GETTEXTDATADIRS=. msgfmt --xml --template messages.xml --locale fr \
            --output-file translations/fr.xml translations/fr.po
    (The first bit is necessary because msgfmt doesn't have an `--its` option,
    so to work around it, you need an `its` directory with a locating rule,
    and an environment variable to point to it.)

I *expect* to get as output the original XML file (the template) with the one
string translated. Instead I get this:

````
<?xml version="1.0"?>
<messages>
  <message>
    <p>A translatable string</p>
    <p xml:lang="fr">Une cha&#xEE;ne traduisible</p>
  </message>
  <message>
    <p translatable="no">A non-translatable string</p>
  </message>
</messages>
````

Note that the original, untranslated element is still there, and the
translated string is in a *new* element, with an "xml:lang" attribute. (That
attribute seems to be determined by the `--locale` option, which serves no
other identifiable purpose, but is not optional.)

If I do the first 4 steps, but in step 5, rather than msgfmt I use ITSTool
like so:
    itstool --merge translations/fr.po --its its/messages.its \
        --out translations/fr.xml messages.xml
then I get the expected output:

````
<?xml version="1.0" encoding="utf-8"?>
<messages>
  <message>
    <p>Une chaîne traduisible</p>
  </message>
  <message>
    <p translatable="no">A non-translatable string</p>
  </message>
</messages>
````

(Note that this is a bit of a cheat, because ITSTool's documentation insists
that the `--out` option must be a *directory*, not a file name. But you get
the same effect if you create a temporary directory, use that as the `--out`
argument, then move the XML file created there to where you want it.)

I have a hard time believing that this is the intended behaviour of msgfmt,
not least because for the vast majority of cases, the XML it produces will
be invalid, either because duplicating an element is wrong (for example, an
XHTML file can't have two <title> elements) or because the xml:lang attribute
isn't allowed on a particular element.

But if this *is* the intended behaviour, then how does one create a translated
XML file? The documentation merely says "use msgfmt; see msgfmt invocation"...
which describes two operation modes. The multilingual "bulk" operation seems
to be about producing stuff like AppStream AppData files, which are of the
form:

````
<component type="desktop-application">
  <id>...</id>
  <name>Name</name>
  <name xml:lang="fr">Nom</name>
  <name xml:lang="ja">名前</name>
  ...
````

That's fine, but is that behaviour really what you want in *single*
translation XML operation? If you want the bulk operation behaviour with just
a single translation language, surely you can achieve it with by just using a
single language code in the LINGUAS file or environment variable.

So what I'd like to know is:

1)  Is this the intended behaviour for msgfmt when using single PO file mode?
2)  If so, how would I obtain the behaviour I desire (to *replace* the
    English message stings with translated strings)?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]