X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7bf2b0881a6bf28138f258504e88b2643daa854e..64b1cea09aac1077469090dc2dac9a139a509833:/src/common/intl.cpp?ds=sidebyside diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 8d0f5f9891..bffac09ffd 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -73,9 +73,9 @@ #include "wx/filesys.h" #if defined(__DARWIN__) - #include "wx/mac/corefoundation/cfref.h" + #include "wx/osx/core/cfref.h" #include - #include "wx/mac/corefoundation/cfstring.h" + #include "wx/osx/core/cfstring.h" #endif // ---------------------------------------------------------------------------- @@ -94,7 +94,7 @@ typedef wxUint32 size_t32; const size_t32 MSGCATALOG_MAGIC = 0x950412de; 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_SUBLANG = 2; static const size_t LEN_FULL = LEN_LANG + 1 + LEN_SUBLANG; // 1 for '_' @@ -135,23 +135,27 @@ public: static wxLocale *wxSetLocale(wxLocale *pLocale); -// helper functions of GetSystemLanguage() -#ifdef __UNIX__ +namespace +{ // get just the language part -static inline wxString ExtractLang(const wxString& langFull) +inline wxString ExtractLang(const wxString& langFull) { return langFull.Left(LEN_LANG); } +// helper functions of GetSystemLanguage() +#ifdef __UNIX__ + // get everything else (including the leading '_') -static inline wxString ExtractNotLang(const wxString& langFull) +inline wxString ExtractNotLang(const wxString& langFull) { return langFull.Mid(LEN_LANG); } #endif // __UNIX__ +} // anonymous namespace // ---------------------------------------------------------------------------- // Plural forms parser @@ -933,7 +937,7 @@ private: // facilitate doing pointer arithmetic with it char *StringData() const { - return wx_static_cast(char *, m_data.GetData()); + return static_cast(m_data.GetData()); } const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const @@ -1173,6 +1177,9 @@ static wxString GetFullSearchPath(const wxString& lang) bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, wxPluralFormsCalculatorPtr& rPluralFormsCalculator) { + wxCHECK_MSG( szDirPrefix.length() >= LEN_LANG, false, + "invalid language specification" ); + wxString searchPath; #if wxUSE_FONTMAP @@ -1191,14 +1198,13 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, searchPath += GetFullSearchPath(szDirPrefix); - size_t sublocaleIndex = szDirPrefix.find(wxS('_')); - if ( sublocaleIndex != wxString::npos ) + if ( szDirPrefix[LEN_LANG] == wxS('_') ) { - // also add just base locale name: for things like "fr_BE" (belgium - // french) we should use "fr" if no belgium specific message catalogs - // exist + // also add just base locale name: for things like "fr_BE" (Belgium + // French) we should use fall back on plain "fr" if no Belgium-specific + // message catalogs exist searchPath << wxPATH_SEP - << GetFullSearchPath(szDirPrefix.Left(sublocaleIndex)); + << GetFullSearchPath(ExtractLang(szDirPrefix)); } // don't give translation errors here because the wxstd catalog might @@ -1263,6 +1269,8 @@ bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName, // read the whole file in memory if ( fileMsg.Read(m_data.GetWriteBuf(nSize), nSize) != lenFile ) return false; + + m_data.UngetWriteBuf(nSize); #endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM @@ -1760,7 +1768,7 @@ bool wxLocale::Init(int language, int flags) const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale); - const wxString langOnly = locale.Left(2); + const wxString langOnly = ExtractLang(locale); if ( !retloc ) { // Some C libraries don't like xx_YY form and require xx only @@ -1793,11 +1801,11 @@ bool wxLocale::Init(int language, int flags) // so will translate the abbrev for them wxString localeAlt; if ( langOnly == wxS("he") ) - localeAlt = wxS("iw") + locale.Mid(3); + localeAlt = wxS("iw") + ExtractNotLang(locale); else if ( langOnly == wxS("id") ) - localeAlt = wxS("in") + locale.Mid(3); + localeAlt = wxS("in") + ExtractNotLang(locale); else if ( langOnly == wxS("yi") ) - localeAlt = wxS("ji") + locale.Mid(3); + localeAlt = wxS("ji") + ExtractNotLang(locale); else if ( langOnly == wxS("nb") ) localeAlt = wxS("no_NO"); else if ( langOnly == wxS("nn") ) @@ -1807,7 +1815,7 @@ bool wxLocale::Init(int language, int flags) { retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt); if ( !retloc ) - retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt.Left(2)); + retloc = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(localeAlt)); } } @@ -1893,7 +1901,7 @@ bool wxLocale::Init(int language, int flags) if ( !retloc ) { // 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 wxUnusedVar(flags); @@ -2536,7 +2544,7 @@ bool wxLocale::IsAvailable(int lang) if ( !tmp ) { // 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 ) return false; } @@ -2565,38 +2573,43 @@ bool wxLocale::AddCatalog(const wxString& szDomain, const wxString& msgIdCharset) { - wxMsgCatalog *pMsgCat = new wxMsgCatalog; - - if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) ) { - // add it to the head of the list so that in GetString it will - // be searched before the catalogs added earlier - pMsgCat->m_pNext = m_pMsgCat; - m_pMsgCat = pMsgCat; + wxCHECK_MSG( IsOk(), false, "must initialize catalog first" ); - return true; - } - else { - // don't add it because it couldn't be loaded anyway - delete pMsgCat; // 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 // source code: - if (m_language == msgIdLanguage) + if ( msgIdLanguage == m_language ) return true; + + wxMsgCatalog *pMsgCat = new wxMsgCatalog; + + if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) ) + { + // add it to the head of the list so that in GetString it will + // be searched before the catalogs added earlier + pMsgCat->m_pNext = m_pMsgCat; + m_pMsgCat = pMsgCat; + + return true; + } + + // don't add it because it couldn't be loaded anyway + delete pMsgCat; + + // If there's no exact match, we may still get partial match where the // (basic) language is same, but the country differs. For example, it's // permitted to use en_US strings from sources even if m_language is en_GB: const wxLanguageInfo *msgIdLangInfo = GetLanguageInfo(msgIdLanguage); if ( msgIdLangInfo && - msgIdLangInfo->CanonicalName.Mid(0, 2) == m_strShort.Mid(0, 2) ) + ExtractLang(msgIdLangInfo->CanonicalName) == ExtractLang(m_strShort) ) { return true; } return false; - } } // ---------------------------------------------------------------------------- @@ -3452,9 +3465,9 @@ void wxLocale::InitLanguagesDB() LNG(wxLANGUAGE_SANGHO, "sg" , 0 , 0 , wxLayout_LeftToRight, "Sangho") LNG(wxLANGUAGE_SANSKRIT, "sa" , LANG_SANSKRIT , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Sanskrit") LNG(wxLANGUAGE_SCOTS_GAELIC, "gd" , 0 , 0 , wxLayout_LeftToRight, "Scots Gaelic") - LNG(wxLANGUAGE_SERBIAN, "sr_SR", LANG_SERBIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Serbian") - LNG(wxLANGUAGE_SERBIAN_CYRILLIC, "sr_SR", LANG_SERBIAN , SUBLANG_SERBIAN_CYRILLIC , wxLayout_LeftToRight, "Serbian (Cyrillic)") - LNG(wxLANGUAGE_SERBIAN_LATIN, "sr_SR@latin", LANG_SERBIAN , SUBLANG_SERBIAN_LATIN , wxLayout_LeftToRight, "Serbian (Latin)") + LNG(wxLANGUAGE_SERBIAN, "sr_RS", LANG_SERBIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Serbian") + LNG(wxLANGUAGE_SERBIAN_CYRILLIC, "sr_RS", LANG_SERBIAN , SUBLANG_SERBIAN_CYRILLIC , wxLayout_LeftToRight, "Serbian (Cyrillic)") + LNG(wxLANGUAGE_SERBIAN_LATIN, "sr_RS@latin", LANG_SERBIAN , SUBLANG_SERBIAN_LATIN , wxLayout_LeftToRight, "Serbian (Latin)") LNG(wxLANGUAGE_SERBIAN_CYRILLIC, "sr_YU", LANG_SERBIAN , SUBLANG_SERBIAN_CYRILLIC , wxLayout_LeftToRight, "Serbian (Cyrillic)") LNG(wxLANGUAGE_SERBIAN_LATIN, "sr_YU@latin", LANG_SERBIAN , SUBLANG_SERBIAN_LATIN , wxLayout_LeftToRight, "Serbian (Latin)") LNG(wxLANGUAGE_SERBO_CROATIAN, "sh" , 0 , 0 , wxLayout_LeftToRight, "Serbo-Croatian") @@ -3513,7 +3526,7 @@ void wxLocale::InitLanguagesDB() LNG(wxLANGUAGE_UZBEK, "uz" , LANG_UZBEK , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Uzbek") LNG(wxLANGUAGE_UZBEK_CYRILLIC, "uz" , LANG_UZBEK , SUBLANG_UZBEK_CYRILLIC , wxLayout_LeftToRight, "Uzbek (Cyrillic)") LNG(wxLANGUAGE_UZBEK_LATIN, "uz" , LANG_UZBEK , SUBLANG_UZBEK_LATIN , wxLayout_LeftToRight, "Uzbek (Latin)") - LNG(wxLANGUAGE_VALENCIAN, "ca_ES@valencia", 0 , 0 , wxLayout_LeftToRight, "Valencian") + LNG(wxLANGUAGE_VALENCIAN, "ca_ES@valencia", 0 , 0 , wxLayout_LeftToRight, "Valencian (Souternhern Catalan)") LNG(wxLANGUAGE_VIETNAMESE, "vi_VN", LANG_VIETNAMESE, SUBLANG_DEFAULT , wxLayout_LeftToRight, "Vietnamese") LNG(wxLANGUAGE_VOLAPUK, "vo" , 0 , 0 , wxLayout_LeftToRight, "Volapuk") LNG(wxLANGUAGE_WELSH, "cy" , 0 , 0 , wxLayout_LeftToRight, "Welsh")