FIXME: UNICODE SUPPORT: must use CHARSET specifier!
*/
wxString szName = szName0;
- if(szName.Find(wxT('.')) != -1) // contains a dot
+ if(szName.Find(wxT('.')) != wxNOT_FOUND) // contains a dot
szName = szName.Left(szName.Find(wxT('.')));
wxString searchPath = GetFullSearchPath(szDirPrefix);
wxString strFullName;
if ( !wxFindFileInPath(&strFullName, searchPath, strFile) ) {
wxLogVerbose(_("catalog file for domain '%s' not found."), szName.c_str());
- return FALSE;
+ return false;
}
// open file
wxFile fileMsg(strFullName);
if ( !fileMsg.IsOpened() )
- return FALSE;
+ return false;
// get the file size
- off_t nSize = fileMsg.Length();
+ wxFileOffset nSize = fileMsg.Length();
if ( nSize == wxInvalidOffset )
- return FALSE;
+ return false;
// read the whole file in memory
m_pData = new size_t8[nSize];
if ( fileMsg.Read(m_pData, nSize) != nSize ) {
wxDELETEA(m_pData);
- return FALSE;
+ return false;
}
// examine header
wxLogWarning(_("'%s' is not a valid message catalog."), strFullName.c_str());
wxDELETEA(m_pData);
- return FALSE;
+ return false;
}
// initialize
{
#if wxUSE_WCHAR_T
wxCSConv *csConv = NULL;
- if ( !!m_charset )
+ if ( !m_charset.IsEmpty() )
csConv = new wxCSConv(m_charset);
wxMBConv& inputConv = csConv ? *((wxMBConv*)csConv) : *wxConvCurrent;
#elif wxUSE_FONTMAP
wxASSERT_MSG( msgIdCharset == NULL,
_T("non-ASCII msgid languages only supported if wxUSE_WCHAR_T=1") );
-
+
wxEncodingConverter converter;
if ( convertEncoding )
{
wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM;
- wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(m_charset, FALSE);
+ wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(m_charset, false);
if ( enc == wxFONTENCODING_SYSTEM )
{
- convertEncoding = FALSE; // unknown encoding
+ convertEncoding = false; // unknown encoding
}
else
{
wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(enc);
if (a[0] == enc)
// no conversion needed, locale uses native encoding
- convertEncoding = FALSE;
+ convertEncoding = false;
if (a.GetCount() == 0)
// we don't know common equiv. under this platform
- convertEncoding = FALSE;
+ convertEncoding = false;
targetEnc = a[0];
}
}
if ( file.Load(szDirPrefix, szName, m_pluralFormsCalculator) )
{
file.FillHash(m_messages, msgIdCharset, bConvertEncoding);
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
const wxChar *wxMsgCatalog::GetString(const wxChar *sz, size_t n) const
// the argument to setlocale()
szLocale = szShort;
- wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") );
+ wxCHECK_MSG( szLocale, false, _T("no locale to set in wxLocale::Init()") );
}
#ifdef __WXWINCE__
// load the default catalog with wxWidgets standard messages
m_pMsgCat = NULL;
- bool bOk = TRUE;
+ bool bOk = true;
if ( bLoadDefault )
bOk = AddCatalog(wxT("wxstd"));
}
-#if defined(__UNIX__) && wxUSE_UNICODE
+#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__)
static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc)
{
wxMB2WXbuf l = wxSetlocale(c, lc);
if ( !l && lc && lc[0] != 0 )
{
- wxString buf(lc);
+ wxString buf(lc);
wxString buf2;
- buf2 = buf + wxT(".UTF-8");
- l = wxSetlocale(c, buf2.c_str());
+ buf2 = buf + wxT(".UTF-8");
+ l = wxSetlocale(c, buf2.c_str());
if ( !l )
{
buf2 = buf + wxT(".utf-8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2.c_str());
}
if ( !l )
{
buf2 = buf + wxT(".UTF8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2.c_str());
}
if ( !l )
{
buf2 = buf + wxT(".utf8");
- l = wxSetlocale(c, buf2.c_str());
+ l = wxSetlocale(c, buf2.c_str());
}
}
return l;
// We failed to detect system language, so we will use English:
if (lang == wxLANGUAGE_UNKNOWN)
{
- return FALSE;
+ return false;
}
const wxLanguageInfo *info = GetLanguageInfo(lang);
if (info == NULL)
{
wxLogError(wxT("Unknown language %i."), lang);
- return FALSE;
+ return false;
}
wxString name = info->Description;
if ( !retloc )
{
wxLogError(wxT("Cannot set locale to '%s'."), locale.c_str());
- return FALSE;
+ return false;
}
#elif defined(__WIN32__)
{
wxLogLastError(wxT("SetThreadLocale"));
wxLogError(wxT("Cannot set locale to language %s."), name.c_str());
- return FALSE;
+ return false;
}
else
{
if ( !retloc )
{
wxLogError(wxT("Cannot set locale to language %s."), name.c_str());
- return FALSE;
+ return false;
}
#elif defined(__WXMAC__) || defined(__WXPM__)
wxMB2WXbuf retloc = wxSetlocale(LC_ALL , wxEmptyString);
#else
- return FALSE;
+ return false;
#define WX_NO_LOCALE_SUPPORT
#endif
return wxFONTENCODING_CP950;
}
#elif defined(__WXMAC__)
- TextEncoding encoding = 0 ;
+ TextEncoding encoding = 0 ;
#if TARGET_CARBON
- encoding = CFStringGetSystemEncoding() ;
+ encoding = CFStringGetSystemEncoding() ;
#else
- UpgradeScriptInfoToTextEncoding ( smSystemScript , kTextLanguageDontCare , kTextRegionDontCare , NULL , &encoding ) ;
+ UpgradeScriptInfoToTextEncoding ( smSystemScript , kTextLanguageDontCare , kTextRegionDontCare , NULL , &encoding ) ;
#endif
return wxMacGetFontEncFromSystemEnc( encoding ) ;
#elif defined(__UNIX_LIKE__) && wxUSE_FONTMAP
if ( !encname.empty() )
{
wxFontEncoding enc = wxFontMapper::Get()->
- CharsetToEncoding(encname, FALSE /* not interactive */);
+ CharsetToEncoding(encname, false /* not interactive */);
// on some modern Linux systems (RedHat 8) the default system locale
// is UTF8 -- but it isn't supported by wxGTK in ANSI build at all so
return pszTrans;
}
+wxString wxLocale::GetHeaderValue( const wxChar* szHeader,
+ const wxChar* szDomain ) const
+{
+ if ( wxIsEmpty(szHeader) )
+ return wxEmptyString;
+
+ wxChar const * pszTrans = NULL;
+ wxMsgCatalog *pMsgCat;
+
+ if ( szDomain != NULL )
+ {
+ pMsgCat = FindCatalog(szDomain);
+
+ // does the catalog exist?
+ if ( pMsgCat == NULL )
+ return wxEmptyString;
+
+ pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1);
+ }
+ else
+ {
+ // search in all domains
+ for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext )
+ {
+ pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1);
+ if ( pszTrans != NULL ) // take the first found
+ break;
+ }
+ }
+
+ if ( wxIsEmpty(pszTrans) )
+ return wxEmptyString;
+
+ wxChar const * pszFound = wxStrstr(pszTrans, szHeader);
+ if ( pszFound == NULL )
+ return wxEmptyString;
+
+ pszFound += wxStrlen(szHeader) + 2 /* ': ' */;
+
+ // Every header is separated by \n
+
+ wxChar const * pszEndLine = wxStrchr(pszFound, wxT('\n'));
+ if ( pszEndLine == NULL ) pszEndLine = pszFound + wxStrlen(pszFound);
+
+
+ // wxString( wxChar*, length);
+ wxString retVal( pszFound, pszEndLine - pszFound );
+
+ return retVal;
+}
+
+
// find catalog by name in a linked list, return NULL if !found
wxMsgCatalog *wxLocale::FindCatalog(const wxChar *szDomain) const
{
DECLARE_DYNAMIC_CLASS(wxLocaleModule)
public:
wxLocaleModule() {}
- bool OnInit() { return TRUE; }
+ bool OnInit() { return true; }
void OnExit() { wxLocale::DestroyLanguagesDB(); }
};