]> git.saurik.com Git - wxWidgets.git/commitdiff
Implemented wxLocale::IsAvailable for unix systems
authorRobin Dunn <robin@alldunn.com>
Sat, 2 Dec 2006 04:52:46 +0000 (04:52 +0000)
committerRobin Dunn <robin@alldunn.com>
Sat, 2 Dec 2006 04:52:46 +0000 (04:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43738 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/locale.tex
src/common/intl.cpp

index 66197b87e8a2c9d7934f8b44e218cf80d494bb0e..7acf7cf621cb8b7a2e5af3ea5fcc2d397da61983 100644 (file)
@@ -433,7 +433,7 @@ given a two letter ISO language code, use
 wxLanguageInfo structure. See \helpref{AddLanguage}{wxlocaleaddlanguage} for
 the wxLanguageInfo description.
 
-\newsince{2.7.1}. Currently only implemented under Windows.
+\newsince{2.7.1}. 
 
 
 \membersection{wxLocale::IsLoaded}\label{wxlocaleisloaded}
index 4d689229a7280b1edc3a86c8657c28eda3c78f5e..93052fae795da92a5c033885fceef5a91d6e2dea 100644 (file)
@@ -2724,7 +2724,7 @@ bool wxLocale::IsAvailable(int lang)
     const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang);
     wxCHECK_MSG( info, false, _T("invalid language") );
 
-#ifdef __WIN32__
+#if defined(__WIN32__)
     if ( !info->WinLang )
         return false;
 
@@ -2734,10 +2734,23 @@ bool wxLocale::IsAvailable(int lang)
                          SORT_DEFAULT),
                 LCID_INSTALLED
             ) )
-      return false;
-#else // !__WIN32__
-    // TODO: test if setlocale(info->CanonicalName) works under other OS?
-#endif // __WIN32__/!__WIN32__
+        return false;
+
+#elif defined(__UNIX__)
+    
+    // Test if setting the locale works, then set it back. 
+    wxMB2WXbuf oldLocale = wxSetlocale(LC_ALL, wxEmptyString);
+    wxMB2WXbuf tmp = wxSetlocaleTryUTF(LC_ALL, info->CanonicalName);
+    if ( !tmp )
+    {
+        // Some C libraries don't like xx_YY form and require xx only
+        tmp = wxSetlocaleTryUTF(LC_ALL, info->CanonicalName.Left(2));
+        if ( !tmp )
+            return false;
+    }
+    // restore the original locale
+    wxSetlocale(LC_ALL, oldLocale);    
+#endif 
 
     return true;
 }