libintl: Fix language preferences on macOS 10.12 or newer.

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.
This commit is contained in:
Bruno Haible 2018-09-16 04:50:22 +02:00
parent b0fb6a58fa
commit aeab87f30d
2 changed files with 33 additions and 9 deletions

9
NEWS
View File

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

View 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