mquinson / po4a

Maintain the translations of your documentation with ease (PO for anything)
http://po4a.org/
GNU General Public License v2.0
121 stars 58 forks source link

XML: Placeholder for empty element #389

Closed k-yaegashi closed 1 year ago

k-yaegashi commented 1 year ago

Given the following XML source

<?xml version="1.0" encoding="utf-8"?>
<doc>
  <p>
    A <place attr="value1"/> B <place attr="value2"/> C <place attr="value3">and</place> D.
  </p>
</doc>

and this configuration,

[po4a_langs] ja
[po4a_paths] test.pot ja:ja.po

[po4a_alias:spec] xml opt:"-o \"placeholder=<place>\""

[type: spec] test.xml ja:output.xml

I expected something like the following message catalogs:

#. type: Content of: <doc><p><place>
#: test.xml:4
#, no-wrap
msgid "and"
msgstr ""

#. type: Content of: <doc><p>
#: test.xml:4
#, no-wrap
msgid ""
"    A <placeholder type=\"place\" id=\"0\"/> B <placeholder type=\"place\" id=\"1\"/> C <placeholder type=\"place\" id=\"2\"/> D.\n"
"  "
msgstr ""

However, the actual result with the latest po4a 0.68 is:

#. type: Content of: <doc><p>
#: test.xml:4
#, no-wrap
msgid "    A "
msgstr ""

#. type: Content of: <doc><p>
#: test.xml:4
#, no-wrap
msgid " B "
msgstr ""

#. type: Content of: <doc><p><place>
#: test.xml:4
#, no-wrap
msgid "and"
msgstr ""

#. type: Content of: <doc><p>
#: test.xml:4
#, no-wrap
msgid ""
" C <placeholder type=\"place\" id=\"0\"/> D.\n"
"  "
msgstr ""

It means placeholder doesn't work for empty element, that is not convenient when empty and non-empty elements are mixed.

In order to get the desirable result, the source XML must be

<?xml version="1.0" encoding="utf-8"?>
<doc>
  <p>
    A <place attr="value1"></place> B <place attr="value2"></place> C <place attr="value3">and</place> D.
  </p>
</doc>

But in many cases, it is nonsense to change source code only for translation.

mquinson commented 1 year ago

Fixed by PR #390.