From: Bruno Haible Date: Tue, 1 Oct 2024 19:28:37 +0000 (+0200) Subject: its: During merge, copy also the XML node's attributes. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=3161ab0f74d0d10e21090288f5381de94ead23a1;p=thirdparty%2Fgettext.git its: During merge, copy also the XML node's attributes. Rationale: In XHTML, attributes like 'style' are used for rendering. * gettext-tools/src/its.c (_its_copy_node_with_attributes): New function. (its_merge_context_merge_node): Use it. * gettext-tools/tests/msgfmt-xml-1: Update expected results. * gettext-tools/tests/msgfmt-xml-2: Likewise. --- diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index a00e9ddd7..bb16645d1 100644 --- a/gettext-tools/src/its.c +++ b/gettext-tools/src/its.c @@ -1961,6 +1961,43 @@ struct its_merge_context_ty struct its_node_list_ty nodes; }; +/* Copies an element node and its attributes, but not its children nodes, + for inserting at a sibling position in the document tree. */ +static xmlNode * +_its_copy_node_with_attributes (xmlNode *node) +{ + xmlNode *copy; + +#if 0 + /* Not suitable here, because it adds namespace declaration attributes, + which is overkill here. */ + copy = xmlCopyNode (node, 2); +#elif 0 + /* Not suitable here either, for the same reason. */ + copy = xmlNewNode (node->ns, node->name); + copy->properties = xmlCopyPropList (copy, node->properties); +#else + copy = xmlNewNode (node->ns, node->name); + + xmlAttr *attributes; + for (attributes = node->properties; + attributes != NULL; + attributes = attributes->next) + { + const xmlChar *attr_name = attributes->name; + if (strcmp ((const char *) attr_name, "id") != 0) + { + xmlNs *attr_ns = attributes->ns; + xmlChar *attr_value = xmlGetNsProp (node, attr_name, attr_ns->href); + xmlNewNsProp (copy, attr_ns, attr_name, attr_value); + xmlFree (attr_value); + } + } +#endif + + return copy; +} + /* Returns true if S starts with a character reference. */ static bool starts_with_character_reference (const char *s) @@ -2108,7 +2145,10 @@ its_merge_context_merge_node (struct its_merge_context_ty *context, { xmlNode *translated; - translated = xmlNewNode (node->ns, node->name); + /* Create a new element node, of the same name, with the same + attributes. */ + translated = _its_copy_node_with_attributes (node); + xmlSetProp (translated, BAD_CAST "xml:lang", BAD_CAST language); /* libxml2 offers two functions for setting the content of an diff --git a/gettext-tools/tests/msgfmt-xml-1 b/gettext-tools/tests/msgfmt-xml-1 index 856c030cf..f4911ad0b 100755 --- a/gettext-tools/tests/msgfmt-xml-1 +++ b/gettext-tools/tests/msgfmt-xml-1 @@ -125,13 +125,13 @@ cat <<\EOF > mf.appdata.xml.ok as &#169;, or as &copy;?

-

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

+

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

Written by &author1;, &author2;, and &author3;.

Écrit par &author1;, &author2;, et &author3;.

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

https://wiki.gnome.org/Design/Apps/CharacterMap dueno_at_src.gnome.org diff --git a/gettext-tools/tests/msgfmt-xml-2 b/gettext-tools/tests/msgfmt-xml-2 index 10e136f94..d75b24c02 100755 --- a/gettext-tools/tests/msgfmt-xml-2 +++ b/gettext-tools/tests/msgfmt-xml-2 @@ -185,17 +185,17 @@ cat <<\EOF > mf.appdata.xml.ok as &#169;, or as &copy;?

-

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

-

Wussten Sie, dass das Copyright-Zeichen (©, U+00A9) in HTML als &#xa9;, als &#169;, oder als &copy; geschrieben werden kann?

+

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

+

Wussten Sie, dass das Copyright-Zeichen (©, U+00A9) in HTML als &#xa9;, als &#169;, oder als &copy; geschrieben werden kann?

Written by &author1;, &author2;, and &author3;.

Écrit par &author1;, &author2;, et &author3;.

Geschrieben von &author1;, &author2; und &author3;.

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

-

Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & < >, Zeichen ©, escaptes Zeichen &#xa9;, Entitäten © &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

+

Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & < >, Zeichen ©, escaptes Zeichen &#xa9;, Entitäten © &author1;

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

-

Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & < >, Zeichen ©, escaptes Zeichen &#xa9;, Entitäten &copy; &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

+

Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & < >, Zeichen ©, escaptes Zeichen &#xa9;, Entitäten &copy; &author1;

https://wiki.gnome.org/Design/Apps/CharacterMap dueno_at_src.gnome.org @@ -232,13 +232,13 @@ cat <<\EOF > mf.appdata.xml.desired.ok as &#169;, or as &copy;?

-

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

+

Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &#xa9;, comme &#169; ou comme &copy; ?

Written by &author1;, &author2;, and &author3;.

Écrit par &author1;, &author2;, et &author3;.

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités © &author1;

Escape gallery: operator x&y, standard XML entities & " ' & < >, character reference ©, escaped character reference &#xa9;, entity references © &author1;

-

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

+

Exposition d'échappements: operateur x&y, entités XML standard & " ' & < >, caractère ©, caractère échappé &#xa9;, entités &copy; &author1;

https://wiki.gnome.org/Design/Apps/CharacterMap dueno_at_src.gnome.org