This allows initializing locale from Mac locale identifiers like 'zh-Hans-US'. The current implementation recognizes it as 'zh-US' which isn't a valid locale identifier for Windows. This patch will try again with the 'lang-script' identifier after get_win_locale() fails with the 'lang-region' identifier.
-- v5: ntdll: Try harder to fallback to neutral locales. ntdll: Initialize locale from Mac language identifiers with script name. ntdll: Use different variable names for Mac locales.
From: Jactry Zeng jzeng@codeweavers.com
--- dlls/ntdll/unix/env.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 5a58911c759..6b249917cfe 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -807,9 +807,9 @@ static void init_locale(void) #ifdef __APPLE__ if (!system_locale[0]) { - CFLocaleRef locale = CFLocaleCopyCurrent(); - CFStringRef lang = CFLocaleGetValue( locale, kCFLocaleLanguageCode ); - CFStringRef country = CFLocaleGetValue( locale, kCFLocaleCountryCode ); + CFLocaleRef mac_sys_locale = CFLocaleCopyCurrent(); + CFStringRef lang = CFLocaleGetValue( mac_sys_locale, kCFLocaleLanguageCode ); + CFStringRef country = CFLocaleGetValue( mac_sys_locale, kCFLocaleCountryCode ); CFStringRef locale_string;
if (country) @@ -818,7 +818,7 @@ static void init_locale(void) locale_string = CFStringCreateCopy(NULL, lang);
CFStringGetCString(locale_string, system_locale, sizeof(system_locale), kCFStringEncodingUTF8); - CFRelease(locale); + CFRelease(mac_sys_locale); CFRelease(locale_string); } if (!user_locale[0]) @@ -833,13 +833,13 @@ static void init_locale(void) { CFStringRef lang = CFDictionaryGetValue( components, kCFLocaleLanguageCode ); CFStringRef country = CFDictionaryGetValue( components, kCFLocaleCountryCode ); - CFLocaleRef locale = NULL; + CFLocaleRef mac_user_locale = NULL; CFStringRef locale_string;
if (!country) { - locale = CFLocaleCopyCurrent(); - country = CFLocaleGetValue( locale, kCFLocaleCountryCode ); + mac_user_locale = CFLocaleCopyCurrent(); + country = CFLocaleGetValue( mac_user_locale, kCFLocaleCountryCode ); } if (country) locale_string = CFStringCreateWithFormat( NULL, NULL, CFSTR("%@-%@"), lang, country ); @@ -847,7 +847,7 @@ static void init_locale(void) locale_string = CFStringCreateCopy( NULL, lang ); CFStringGetCString( locale_string, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 ); CFRelease( locale_string ); - if (locale) CFRelease( locale ); + if (mac_user_locale) CFRelease( mac_user_locale ); CFRelease( components ); } }
This merge request was approved by Alexandre Julliard.
From: Jactry Zeng jzeng@codeweavers.com
--- dlls/ntdll/unix/env.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 6b249917cfe..1110acfd0fd 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -833,6 +833,7 @@ static void init_locale(void) { CFStringRef lang = CFDictionaryGetValue( components, kCFLocaleLanguageCode ); CFStringRef country = CFDictionaryGetValue( components, kCFLocaleCountryCode ); + CFStringRef script = CFDictionaryGetValue( components, kCFLocaleScriptCode ); CFLocaleRef mac_user_locale = NULL; CFStringRef locale_string;
@@ -841,7 +842,11 @@ static void init_locale(void) mac_user_locale = CFLocaleCopyCurrent(); country = CFLocaleGetValue( mac_user_locale, kCFLocaleCountryCode ); } - if (country) + if (country && script) + locale_string = CFStringCreateWithFormat( NULL, NULL, CFSTR("%@-%@-%@"), lang, script, country ); + else if (script) + locale_string = CFStringCreateWithFormat( NULL, NULL, CFSTR("%@-%@"), lang, script ); + else if (country) locale_string = CFStringCreateWithFormat( NULL, NULL, CFSTR("%@-%@"), lang, country ); else locale_string = CFStringCreateCopy( NULL, lang );
From: Jactry Zeng jzeng@codeweavers.com
--- dlls/ntdll/unix/env.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/unix/env.c b/dlls/ntdll/unix/env.c index 1110acfd0fd..4fd3254b2d2 100644 --- a/dlls/ntdll/unix/env.c +++ b/dlls/ntdll/unix/env.c @@ -799,6 +799,7 @@ static void init_locale(void) struct locale_nls_header *header; const NLS_LOCALE_HEADER *locale_table; const NLS_LOCALE_DATA *locale; + char *p;
setlocale( LC_ALL, "" ); if (!unix_to_win_locale( setlocale( LC_CTYPE, NULL ), system_locale )) system_locale[0] = 0; @@ -863,10 +864,21 @@ static void init_locale(void) if ((header = read_nls_file( "locale.nls" ))) { locale_table = (const NLS_LOCALE_HEADER *)((char *)header + header->locales); - if ((locale = get_win_locale( locale_table, system_locale )) && locale->idefaultlanguage != LOCALE_CUSTOM_UNSPECIFIED) + while (!(locale = get_win_locale( locale_table, system_locale ))) + { + if (!(p = strrchr( system_locale, '-' ))) break; + *p = 0; + } + if (locale && locale->idefaultlanguage != LOCALE_CUSTOM_UNSPECIFIED) system_lcid = locale->idefaultlanguage; - if ((locale = get_win_locale( locale_table, user_locale ))) - user_lcid = locale->idefaultlanguage; + + while (!(locale = get_win_locale( locale_table, user_locale ))) + { + if (!(p = strrchr( user_locale, '-' ))) break; + *p = 0; + } + if (locale) user_lcid = locale->idefaultlanguage; + free( header ); } if (!system_lcid) system_lcid = MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT );