From: Bruno Haible Date: Sun, 10 Sep 2023 18:33:09 +0000 (+0200) Subject: intl: Treat C.UTF-8 locale like C locale. X-Git-Tag: v0.23~408 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3873b7f1c777e6b2c874ef7c8da3f66f3b02e3fc;p=thirdparty%2Fgettext.git intl: Treat C.UTF-8 locale like C locale. The wiki page https://sourceware.org/glibc/wiki/Proposals/C.UTF-8 says that "Setting LC_ALL=C.UTF-8 will ignore LANGUAGE just like it does with LC_ALL=C." This is now implemented in glibc. Implement it for other platforms as well. * gettext-runtime/intl/dcigettext.c (DCIGETTEXT, guess_category_value): Treat C. locale like the C locale. * gettext-runtime/NEWS: Mention it. * NEWS: Likewise. * gettext-tools/tests/intl-0: New file, based on gettext-tools/tests/intl-1. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/NEWS b/NEWS index 07aace64f..60a1e1873 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,13 @@ -Version 0.23 - July 2023 +Version 0.23 - October 2023 * Programming languages support: - Glade: xgettext has improved support for GtkBuilder 4. +* Runtime behaviour: + - In the C.UTF-8 locale, like in the C locale, the *gettext() functions + now return the msgid untranslated. This is relevant for GNU systems, + Linux with musl libc, FreeBSD, NetBSD, OpenBSD, Cygwin, and Android. + * msgmerge: - The msgmerge option '--sorted-output' is now deprecated. diff --git a/gettext-runtime/NEWS b/gettext-runtime/NEWS index d4a455f35..4bc5290a6 100644 --- a/gettext-runtime/NEWS +++ b/gettext-runtime/NEWS @@ -1,3 +1,9 @@ +Version 0.23 - October 2023 + +* In the C.UTF-8 locale, like in the C locale, the *gettext() functions + now return the msgid untranslated. This is relevant for GNU systems, + Linux with musl libc, FreeBSD, NetBSD, OpenBSD, Cygwin, and Android. + Version 0.21.1 - October 2022 * On AIX, locale names with a script or with an uppercase language are now diff --git a/gettext-runtime/intl/dcigettext.c b/gettext-runtime/intl/dcigettext.c index 7c122b1e4..0be23e194 100644 --- a/gettext-runtime/intl/dcigettext.c +++ b/gettext-runtime/intl/dcigettext.c @@ -754,9 +754,10 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, continue; } - /* If the current locale value is C (or POSIX) we don't load a - domain. Return the MSGID. */ - if (strcmp (single_locale, "C") == 0 + /* If the current locale value is "C" or "C." or "POSIX", + we don't load a domain. Return the MSGID. */ + if ((single_locale[0] == 'C' + && (single_locale[1] == '\0' || single_locale[1] == '.')) || strcmp (single_locale, "POSIX") == 0) break; @@ -1626,8 +1627,12 @@ guess_category_value (int category, const char *categoryname) 2. The precise output of some programs in the "C" locale is specified by POSIX and should not depend on environment variables like "LANGUAGE" or system-dependent information. We allow such programs - to use gettext(). */ - if (strcmp (locale, "C") == 0) + to use gettext(). + Ignore LANGUAGE and its system-dependent analogon also if the locale is + set to "C.UTF-8" or, more generally, to "C.", because that's + the by-design behaviour for glibc, see + . */ + if (locale[0] == 'C' && (locale[1] == '\0' || locale[1] == '.')) return locale; /* The highest priority value is the value of the 'LANGUAGE' environment diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index f4e3d227d..090a8d13a 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -21,7 +21,7 @@ EXTRA_DIST = MOSTLYCLEANFILES = core *.stackdump TESTS = gettext-1 gettext-2 \ - intl-1 intl-2 intl-3 intl-4 intl-5 intl-6 intl-7 \ + intl-0 intl-1 intl-2 intl-3 intl-4 intl-5 intl-6 intl-7 \ intl-setlocale-1 intl-setlocale-2 \ intl-thread-1 intl-thread-2 intl-thread-3 \ intl-version \ diff --git a/gettext-tools/tests/intl-0 b/gettext-tools/tests/intl-0 new file mode 100755 index 000000000..9977cfe2e --- /dev/null +++ b/gettext-tools/tests/intl-0 @@ -0,0 +1,27 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test that gettext(), in the C and C.UTF-8 locales, does no translation. + +test -d in-0 || mkdir in-0 +test -d in-0/C || mkdir in-0/C +test -d in-0/C/LC_MESSAGES || mkdir in-0/C/LC_MESSAGES + +: ${MSGFMT=msgfmt} +${MSGFMT} -o in-0/C/LC_MESSAGES/tstprog.mo "$wabs_srcdir"/intl-1.po + +: ${DIFF=diff} +cat < in-0.ok +cheese +EOF + +../intl-1-prg in-0 C > in-0.tmp || Exit 1 +LC_ALL=C tr -d '\r' < in-0.tmp > in-0-1.out || Exit 1 +${DIFF} in-0.ok in-0-1.out || Exit 1 + +prepare_locale_ in-0/C in-0/C.UTF-8 +../intl-1-prg in-0 C.UTF-8 > in-0.tmp || Exit 1 +LC_ALL=C tr -d '\r' < in-0.tmp > in-0-2.out || Exit 1 +${DIFF} in-0.ok in-0-2.out || Exit 1 + +Exit 0