From 184685588e94bcd97866f62cf9fa85e69831a976 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Wed, 5 Dec 2007 21:50:20 +0000 Subject: [PATCH] extending locale detection git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50482 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/wxcrt.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/common/wxcrt.cpp b/src/common/wxcrt.cpp index d7de48de96..55339ef61d 100644 --- a/src/common/wxcrt.cpp +++ b/src/common/wxcrt.cpp @@ -65,6 +65,7 @@ using namespace std ; #include "wx/mac/corefoundation/cfref.h" #include #include "wx/mac/corefoundation/cfstring.h" + #include #endif #if wxUSE_WCHAR_T @@ -163,13 +164,26 @@ char* wxSetlocale(int category, const char *locale) char *rv = NULL ; if ( locale != NULL && locale[0] == 0 ) { - // we have to emulate the behaviour under OS X - wxCFRef userLocaleRef(CFLocaleCopyCurrent()); - wxMacCFStringHolder str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); - wxString langFull = str.AsString()+"_"; - str.Assign(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); - langFull += str.AsString(); - rv = setlocale(category, langFull.c_str()); + locale_t lt = newlocale(LC_ALL_MASK, "", NULL); + if ( lt ) + { + rv = (char*) querylocale( LC_ALL_MASK, lt ); + freelocale(lt); + } + if ( rv == NULL || rv[0] == 0 || strcmp( rv , "C" ) == 0 || strcmp( rv, "POSIX" ) == 0 ) + { + // we have to emulate the behaviour under OS X + wxCFRef userLocaleRef(CFLocaleCopyCurrent()); + wxMacCFStringHolder str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode))); + wxString langFull = str.AsString()+"_"; + str.Assign(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode))); + langFull += str.AsString(); + rv = setlocale(category, langFull.c_str()); + } + else + { + rv = setlocale(category, rv); + } } else rv = setlocale(category, locale); -- 2.45.2