X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0e32fdb872d413f14da8ce045766f0e2f13e202d..5541d1fda4b73af86e42b2f43724f0c063a352d0:/src/common/intl.cpp diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 5e03cbdc18..d84627fc7a 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -60,6 +60,10 @@ #include "wx/fontmap.h" // for CharsetToEncoding() #endif +#if defined(__WXMAC__) + #include "wx/mac/private.h" // includes mac headers +#endif + // ---------------------------------------------------------------------------- // simple types // ---------------------------------------------------------------------------- @@ -84,20 +88,9 @@ typedef unsigned char size_t8; typedef unsigned long size_t32; #else // assume sizeof(int) == 4 - what else can we do - typedef unsigned int size_t32; + wxCOMPILE_TIME_ASSERT( sizeof(int) == 4, IntMustBeExactly4Bytes); - // ... but at least check it during run time - static class IntSizeChecker - { - public: - IntSizeChecker() - { - // Asserting a sizeof directly causes some compilers to - // issue a "using constant in a conditional expression" warning - wxASSERT_MSG( wxAssertIsEqual(sizeof(int), 4), - "size_t32 is incorrectly defined!" ); - } - } intsizechecker; + typedef unsigned int size_t32; #endif #endif // Win/!Win @@ -615,7 +608,12 @@ bool wxLocale::Init(const wxChar *szName, if ( m_strShort.IsEmpty() ) { // FIXME I don't know how these 2 letter abbreviations are formed, // this wild guess is surely wrong - m_strShort = tolower(szLocale[0]) + tolower(szLocale[1]); + if ( szLocale[0] ) + { + m_strShort += (wxChar)wxTolower(szLocale[0]); + if ( szLocale[1] ) + m_strShort += (wxChar)wxTolower(szLocale[1]); + } } // save the old locale to be able to restore it later @@ -796,7 +794,7 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) return wxLANGUAGE_ENGLISH; } - if ( langFull == _T("C") ) + if ( langFull == _T("C") || langFull == _T("POSIX") ) { // default C locale return wxLANGUAGE_ENGLISH; @@ -804,18 +802,31 @@ void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) // the language string has the following form // - // lang[_LANG[.encoding]] + // lang[_LANG][.encoding][@modifier] + // + // (see environ(5) in the Open Unix specification) // - // where lang is the primary language, LANG is a sublang + // where lang is the primary language, LANG is a sublang/territory, + // encoding is the charset to use and modifier "allows the user to select + // a specific instance of localization data within a single category" // // for example, the following strings are valid: // fr // fr_FR // de_DE.iso88591 + // de_DE@euro + // de_DE.iso88591@euro // for now we don't use the encoding, although we probably should (doing // translations of the msg catalogs on the fly as required) (TODO) - langFull = langFull.BeforeFirst(_T('.')); + // + // we don't use the modifiers neither but we probably should translate + // "euro" into iso885915 + size_t posEndLang = langFull.find_first_of(_T("@.")); + if ( posEndLang != wxString::npos ) + { + langFull.Truncate(posEndLang); + } // in addition to the format above, we also can have full language names // in LANG env var - for example, SuSE is known to use LANG="german" - so @@ -1222,7 +1233,7 @@ wxString wxLocale::GetSystemEncodingName() { wxString encname; -#ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__WXMICROWIN__) // FIXME: what is the error return value for GetACP()? UINT codepage = ::GetACP(); encname.Printf(_T("windows-%u"), codepage); @@ -1238,7 +1249,19 @@ wxString wxLocale::GetSystemEncodingName() free(oldLocale); if (alang) { - encname = wxConvLibc.cMB2WX(alang); +#ifdef __SOLARIS__ + // nl_langinfo() under Solaris returns 646 by default which stands for + // ISO-646, i.e. 7 bit ASCII and we should recognize it to avoid + // warnings about unrecognized encoding on each program startup + if ( strcmp(alang, "646") == 0 ) + { + encname = _T("US-ASCII"); + } + else +#endif // __SOLARIS__ + { + encname = wxConvLibc.cMB2WX(alang); + } } else #endif // HAVE_LANGINFO_H @@ -1274,20 +1297,52 @@ wxString wxLocale::GetSystemEncodingName() /* static */ wxFontEncoding wxLocale::GetSystemEncoding() { -#ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__WXMICROWIN__) UINT codepage = ::GetACP(); - // wxWindows only knows about CP1250-1257 + // wxWindows only knows about CP1250-1257, 932, 936, 949, 950 if ( codepage >= 1250 && codepage <= 1257 ) { return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); } + + if ( codepage == 932 ) + { + return wxFONTENCODING_CP932; + } + + if ( codepage == 936 ) + { + return wxFONTENCODING_CP936; + } + + if ( codepage == 949 ) + { + return wxFONTENCODING_CP949; + } + + if ( codepage == 950 ) + { + return wxFONTENCODING_CP950; + } #elif defined(__UNIX_LIKE__) && wxUSE_FONTMAP wxString encname = GetSystemEncodingName(); if ( !encname.empty() ) { - return wxTheFontMapper-> + wxFontEncoding enc = wxTheFontMapper-> CharsetToEncoding(encname, FALSE /* not interactive */); + + // this should probably be considered as a bug in CharsetToEncoding(): + // it shouldn't return wxFONTENCODING_DEFAULT at all - but it does it + // for US-ASCII charset + // + // we, OTOH, definitely shouldn't return it as it doesn't make sense at + // all (which encoding is it?) + if ( enc != wxFONTENCODING_DEFAULT ) + { + return enc; + } + //else: return wxFONTENCODING_SYSTEM below } #endif // Win32/Unix @@ -1326,7 +1381,7 @@ const wxMB2WXbuf wxLocale::GetString(const wxChar *szOrigString, const wxChar *szDomain) const { if ( wxIsEmpty(szOrigString) ) - return szDomain; + return _T(""); const char *pszTrans = NULL; #if wxUSE_UNICODE @@ -1372,12 +1427,13 @@ const wxMB2WXbuf wxLocale::GetString(const wxChar *szOrigString, return (wxMB2WXbuf)(szOrigString); } - else - { - return wxConvertMB2WX(pszTrans); // or preferably wxCSConv(charset).cMB2WX(pszTrans) or something, - // a macro similar to wxConvertMB2WX could be written for that - } + // or preferably wxCSConv(charset).cMB2WX(pszTrans) or something, a macro + // similar to wxConvertMB2WX could be written for that + + return wxConvertMB2WX(pszTrans); + + // undo the hack from the beginning of this function #undef szOrgString } @@ -1421,6 +1477,62 @@ bool wxLocale::AddCatalog(const wxChar *szDomain) } } +// ---------------------------------------------------------------------------- +// accessors for locale-dependent data +// ---------------------------------------------------------------------------- + +#if 0 + +#ifdef __WXMSW__ + +/* static */ +wxString wxLocale::GetInfo(wxLocaleInfo index) +{ + wxString str; + wxChar buffer[256]; + size_t count; + buffer[0] = wxT('\0'); + switch (index) + { + case wxSYS_DECIMAL_SEPARATOR: + count = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, buffer, 256); + if (!count) + str << "."; + else + str << buffer; + break; + case wxSYS_LIST_SEPARATOR: + count = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLIST, buffer, 256); + if (!count) + str << ","; + else + str << buffer; + break; + case wxSYS_LEADING_ZERO: // 0 means no leading zero, 1 means leading zero + count = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, buffer, 256); + if (!count) + str << "0"; + else + str << buffer; + break; + default: + wxFAIL_MSG("Unknown System String !"); + } + return str; +} + +#else // !__WXMSW__ + +/* static */ +wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory) +{ + return wxEmptyString; +} + +#endif // __WXMSW__/!__WXMSW__ + +#endif // 0 + // ---------------------------------------------------------------------------- // global functions and variables // ----------------------------------------------------------------------------