From 7b8503c2516f549dd6b4789805acc6d6a596d15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Tue, 3 Jul 2018 23:07:55 +0000 Subject: [PATCH 1/2] Use GetUserDefaultUILanguage instead of GetThreadLocale GetThreadLocale() returns the user-chosen "Format" language, not the UI language of the operating system. Use the GetUserDefaultUILanguage() for that instead, when the category being queried for the default locale name is LC_MESSAGES. --- lib/localename.c | 20 ++++++++++++++++++-- lib/localename.h | 17 +++++++++++++++++ lib/setlocale.c | 6 +++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/localename.c b/lib/localename.c index c9415c9..d6120f4 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -2888,7 +2888,7 @@ gl_locale_name_environ (int category, const char *categoryname) } const char * -gl_locale_name_default (void) +gl_locale_name_default_for_category (int category) { /* POSIX:2001 says: "All implementations shall define a locale as the default locale, to be @@ -2974,6 +2974,16 @@ gl_locale_name_default (void) # endif # if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */ + if (category == LC_MESSAGES) + { + LANGID langid; + + /* Use native Windows API UI language ID. */ + langid = GetUserDefaultUILanguage (); + + return gl_locale_name_from_win32_LANGID (langid); + } + else { LCID lcid; @@ -2986,6 +2996,12 @@ gl_locale_name_default (void) #endif } +const char * +gl_locale_name_default () +{ + return gl_locale_name_default_for_category (LC_CTYPE); +} + /* Determine the current locale's name, and canonicalize it into XPG syntax address@hidden The codeset part in the result is not reliable; the locale_charset() @@ -3005,5 +3021,5 @@ gl_locale_name (int category, const char *categoryname) if (retval != NULL) return retval; - return gl_locale_name_default (); + return gl_locale_name_default_for_category (LC_CTYPE); } diff --git a/lib/localename.h b/lib/localename.h index a7c0369..e68c244 100644 --- a/lib/localename.h +++ b/lib/localename.h @@ -92,6 +92,23 @@ extern const char * gl_locale_name_default (void) #endif ; +/* Determine the default locale's name for a given category. + This is the current locale's name for a given category, + if not specified by uselocale() calls, by setlocale() calls, or by + environment variables. This locale name is usually determined by systems + settings that the user can manipulate through a GUI. + + Unlike gl_locale_name_default(), it returns correct locale for LC_MESSAGES + when running on Windows. + + The result must not be freed; it is statically allocated. */ +extern const char * gl_locale_name_default_for_category (int category) +#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE \ + || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__) + _GL_ATTRIBUTE_CONST +#endif + ; + #ifdef __cplusplus } #endif diff --git a/lib/setlocale.c b/lib/setlocale.c index 1ac3f4d..13fa545 100644 --- a/lib/setlocale.c +++ b/lib/setlocale.c @@ -848,7 +848,7 @@ rpl_setlocale (int category, const char *locale) base_name = gl_locale_name_environ (LC_CTYPE, category_to_name (LC_CTYPE)); if (base_name == NULL) - base_name = gl_locale_name_default (); + base_name = gl_locale_name_default_for_category (LC_CTYPE); if (setlocale_unixlike (LC_ALL, base_name) == NULL) goto fail; @@ -868,7 +868,7 @@ rpl_setlocale (int category, const char *locale) name = gl_locale_name_environ (cat, category_to_name (cat)); if (name == NULL) - name = gl_locale_name_default (); + name = gl_locale_name_default_for_category (cat); /* If name is the same as base_name, it has already been set through the setlocale call before the loop. */ @@ -896,7 +896,7 @@ rpl_setlocale (int category, const char *locale) const char *name = gl_locale_name_environ (category, category_to_name (category)); if (name == NULL) - name = gl_locale_name_default (); + name = gl_locale_name_default_for_category (category); return setlocale_single (category, name); } -- 2.4.0