consistently use ExtractLang() everywhere instead of Left/Mid wxString methods; added ExtractCountry()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56764 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -94,7 +94,7 @@ typedef wxUint32 size_t32;
|
|||||||
const size_t32 MSGCATALOG_MAGIC = 0x950412de;
|
const size_t32 MSGCATALOG_MAGIC = 0x950412de;
|
||||||
const size_t32 MSGCATALOG_MAGIC_SW = 0xde120495;
|
const size_t32 MSGCATALOG_MAGIC_SW = 0xde120495;
|
||||||
|
|
||||||
// the constants describing the format of lang_LANG locale string
|
// the constants describing the format of ll_CC locale string
|
||||||
static const size_t LEN_LANG = 2;
|
static const size_t LEN_LANG = 2;
|
||||||
static const size_t LEN_SUBLANG = 2;
|
static const size_t LEN_SUBLANG = 2;
|
||||||
static const size_t LEN_FULL = LEN_LANG + 1 + LEN_SUBLANG; // 1 for '_'
|
static const size_t LEN_FULL = LEN_LANG + 1 + LEN_SUBLANG; // 1 for '_'
|
||||||
@@ -135,23 +135,27 @@ public:
|
|||||||
|
|
||||||
static wxLocale *wxSetLocale(wxLocale *pLocale);
|
static wxLocale *wxSetLocale(wxLocale *pLocale);
|
||||||
|
|
||||||
// helper functions of GetSystemLanguage()
|
namespace
|
||||||
#ifdef __UNIX__
|
{
|
||||||
|
|
||||||
// get just the language part
|
// get just the language part
|
||||||
static inline wxString ExtractLang(const wxString& langFull)
|
inline wxString ExtractLang(const wxString& langFull)
|
||||||
{
|
{
|
||||||
return langFull.Left(LEN_LANG);
|
return langFull.Left(LEN_LANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper functions of GetSystemLanguage()
|
||||||
|
#ifdef __UNIX__
|
||||||
|
|
||||||
// get everything else (including the leading '_')
|
// get everything else (including the leading '_')
|
||||||
static inline wxString ExtractNotLang(const wxString& langFull)
|
inline wxString ExtractNotLang(const wxString& langFull)
|
||||||
{
|
{
|
||||||
return langFull.Mid(LEN_LANG);
|
return langFull.Mid(LEN_LANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Plural forms parser
|
// Plural forms parser
|
||||||
@@ -1191,14 +1195,13 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName,
|
|||||||
|
|
||||||
|
|
||||||
searchPath += GetFullSearchPath(szDirPrefix);
|
searchPath += GetFullSearchPath(szDirPrefix);
|
||||||
size_t sublocaleIndex = szDirPrefix.find(wxS('_'));
|
if ( szDirPrefix[LEN_LANG] == wxS('_') )
|
||||||
if ( sublocaleIndex != wxString::npos )
|
|
||||||
{
|
{
|
||||||
// also add just base locale name: for things like "fr_BE" (belgium
|
// also add just base locale name: for things like "fr_BE" (Belgium
|
||||||
// french) we should use "fr" if no belgium specific message catalogs
|
// French) we should use fall back on plain "fr" if no Belgium-specific
|
||||||
// exist
|
// message catalogs exist
|
||||||
searchPath << wxPATH_SEP
|
searchPath << wxPATH_SEP
|
||||||
<< GetFullSearchPath(szDirPrefix.Left(sublocaleIndex));
|
<< GetFullSearchPath(ExtractLang(szDirPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't give translation errors here because the wxstd catalog might
|
// don't give translation errors here because the wxstd catalog might
|
||||||
@@ -1762,7 +1765,7 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
|
|
||||||
const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
|
const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
|
||||||
|
|
||||||
const wxString langOnly = locale.Left(2);
|
const wxString langOnly = ExtractLang(locale);
|
||||||
if ( !retloc )
|
if ( !retloc )
|
||||||
{
|
{
|
||||||
// Some C libraries don't like xx_YY form and require xx only
|
// Some C libraries don't like xx_YY form and require xx only
|
||||||
@@ -1795,11 +1798,11 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
// so will translate the abbrev for them
|
// so will translate the abbrev for them
|
||||||
wxString localeAlt;
|
wxString localeAlt;
|
||||||
if ( langOnly == wxS("he") )
|
if ( langOnly == wxS("he") )
|
||||||
localeAlt = wxS("iw") + locale.Mid(3);
|
localeAlt = wxS("iw") + ExtractNotLang(locale);
|
||||||
else if ( langOnly == wxS("id") )
|
else if ( langOnly == wxS("id") )
|
||||||
localeAlt = wxS("in") + locale.Mid(3);
|
localeAlt = wxS("in") + ExtractNotLang(locale);
|
||||||
else if ( langOnly == wxS("yi") )
|
else if ( langOnly == wxS("yi") )
|
||||||
localeAlt = wxS("ji") + locale.Mid(3);
|
localeAlt = wxS("ji") + ExtractNotLang(locale);
|
||||||
else if ( langOnly == wxS("nb") )
|
else if ( langOnly == wxS("nb") )
|
||||||
localeAlt = wxS("no_NO");
|
localeAlt = wxS("no_NO");
|
||||||
else if ( langOnly == wxS("nn") )
|
else if ( langOnly == wxS("nn") )
|
||||||
@@ -1809,7 +1812,7 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
{
|
{
|
||||||
retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt);
|
retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt);
|
||||||
if ( !retloc )
|
if ( !retloc )
|
||||||
retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt.Left(2));
|
retloc = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(localeAlt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1895,7 +1898,7 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
if ( !retloc )
|
if ( !retloc )
|
||||||
{
|
{
|
||||||
// Some C libraries don't like xx_YY form and require xx only
|
// Some C libraries don't like xx_YY form and require xx only
|
||||||
retloc = wxSetlocale(LC_ALL, locale.Mid(0,2));
|
retloc = wxSetlocale(LC_ALL, ExtractLang(locale));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
wxUnusedVar(flags);
|
wxUnusedVar(flags);
|
||||||
@@ -2538,7 +2541,7 @@ bool wxLocale::IsAvailable(int lang)
|
|||||||
if ( !tmp )
|
if ( !tmp )
|
||||||
{
|
{
|
||||||
// Some C libraries don't like xx_YY form and require xx only
|
// Some C libraries don't like xx_YY form and require xx only
|
||||||
tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName.Left(2));
|
tmp = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
|
||||||
if ( !tmp )
|
if ( !tmp )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2569,7 +2572,8 @@ bool wxLocale::AddCatalog(const wxString& szDomain,
|
|||||||
{
|
{
|
||||||
wxMsgCatalog *pMsgCat = new wxMsgCatalog;
|
wxMsgCatalog *pMsgCat = new wxMsgCatalog;
|
||||||
|
|
||||||
if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) ) {
|
if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) )
|
||||||
|
{
|
||||||
// add it to the head of the list so that in GetString it will
|
// add it to the head of the list so that in GetString it will
|
||||||
// be searched before the catalogs added earlier
|
// be searched before the catalogs added earlier
|
||||||
pMsgCat->m_pNext = m_pMsgCat;
|
pMsgCat->m_pNext = m_pMsgCat;
|
||||||
@@ -2577,14 +2581,15 @@ bool wxLocale::AddCatalog(const wxString& szDomain,
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// don't add it because it couldn't be loaded anyway
|
// don't add it because it couldn't be loaded anyway
|
||||||
delete pMsgCat;
|
delete pMsgCat;
|
||||||
|
|
||||||
|
|
||||||
// It is OK to not load catalog if the msgid language and m_language match,
|
// It is OK to not load catalog if the msgid language and m_language match,
|
||||||
// in which case we can directly display the texts embedded in program's
|
// in which case we can directly display the texts embedded in program's
|
||||||
// source code:
|
// source code:
|
||||||
if (m_language == msgIdLanguage)
|
if ( msgIdLanguage == m_language )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// If there's no exact match, we may still get partial match where the
|
// If there's no exact match, we may still get partial match where the
|
||||||
@@ -2592,13 +2597,12 @@ bool wxLocale::AddCatalog(const wxString& szDomain,
|
|||||||
// permitted to use en_US strings from sources even if m_language is en_GB:
|
// permitted to use en_US strings from sources even if m_language is en_GB:
|
||||||
const wxLanguageInfo *msgIdLangInfo = GetLanguageInfo(msgIdLanguage);
|
const wxLanguageInfo *msgIdLangInfo = GetLanguageInfo(msgIdLanguage);
|
||||||
if ( msgIdLangInfo &&
|
if ( msgIdLangInfo &&
|
||||||
msgIdLangInfo->CanonicalName.Mid(0, 2) == m_strShort.Mid(0, 2) )
|
ExtractLang(msgIdLangInfo->CanonicalName) == ExtractLang(m_strShort) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user