Ken Thomases : kernel32: On Mac, construct locale string from language and country codes.

Alexandre Julliard julliard at winehq.org
Thu Dec 10 10:01:01 CST 2009


Module: wine
Branch: master
Commit: 21acb71e4248ffc9b675caaf83ac8f399f91adce
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=21acb71e4248ffc9b675caaf83ac8f399f91adce

Author: Ken Thomases <ken at codeweavers.com>
Date:   Wed Dec  9 15:02:55 2009 -0600

kernel32: On Mac, construct locale string from language and country codes.

Don't rely on CFLocaleGetIdentifier(), whose result may not be sensible to
the C library.

---

 dlls/kernel32/locale.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index f1e6370..ac33e78 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -2929,16 +2929,27 @@ void LOCALE_Init(void)
     CFArrayRef preferred_locales, all_locales;
     CFStringRef user_language_string_ref = NULL;
     char user_locale[50];
-    char* p;
 
     CFLocaleRef user_locale_ref = CFLocaleCopyCurrent();
-    CFStringRef user_locale_string_ref = CFLocaleGetIdentifier( user_locale_ref );
+    CFStringRef user_locale_lang_ref = CFLocaleGetValue( user_locale_ref, kCFLocaleLanguageCode );
+    CFStringRef user_locale_country_ref = CFLocaleGetValue( user_locale_ref, kCFLocaleCountryCode );
+    CFStringRef user_locale_string_ref;
+
+    if (user_locale_country_ref)
+    {
+        user_locale_string_ref = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@_%@.UTF-8"),
+            user_locale_lang_ref, user_locale_country_ref);
+    }
+    else
+    {
+        user_locale_string_ref = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.UTF-8"),
+            user_locale_lang_ref);
+    }
 
     CFStringGetCString( user_locale_string_ref, user_locale, sizeof(user_locale), kCFStringEncodingUTF8 );
     CFRelease( user_locale_ref );
-    /* Strip modifiers because setlocale() can't parse them. */
-    if ((p = strchr( user_locale, '@' ))) *p = 0;
-    if (!strchr( user_locale, '.' )) strcat( user_locale, ".UTF-8" );
+    CFRelease( user_locale_string_ref );
+
     unix_cp = CP_UTF8;  /* default to utf-8 even if we don't get a valid locale */
     setenv( "LANG", user_locale, 0 );
     TRACE( "setting locale to '%s'\n", user_locale );




More information about the wine-cvs mailing list