]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/intl.cpp
no 10.4 support anymore
[wxWidgets.git] / src / common / intl.cpp
index 575900d041359e90d91902d1f48b5a20627af2e4..40d6fa1db5b73720507786742641b009962b7fa1 100644 (file)
@@ -1033,7 +1033,14 @@ wxLocale::~wxLocale()
 bool wxLocale::IsAvailable(int lang)
 {
     const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang);
-    wxCHECK_MSG( info, false, wxS("invalid language") );
+    if ( !info )
+    {
+        // The language is unknown (this normally only happens when we're
+        // passed wxLANGUAGE_DEFAULT), so we can't support it.
+        wxASSERT_MSG( lang == wxLANGUAGE_DEFAULT,
+                      wxS("No info for a valid language?") );
+        return false;
+    }
 
 #if defined(__WIN32__)
     if ( !info->WinLang )
@@ -1045,16 +1052,21 @@ bool wxLocale::IsAvailable(int lang)
 #elif defined(__UNIX__)
 
     // Test if setting the locale works, then set it back.
-    const char *oldLocale = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
-    if ( !oldLocale )
-    {
-        // Some C libraries don't like xx_YY form and require xx only
-        oldLocale = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
-        if ( !oldLocale )
-            return false;
-    }
+    char * const oldLocale = wxStrdupA(setlocale(LC_ALL, NULL));
+
+    // Some platforms don't like xx_YY form and require xx only so test for
+    // it too.
+    const bool
+        available = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName) ||
+                    wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
+
     // restore the original locale
     wxSetlocale(LC_ALL, oldLocale);
+
+    free(oldLocale);
+
+    if ( !available )
+        return false;
 #endif
 
     return true;
@@ -1437,7 +1449,23 @@ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat)
                                      : LOCALE_SDECIMAL,
                                  buf,
                                  WXSIZEOF(buf)) )
+            {
                 str = buf;
+
+                // As we get our decimal point separator from Win32 and not the
+                // CRT there is a possibility of mismatch between them and this
+                // can easily happen if the user code called setlocale()
+                // instead of using wxLocale to change the locale. And this can
+                // result in very strange bugs elsewhere in the code as the
+                // assumptions that formatted strings do use the decimal
+                // separator actually fail, so check for it here.
+                wxASSERT_MSG
+                (
+                    wxString::Format("%.3f", 1.23).find(str) != wxString::npos,
+                    "Decimal separator mismatch -- did you use setlocale()?"
+                    "If so, use wxLocale to change the locale instead."
+                );
+            }
             break;
 
         case wxLOCALE_SHORT_DATE_FMT: