]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
its: During merge, copy also the XML node's attributes.
authorBruno Haible <bruno@clisp.org>
Tue, 1 Oct 2024 19:28:37 +0000 (21:28 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Oct 2024 19:28:37 +0000 (21:28 +0200)
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.

gettext-tools/src/its.c
gettext-tools/tests/msgfmt-xml-1
gettext-tools/tests/msgfmt-xml-2

index a00e9ddd769b8d86a2b0a4d8f5a7b51291b1a810..bb16645d141c1cc01cf62ce614684ee2685e874d 100644 (file)
@@ -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
index 856c030cf2a5adffb7bd213e04c448f00443e96e..f4911ad0ba9f3cc8b00039afd8952cc8a0f59bb9 100755 (executable)
@@ -125,13 +125,13 @@ cat <<\EOF > mf.appdata.xml.ok
       as &amp;#169;,
       or as &amp;copy;?
     </p>
-    <p xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
+    <p gt:escape="yes" xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
     <p>Written by &author1;, &author2;, and &author3;.</p>
     <p xml:lang="fr">Écrit par &author1;, &author2;, et &author3;.</p>
     <p gt:escape="no">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
+    <p gt:escape="no" xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
     <p gt:escape="yes">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
+    <p gt:escape="yes" xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
   </description>
   <url type="homepage">https://wiki.gnome.org/Design/Apps/CharacterMap</url>
   <updatecontact>dueno_at_src.gnome.org</updatecontact>
index 10e136f94ba3116b9a5bf43fe3c2fc74966095df..d75b24c02bfc32fb68ff86811939f4cc5cd372ae 100755 (executable)
@@ -185,17 +185,17 @@ cat <<\EOF > mf.appdata.xml.ok
       as &amp;#169;,
       or as &amp;copy;?
     </p>
-    <p xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
-    <p xml:lang="de">Wussten Sie, dass das Copyright-Zeichen (©, U+00A9) in HTML als &amp;#xa9;, als &amp;#169;, oder als &amp;copy; geschrieben werden kann?</p>
+    <p gt:escape="yes" xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
+    <p gt:escape="yes" xml:lang="de">Wussten Sie, dass das Copyright-Zeichen (©, U+00A9) in HTML als &amp;#xa9;, als &amp;#169;, oder als &amp;copy; geschrieben werden kann?</p>
     <p>Written by &author1;, &author2;, and &author3;.</p>
     <p xml:lang="fr">Écrit par &author1;, &author2;, et &author3;.</p>
     <p xml:lang="de">Geschrieben von &author1;, &author2; und &author3;.</p>
     <p gt:escape="no">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
-    <p xml:lang="de">Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & &lt; &gt;, Zeichen ©, escaptes Zeichen &amp;#xa9;, Entitäten &copy; &author1;</p>
+    <p gt:escape="no" xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
+    <p gt:escape="no" xml:lang="de">Escape-Beispiele: Operator x&y, Standard-XML Entitäten & " ' & &lt; &gt;, Zeichen ©, escaptes Zeichen &amp;#xa9;, Entitäten &copy; &author1;</p>
     <p gt:escape="yes">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
-    <p xml:lang="de">Escape-Beispiele: Operator x&amp;y, Standard-XML Entitäten &amp; " ' &amp; &lt; &gt;, Zeichen ©, escaptes Zeichen &amp;#xa9;, Entitäten &amp;copy; &amp;author1;</p>
+    <p gt:escape="yes" xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
+    <p gt:escape="yes" xml:lang="de">Escape-Beispiele: Operator x&amp;y, Standard-XML Entitäten &amp; " ' &amp; &lt; &gt;, Zeichen ©, escaptes Zeichen &amp;#xa9;, Entitäten &amp;copy; &amp;author1;</p>
   </description>
   <url type="homepage">https://wiki.gnome.org/Design/Apps/CharacterMap</url>
   <updatecontact>dueno_at_src.gnome.org</updatecontact>
@@ -232,13 +232,13 @@ cat <<\EOF > mf.appdata.xml.desired.ok
       as &amp;#169;,
       or as &amp;copy;?
     </p>
-    <p xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
+    <p gt:escape="yes" xml:lang="fr">Saviez-vous que le signe de copyright (©, U+00A9) peut être écrit en HTML comme &amp;#xa9;, comme &amp;#169; ou comme &amp;copy; ?</p>
     <p>Written by &author1;, &author2;, and &author3;.</p>
     <p xml:lang="fr">Écrit par &author1;, &author2;, et &author3;.</p>
     <p gt:escape="no">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
+    <p gt:escape="no" xml:lang="fr">Exposition d'échappements: operateur x&y, entités XML standard & " ' & &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &copy; &author1;</p>
     <p gt:escape="yes">Escape gallery: operator x&amp;y, standard XML entities &amp; " ' &amp; &lt; &gt;, character reference ©, escaped character reference &amp;#xa9;, entity references &copy; &author1;</p>
-    <p xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
+    <p gt:escape="yes" xml:lang="fr">Exposition d'échappements: operateur x&amp;y, entités XML standard &amp; " ' &amp; &lt; &gt;, caractère ©, caractère échappé &amp;#xa9;, entités &amp;copy; &amp;author1;</p>
   </description>
   <url type="homepage">https://wiki.gnome.org/Design/Apps/CharacterMap</url>
   <updatecontact>dueno_at_src.gnome.org</updatecontact>