From: Bruno Haible Date: Thu, 3 Oct 2024 20:34:14 +0000 (+0200) Subject: its: Fix the value of the xml:lang attribute inserted by msgfmt. X-Git-Tag: v0.23~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=446241c7cabb9b5de52c63248aa2574ce1acb388;p=thirdparty%2Fgettext.git its: Fix the value of the xml:lang attribute inserted by msgfmt. Reported by Matthias Klumpp at . * 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. --- diff --git a/NEWS b/NEWS index f423a58e7..4421854b5 100644 --- 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. diff --git a/autogen.sh b/autogen.sh index 984f571c1..0c99bdb21 100755 --- a/autogen.sh +++ b/autogen.sh @@ -168,6 +168,7 @@ if ! $skip_gnulib; then attribute backupfile basename-lgpl + bcp47 binary-io bison bison-i18n diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index bb16645d1..98521c5b2 100644 --- a/gettext-tools/src/its.c +++ b/gettext-tools/src/its.c @@ -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. + + 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 diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 454160141..9c7b3276e 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -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 index 000000000..3a13bda67 --- /dev/null +++ b/gettext-tools/tests/msgfmt-xml-3 @@ -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 + + + org.gnome.Characters.desktop + GNOME Characters + Character map application + CC0 + +

Happy new year!

+
+
+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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 , 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 \n" +"Language-Team: LANGUAGE \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 + + + org.gnome.Characters.desktop + GNOME Characters + Character map application + CC0 + +

Happy new year!

+

新年快樂!

+

Янги йил билан!

+

Yangi yil bilan!

+

Sersala ve mibarek be!

+

שנה טובה!

+

Gutes neues Jahr!

+

Conne année!

+
+
+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