From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 67A8D1F461 for ; Mon, 20 May 2019 00:59:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:55658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSWe7-0000O2-2q for normalperson@yhbt.net; Sun, 19 May 2019 20:59:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSWe2-0000Nv-6v for bug-gnulib@gnu.org; Sun, 19 May 2019 20:59:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSWe0-00056b-Iw for bug-gnulib@gnu.org; Sun, 19 May 2019 20:59:14 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::7]:16429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hSWdz-0004s5-T9 for bug-gnulib@gnu.org; Sun, 19 May 2019 20:59:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1558313948; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=5WsrT6bLlNn/HNWIDPzeUt884l7yFIHJSMSyuHXibVE=; b=FltQmbiAcgvOA4BNqjg8fJg5F4DYNkKDtuBWZuwk3ddXtvc4gMWyWzJODSLEclxPmg fMWYXkHvgqbZ/iZCNkqU/qubLXrNX2DiS0Vo9k7nfNv6IRunFJuteyLyuLnmcpXIISzE PMhgMsadWASl3eY+x3bPVdVpELOKbdfNMkpCLgYaU73Nx0kZKpJm1db8QssmP1moZVn4 5F8fpH25KfOJVf+5neF5zU2dvuLUBbSIIO5TqfIxzPttQplxU2YRAFpR9Y6UnT4zxbtV Fmu4B4Nmh+JP0JWdbLXeLbH1UPJXBsCCOsUgdxkHVAOoHAlv/+GWmG2Ivy3+11yO9X8X rExg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGaf0y5RW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.18 DYNA|AUTH) with ESMTPSA id m03afev4K0x4BPN (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 20 May 2019 02:59:04 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: localename: fix default on macOS Date: Mon, 20 May 2019 02:59:03 +0200 Message-ID: <3458419.gAk2X40PyC@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-145-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::7 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" On macOS 10.13.4, the locale name returned by gl_locale_name_default() is wrong when two or more preferred languages are specified in the system preferences. Namely, it returns, e.g. for me in Germany, "en_DE" instead of the expected "de_DE" (where the language is the first preferred language). This is caused by an unexpected behaviour of CFLocaleCopyCurrent(). It may be the same bug as the one mentioned here: - for macOS: - for iOS: The fix is to use the older API instead, which still returns the expected locale name. 2019-05-19 Bruno Haible localename: Fix default on macOS. * m4/intlmacosx.m4 (gt_INTL_MACOSX): Don't test for CFLocaleCopyCurrent. * lib/localename.c: Remove includes for HAVE_CFLOCALECOPYCURRENT. (gl_locale_name_environ, gl_locale_name_default): Remove code for HAVE_CFLOCALECOPYCURRENT. * lib/localename.h (gl_locale_name_default): Update. diff --git a/m4/intlmacosx.m4 b/m4/intlmacosx.m4 index 30e6f50..3495174 100644 --- a/m4/intlmacosx.m4 +++ b/m4/intlmacosx.m4 @@ -1,4 +1,4 @@ -# intlmacosx.m4 serial 6 (gettext-0.20) +# intlmacosx.m4 serial 7 (gettext-0.20.2) dnl Copyright (C) 2004-2014, 2016, 2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -33,21 +33,15 @@ AC_DEFUN([gt_INTL_MACOSX], AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1], [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) fi - dnl Check for API introduced in Mac OS X 10.5. - AC_CACHE_CHECK([for CFLocaleCopyCurrent], [gt_cv_func_CFLocaleCopyCurrent], - [gt_save_LIBS="$LIBS" - LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include ]], - [[CFLocaleCopyCurrent();]])], - [gt_cv_func_CFLocaleCopyCurrent=yes], - [gt_cv_func_CFLocaleCopyCurrent=no]) - LIBS="$gt_save_LIBS"]) - if test $gt_cv_func_CFLocaleCopyCurrent = yes; then - AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], [1], - [Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) - fi + dnl Don't check for the API introduced in Mac OS X 10.5, CFLocaleCopyCurrent, + dnl because in macOS 10.13.4 it has the following behaviour: + dnl When two or more languages are specified in the + dnl "System Preferences > Language & Region > Preferred Languages" panel, + dnl it returns en_CC where CC is the territory (even when English is not among + dnl the preferred languages!). What we want instead is what + dnl CFLocaleCopyCurrent returned in earlier macOS releases and what + dnl CFPreferencesCopyAppValue still returns, namely ll_CC where ll is the + dnl first among the preferred languages and CC is the territory. AC_CACHE_CHECK([for CFLocaleCopyPreferredLanguages], [gt_cv_func_CFLocaleCopyPreferredLanguages], [gt_save_LIBS="$LIBS" LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" @@ -64,7 +58,6 @@ AC_DEFUN([gt_INTL_MACOSX], fi INTL_MACOSX_LIBS= if test $gt_cv_func_CFPreferencesCopyAppValue = yes \ - || test $gt_cv_func_CFLocaleCopyCurrent = yes \ || test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" fi diff --git a/lib/localename.c b/lib/localename.c index 1b1bb19..b6b94c2 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -66,13 +66,9 @@ extern char * getlocalename_l(int, locale_t); # endif #endif -#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE +#if HAVE_CFPREFERENCESCOPYAPPVALUE # include -# if HAVE_CFLOCALECOPYCURRENT -# include -# elif HAVE_CFPREFERENCESCOPYAPPVALUE -# include -# endif +# include #endif #if defined _WIN32 && !defined __CYGWIN__ @@ -1156,7 +1152,7 @@ extern char * getlocalename_l(int, locale_t); #endif -#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE +#if HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.4 or newer */ /* Canonicalize a Mac OS X locale name to a Unix locale name. @@ -3326,7 +3322,7 @@ gl_locale_name_environ (int category, const char *categoryname) retval = getenv ("LANG"); if (retval != NULL && retval[0] != '\0') { -#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE +#if HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.2 or newer. Ignore invalid LANG value set by the Terminal application. */ if (strcmp (retval, "UTF-8") != 0) @@ -3373,7 +3369,7 @@ gl_locale_name_default (void) "C.UTF-8" locale, which operates in the same way as the "C" locale. */ -#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__) +#if !(HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__) /* The system does not have a way of setting the locale, other than the POSIX specified environment variables. We use C as default locale. */ @@ -3386,8 +3382,17 @@ gl_locale_name_default (void) context, because message catalogs are not specific to a single codeset. */ -# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE +# if HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.4 or newer */ + /* Don't use the API introduced in Mac OS X 10.5, CFLocaleCopyCurrent, + because in macOS 10.13.4 it has the following behaviour: + When two or more languages are specified in the + "System Preferences > Language & Region > Preferred Languages" panel, + it returns en_CC where CC is the territory (even when English is not among + the preferred languages!). What we want instead is what + CFLocaleCopyCurrent returned in earlier macOS releases and what + CFPreferencesCopyAppValue still returns, namely ll_CC where ll is the + first among the preferred languages and CC is the territory. */ { /* Cache the locale name, since CoreFoundation calls are expensive. */ static const char *cached_localename; @@ -3395,17 +3400,12 @@ gl_locale_name_default (void) if (cached_localename == NULL) { char namebuf[256]; -# if HAVE_CFLOCALECOPYCURRENT /* Mac OS X 10.5 or newer */ - CFLocaleRef locale = CFLocaleCopyCurrent (); - CFStringRef name = CFLocaleGetIdentifier (locale); -# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.4 or newer */ CFTypeRef value = CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), kCFPreferencesCurrentApplication); if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID ()) { CFStringRef name = (CFStringRef)value; -# endif if (CFStringGetCString (name, namebuf, sizeof (namebuf), kCFStringEncodingASCII)) @@ -3413,12 +3413,7 @@ gl_locale_name_default (void) gl_locale_name_canonicalize (namebuf); cached_localename = strdup (namebuf); } - -# if HAVE_CFLOCALECOPYCURRENT /* Mac OS X 10.5 or newer */ - CFRelease (locale); -# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.4 or newer */ } -# endif if (cached_localename == NULL) cached_localename = "C"; } diff --git a/lib/localename.h b/lib/localename.h index 071248a..c0839b8 100644 --- a/lib/localename.h +++ b/lib/localename.h @@ -86,8 +86,7 @@ extern const char * gl_locale_name_environ (int category, const char *categoryna The result must not be freed; it is statically allocated. */ extern const char * gl_locale_name_default (void) -#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE \ - || defined _WIN32 || defined __CYGWIN__) +#if !(HAVE_CFPREFERENCESCOPYAPPVALUE || defined _WIN32 || defined __CYGWIN__) _GL_ATTRIBUTE_CONST #endif ;