From: Bruno Haible Date: Sun, 16 Sep 2018 02:50:22 +0000 (+0200) Subject: libintl: Fix language preferences on macOS 10.12 or newer. X-Git-Tag: v0.20~394 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeab87f30d60f17817477901672bcd20083ea2a3;p=thirdparty%2Fgettext.git libintl: Fix language preferences on macOS 10.12 or newer. Reported by Kristian Rietveld at . * 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. --- diff --git a/NEWS b/NEWS index a6d777140..c4a8cbfe5 100644 --- a/NEWS +++ b/NEWS @@ -36,10 +36,11 @@ Free Pascal compiler version 3.0.0 or newer. * Runtime behaviour: - The replacements for the printf()/fprintf()/... functions that are - provided through 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 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 diff --git a/gettext-runtime/intl/langprefs.c b/gettext-runtime/intl/langprefs.c index 6dfbd1a66..98232745b 100644 --- a/gettext-runtime/intl/langprefs.c +++ b/gettext-runtime/intl/langprefs.c @@ -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