]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libintl: Fix language preferences on macOS 10.12 or newer.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Sep 2018 02:50:22 +0000 (04:50 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 16 Sep 2018 02:52:18 +0000 (04:52 +0200)
Reported by Kristian Rietveld <kris@loopnest.org> at
<https://savannah.gnu.org/bugs/?49560>.

* gettext-runtime/intl/langprefs.c (_nl_language_preferences_default): Handle
preferences elements of the form "ll-CC" in a reasonable way.
* NEWS: Mention the change.

NEWS
gettext-runtime/intl/langprefs.c

diff --git a/NEWS b/NEWS
index a6d7771406819d220a2ab9e9f2515c9bc31b6656..c4a8cbfe58f58fd3877db5db1fd750693baa4a9b 100644 (file)
--- a/NEWS
+++ b/NEWS
     Free Pascal compiler version 3.0.0 or newer.
 
 * Runtime behaviour:
-  The replacements for the printf()/fprintf()/... functions that are
-  provided through <libintl.h> on native Windows and NetBSD are now POSIX
-  compliant.  There is no conflict any more between these replacements
-  and other possible replacements provided by gnulib or mingw.
+  - The interpretation of the language preferences on macOS has been fixed.
+  - The replacements for the printf()/fprintf()/... functions that are
+    provided through <libintl.h> on native Windows and NetBSD are now POSIX
+    compliant.  There is no conflict any more between these replacements
+    and other possible replacements provided by gnulib or mingw.
 
 Version 0.19.8 - June 2016
 
index 6dfbd1a66bd22fe615478f387d34800926718155..98232745b74a3cf765b0ed689b1b6db62ada62f4 100644 (file)
@@ -264,12 +264,25 @@ _nl_language_preferences_default (void)
                   {
                     _nl_locale_name_canonicalize (buf);
                     size += strlen (buf) + 1;
+                    /* Mac OS X 10.12 or newer returns an array of elements of
+                       the form "ll-CC" where ll is a language code and CC is a
+                       country code.  _nl_locale_name_canonicalize converts this
+                       to "ll_CC".  Sometimes ll and CC are unrelated, i.e.
+                       there is no translation for "ll_CC" but one for "ll".
+                       Therefore, in the result, we return "ll_CC" followed
+                       by "ll".  */
+                    {
+                      char *underscore = strchr (buf, '_');
+                      if (underscore != NULL)
+                        size += (underscore - buf) + 1;
+                    }
                     /* Most GNU programs use msgids in English and don't ship
-                       an en.mo message catalog.  Therefore when we see "en"
-                       in the preferences list, arrange for gettext() to
-                       return the msgid, and ignore all further elements of
+                       an en.mo message catalog.  Therefore when we see "en" or
+                       "en-CC" in the preferences list, arrange for gettext()
+                       to return the msgid, and ignore all further elements of
                        the preferences list.  */
-                    if (strcmp (buf, "en") == 0)
+                    if (buf[0] == 'e' && buf[1] == 'n'
+                        && (buf[2] == '\0' || buf[2] == '_'))
                       break;
                   }
                 else
@@ -297,7 +310,17 @@ _nl_language_preferences_default (void)
                             strcpy (p, buf);
                             p += strlen (buf);
                             *p++ = ':';
-                            if (strcmp (buf, "en") == 0)
+                            {
+                              char *underscore = strchr (buf, '_');
+                              if (underscore != NULL)
+                                {
+                                  memcpy (p, buf, underscore - buf);
+                                  p += underscore - buf;
+                                  *p++ = ':';
+                                }
+                            }
+                            if (buf[0] == 'e' && buf[1] == 'n'
+                                 && (buf[2] == '\0' || buf[2] == '_'))
                               break;
                           }
                         else