]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
its: Fix the value of the xml:lang attribute inserted by msgfmt.
authorBruno Haible <bruno@clisp.org>
Thu, 3 Oct 2024 20:34:14 +0000 (22:34 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 3 Oct 2024 20:34:14 +0000 (22:34 +0200)
Reported by Matthias Klumpp <matthias@tenstral.net>
at <https://savannah.gnu.org/bugs/?64025>.

* autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add bcp47.
* gettext-tools/src/its.c: Include "bcp47.h".
(its_merge_context_merge_node): Convert the language / locale name to BCP 47
syntax before storing it in the xml:lang attribute.
* gettext-tools/tests/msgfmt-xml-3: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
* NEWS: Mention the change.

NEWS
autogen.sh
gettext-tools/src/its.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgfmt-xml-3 [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index f423a58e796aaf97905e9ba37570fcaf50e293e8..4421854b5cba61a154e2dadb50558f04167e656b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Version 0.23 - September 2024
       fully apply. As a maintainer of a package that has translatable XML files,
       you need to regenerate the POT file and pass it on to your translators.
     o XML schemas for .its and .loc files are now provided.
+    o The value of the xml:lang attribute, inserted by msgfmt, now conforms
+      to W3C standards.
   - Python:
     o xgettext now assumes source code for Python 3 rather than Python 2.
       This affects the interpretation of escape sequences in string literals.
index 984f571c19820cbbb12813130496ef56f8ddf4b0..0c99bdb215c82a4edaa62bf9454243626272265c 100755 (executable)
@@ -168,6 +168,7 @@ if ! $skip_gnulib; then
     attribute
     backupfile
     basename-lgpl
+    bcp47
     binary-io
     bison
     bison-i18n
index bb16645d141c1cc01cf62ce614684ee2685e874d..98521c5b2fb5c8288520584e042559c20ece57ff 100644 (file)
@@ -40,6 +40,7 @@
 #include "xalloc.h"
 #include "xvasprintf.h"
 #include "string-buffer.h"
+#include "bcp47.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
@@ -2144,12 +2145,18 @@ its_merge_context_merge_node (struct its_merge_context_ty *context,
           if (mp && *mp->msgstr != '\0')
             {
               xmlNode *translated;
+              char language_bcp47[BCP47_MAX];
 
               /* 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);
+              /* Set the xml:lang attribute.
+                 <https://www.w3.org/International/questions/qa-when-xmllang.en.html>
+                 says: "The value of the xml:lang attribute is a language tag
+                 defined by BCP 47."  */
+              xpg_to_bcp47 (language_bcp47, language);
+              xmlSetProp (translated, BAD_CAST "xml:lang", BAD_CAST language_bcp47);
 
               /* libxml2 offers two functions for setting the content of an
                  element: xmlNodeSetContent and xmlNodeAddContent.  They differ
index 45416014148d4b4217ba9ee97533a0ad175f86ef..9c7b3276e4d8c5b0f9233209e6110e3e98fcfe8e 100644 (file)
@@ -57,7 +57,7 @@ TESTS = gettext-1 gettext-2 \
        msgfmt-tcl-1 msgfmt-tcl-2 \
        msgfmt-qt-1 msgfmt-qt-2 \
        msgfmt-desktop-1 msgfmt-desktop-2 msgfmt-desktop-3 \
-       msgfmt-xml-1 msgfmt-xml-2 \
+       msgfmt-xml-1 msgfmt-xml-2 msgfmt-xml-3 \
        msggrep-1 msggrep-2 msggrep-3 msggrep-4 msggrep-5 msggrep-6 msggrep-7 \
        msggrep-8 msggrep-9 msggrep-10 msggrep-11 \
        msginit-1 msginit-2 msginit-3 msginit-4 \
diff --git a/gettext-tools/tests/msgfmt-xml-3 b/gettext-tools/tests/msgfmt-xml-3
new file mode 100755 (executable)
index 0000000..3a13bda
--- /dev/null
@@ -0,0 +1,221 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test msgfmt --xml: the value of the xml:lang attribute.
+
+cat <<\EOF > mf.appdata.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<component type="desktop" xmlns:gt="https://www.gnu.org/s/gettext/ns/its/extensions/1.0">
+  <id>org.gnome.Characters.desktop</id>
+  <name>GNOME Characters</name>
+  <summary>Character map application</summary>
+  <licence>CC0</licence>
+  <description>
+    <p>Happy new year!</p>
+  </description>
+</component>
+EOF
+
+test -d po || mkdir po
+
+cat <<\EOF > po/fr.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+# ouais, je sais
+msgid "Happy new year!"
+msgstr "Conne année!"
+EOF
+
+cat <<\EOF > po/de.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Happy new year!"
+msgstr "Gutes neues Jahr!"
+EOF
+
+cat <<\EOF > po/he.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+# Pronounced as: shana tova!
+msgid "Happy new year!"
+msgstr "שנה טובה!"
+EOF
+
+cat <<\EOF > po/ku_TR.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Happy new year!"
+msgstr "Sersala ve mibarek be!"
+EOF
+
+cat <<\EOF > po/uz_UZ.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Happy new year!"
+msgstr "Yangi yil bilan!"
+EOF
+
+cat <<\EOF > po/uz_UZ@cyrillic.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Happy new year!"
+msgstr "Янги йил билан!"
+EOF
+
+cat <<\EOF > po/zh_HK.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-03-17 07:36+0900\n"
+"PO-Revision-Date: 2014-03-17 08:40+0900\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Happy new year!"
+msgstr "新年快樂!"
+EOF
+
+cat <<\EOF > po/LINGUAS
+fr de he ku_TR uz_UZ uz_UZ@cyrillic zh_HK
+EOF
+
+cat <<\EOF > mf.appdata.xml.ok
+<?xml version="1.0" encoding="UTF-8"?>
+<component xmlns:gt="https://www.gnu.org/s/gettext/ns/its/extensions/1.0" type="desktop">
+  <id>org.gnome.Characters.desktop</id>
+  <name>GNOME Characters</name>
+  <summary>Character map application</summary>
+  <licence>CC0</licence>
+  <description>
+    <p>Happy new year!</p>
+    <p xml:lang="zh-Hant-HK">新年快樂!</p>
+    <p xml:lang="uz-Cyrl-UZ">Янги йил билан!</p>
+    <p xml:lang="uz-Latn-UZ">Yangi yil bilan!</p>
+    <p xml:lang="ku-Latn-TR">Sersala ve mibarek be!</p>
+    <p xml:lang="he">שנה טובה!</p>
+    <p xml:lang="de">Gutes neues Jahr!</p>
+    <p xml:lang="fr">Conne année!</p>
+  </description>
+</component>
+EOF
+
+unset LINGUAS
+
+${MSGFMT} --xml --template=mf.appdata.xml -d po -o mf.appdata.xml.out || Exit 1
+
+: ${DIFF=diff}
+${DIFF} mf.appdata.xml.ok mf.appdata.xml.out
+test $? = 0 || Exit 1