added animate contrib
[wxWidgets.git] / src / common / intl.cpp
index 50228ca0a171d2ff27780691cf442c45cfc8b325..69178b2abc00766a56c47bbe4f3a995d5a7a25ea 100644 (file)
@@ -141,6 +141,7 @@ static inline wxString ExtractNotLang(const wxString& langFull)
 #endif // __UNIX__
 
 
+
 // ----------------------------------------------------------------------------
 // wxMsgCatalogFile corresponds to one disk-file message catalog.
 //
@@ -614,7 +615,8 @@ bool wxLocale::Init(const wxChar *szName,
 
     wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") );
   }
-  m_pszOldLocale = wxSetlocale(LC_ALL, szLocale);
+
+  m_pszOldLocale = wxStrdup(wxSetlocale(LC_ALL, szLocale));
   if ( m_pszOldLocale == NULL )
     wxLogError(_("locale '%s' can not be set."), szLocale);
 
@@ -643,6 +645,23 @@ bool wxLocale::Init(const wxChar *szName,
   return bOk;
 }
 
+
+#if defined(__UNIX__) && wxUSE_UNICODE
+static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc)
+{
+    wxMB2WXbuf l = wxSetlocale(c, lc);
+    if ( lc && lc[0] != 0 && !l )
+    {
+       wxString buf(lc);
+       buf += wxT(".utf8");
+       l = wxSetlocale(c, buf.c_str());
+    }
+    return l;
+}
+#else
+#define wxSetlocaleTryUTF(c, lc)  wxSetlocale(c, lc)
+#endif
+
 bool wxLocale::Init(int language, int flags)
 {
     int lang = language;
@@ -678,12 +697,12 @@ bool wxLocale::Init(int language, int flags)
     else
         locale = info->CanonicalName;
 
-    wxMB2WXbuf retloc = wxSetlocale(LC_ALL, locale);
+    wxMB2WXbuf retloc = wxSetlocaleTryUTF(LC_ALL, locale);
 
     if ( !retloc )
     {
         // Some C libraries don't like xx_YY form and require xx only
-        retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale.Mid(0,2));
     }
     if ( !retloc )
     {
@@ -701,13 +720,13 @@ bool wxLocale::Init(int language, int flags)
         else if (mid == wxT("nn"))
             locale = wxT("no_NY");
 
-        retloc = wxSetlocale(LC_ALL, locale);
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale);
     }
     if ( !retloc )
     {
         // (This time, we changed locale in previous if-branch, so try again.)
         // Some C libraries don't like xx_YY form and require xx only
-        retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
+        retloc = wxSetlocaleTryUTF(LC_ALL, locale.Mid(0,2));
     }
     if ( !retloc )
     {
@@ -803,12 +822,15 @@ bool wxLocale::Init(int language, int flags)
 #endif
 
 #ifndef WX_NO_LOCALE_SUPPORT
-     wxChar *szLocale = retloc ? wxStrdup(retloc) : NULL;
+    wxChar *szLocale = retloc ? wxStrdup(retloc) : NULL;
     bool ret = Init(name, canonical, retloc,
                     (flags & wxLOCALE_LOAD_DEFAULT) != 0,
                     (flags & wxLOCALE_CONV_ENCODING) != 0);
-    if (szLocale)
-        free(szLocale);
+    free(szLocale);
+
+    if ( ret )
+        m_language = lang;
+
     return ret;
 #endif
 }
@@ -1444,6 +1466,16 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang)
     return NULL;
 }
 
+/* static */
+wxString wxLocale::GetLanguageName(int lang)
+{
+    const wxLanguageInfo *info = GetLanguageInfo(lang);
+    if ( !info )
+        return wxEmptyString;
+    else
+        return info->Description;
+}
+
 /* static */
 const wxLanguageInfo *wxLocale::FindLanguageInfo(const wxString& locale)
 {
@@ -1499,6 +1531,7 @@ wxLocale::~wxLocale()
     // restore old locale
     wxSetLocale(m_pOldLocale);
     wxSetlocale(LC_ALL, m_pszOldLocale);
+    free((wxChar *)m_pszOldLocale);     // const_cast
 }
 
 // get the translation of given string in current locale