]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxLocale::FindLanguageInfo()
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Feb 2003 16:43:10 +0000 (16:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Feb 2003 16:43:10 +0000 (16:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index fe59e6e09ec163e721065b1c3113beb6da5339e7..d6f8d46d2c6d03f58baf8feb5cc4517b2b4496e4 100644 (file)
@@ -395,6 +395,22 @@ struct WXDLLEXPORT wxLanguageInfo
 \perlnote{In wxPerl Wx::LanguageInfo has only one method:\par
 Wx::LanguageInfo->new( language, canonicalName, WinLang, WinSubLang, Description )}
 
+\membersection{wxLocale::FindLanguageInfo}{wxlocalefindlanguageinfo}
+
+\constfunc{static wxLanguageInfo *}{FindLanguageInfo}{\param{const wxString\& }{locale}}
+
+This function may be used to find the language description structure for the
+given locale, specified either as a two letter ISO language code (for example,
+"pt"), a language code followed by the country code ("pt\_BR") or a full, human
+readable, language description ("Portuguese-Brazil").
+
+Returns the information for the given language or {\tt NULL} if this language
+is unknown. Note that even if the returned pointer is valid, the caller should
+{\it not} delete it.
+
+\wxheading{See also}
+
+\helpref{GetLanguageInfo}{wxlocalegetlanguageinfo}
 
 \membersection{wxLocale::GetCanonicalName}\label{wxlocalegetcanonicalname}
 
index 2f503453257346ad657258dd78bcd3558ab91eb1..379ff977ba4775e8783d663402d222fd43c4f0a1 100644 (file)
@@ -455,6 +455,13 @@ public:
     // Returns NULL if no info found, pointer must *not* be deleted by caller
     static const wxLanguageInfo *GetLanguageInfo(int lang);
 
+    // Find the language for the given locale string which may be either a
+    // canonical ISO 2 letter language code ("xx"), a language code followed by
+    // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
+    //
+    // Returns NULL if no info found, pointer must *not* be deleted by caller
+    static const wxLanguageInfo *FindLanguageInfo(const wxString& locale);
+
     // Add custom language to the list of known languages.
     // Notes: 1) wxLanguageInfo contains platform-specific data
     //        2) must be called before Init to have effect
index e2a7299f7aef6ff59178ac3b98a926264272f1eb..9fbde46e7c95a467df24837a55c7dd7719d94041 100644 (file)
@@ -1395,7 +1395,7 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang)
 {
     CreateLanguagesDB();
 
-    size_t count = ms_languagesDB->GetCount();
+    const size_t count = ms_languagesDB->GetCount();
     for ( size_t i = 0; i < count; i++ )
     {
         if ( ms_languagesDB->Item(i).Language == lang )
@@ -1407,6 +1407,42 @@ const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang)
     return NULL;
 }
 
+/* static */
+const wxLanguageInfo *wxLocale::FindLanguageInfo(const wxString& locale)
+{
+    CreateLanguagesDB();
+
+    const wxLanguageInfo *infoRet = NULL;
+
+    const size_t count = ms_languagesDB->GetCount();
+    for ( size_t i = 0; i < count; i++ )
+    {
+        const wxLanguageInfo *info = &ms_languagesDB->Item(i);
+
+        if ( wxStricmp(locale, info->CanonicalName) == 0 ||
+                wxStricmp(locale, info->Description) == 0 )
+        {
+            // exact match, stop searching
+            infoRet = info;
+            break;
+        }
+
+        if ( wxStricmp(locale, info->CanonicalName.BeforeFirst(_T('_'))) == 0 )
+        {
+            // a match -- but maybe we'll find an exact one later, so continue
+            // looking
+            //
+            // OTOH, maybe we had already found a language match and in this
+            // case don't overwrite it becauce the entry for the default
+            // country always appears first in ms_languagesDB
+            if ( !infoRet )
+                infoRet = info;
+        }
+    }
+
+    return infoRet;
+}
+
 wxString wxLocale::GetSysName() const
 {
     return wxSetlocale(LC_ALL, NULL);