]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
intl: Treat C.UTF-8 locale like C locale.
authorBruno Haible <bruno@clisp.org>
Sun, 10 Sep 2023 18:33:09 +0000 (20:33 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 10 Sep 2023 18:49:32 +0000 (20:49 +0200)
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.<encoding> 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.

NEWS
gettext-runtime/NEWS
gettext-runtime/intl/dcigettext.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/intl-0 [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 07aace64f3d378eb64a14647582051c0873243cc..60a1e18733cd48ec4fd159b1f896afa3676831f1 100644 (file)
--- 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.
 
index d4a455f359e7f73ccd4862623a972d714c673748..4bc5290a65712af348768771915fe4fcbf8bc0be 100644 (file)
@@ -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
index 7c122b1e4ff1ecdffc4af07298fde805f12954c2..0be23e194215d19d16a111f5889edee8d87d23a5 100644 (file)
@@ -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.<encoding>" 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.<encoding>", because that's
+     the by-design behaviour for glibc, see
+     <https://sourceware.org/glibc/wiki/Proposals/C.UTF-8>.  */
+  if (locale[0] == 'C' && (locale[1] == '\0' || locale[1] == '.'))
     return locale;
 
   /* The highest priority value is the value of the 'LANGUAGE' environment
index f4e3d227d55c7695857359ec67ea84cadcdd490f..090a8d13a3698775bf19aa2f92ac22aaf54d6757 100644 (file)
@@ -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 (executable)
index 0000000..9977cfe
--- /dev/null
@@ -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 <<EOF > 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