+// check if the given locale is provided by OS and C run time
+/* static */
+bool wxLocale::IsAvailable(int lang)
+{
+ const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang);
+ wxCHECK_MSG( info, false, _T("invalid language") );
+
+#if defined(__WIN32__)
+ if ( !info->WinLang )
+ return false;
+
+ if ( !::IsValidLocale
+ (
+ MAKELCID(MAKELANGID(info->WinLang, info->WinSublang),
+ SORT_DEFAULT),
+ LCID_INSTALLED
+ ) )
+ 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;
+}
+