simplify SETLOCALE_FAILS_ON_UNICODE_LANGS-related code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51671 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1016,6 +1016,25 @@ static wxArrayString gs_searchPrefixes;
|
|||||||
// wxLanguageInfo
|
// wxLanguageInfo
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// helper used by wxLanguageInfo::GetLocaleName() and elsewhere to determine
|
||||||
|
// whether the locale is Unicode-only (it is if this function returns empty
|
||||||
|
// string)
|
||||||
|
static wxString wxGetANSICodePageForLocale(LCID lcid)
|
||||||
|
{
|
||||||
|
wxString cp;
|
||||||
|
|
||||||
|
wxChar buffer[16];
|
||||||
|
if ( ::GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
||||||
|
buffer, WXSIZEOF(buffer)) > 0 )
|
||||||
|
{
|
||||||
|
if ( buffer[0] != _T('0') || buffer[1] != _T('\0') )
|
||||||
|
cp = buffer;
|
||||||
|
//else: this locale doesn't use ANSI code page
|
||||||
|
}
|
||||||
|
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
|
|
||||||
wxUint32 wxLanguageInfo::GetLCID() const
|
wxUint32 wxLanguageInfo::GetLCID() const
|
||||||
@@ -1044,12 +1063,10 @@ wxString wxLanguageInfo::GetLocaleName() const
|
|||||||
locale << _T('_') << buffer;
|
locale << _T('_') << buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ::GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE,
|
const wxString cp = wxGetANSICodePageForLocale(lcid);
|
||||||
buffer, WXSIZEOF(buffer)) > 0 )
|
if ( !cp.empty() )
|
||||||
{
|
{
|
||||||
if ( buffer[0] != _T('0') || buffer[1] != _T('\0') )
|
locale << _T('.') << cp;
|
||||||
locale << _T('.') << buffer;
|
|
||||||
//else: this locale doesn't use ANSI code page
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return locale;
|
return locale;
|
||||||
@@ -1815,17 +1832,6 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
#endif // __AIX__
|
#endif // __AIX__
|
||||||
|
|
||||||
#elif defined(__WIN32__)
|
#elif defined(__WIN32__)
|
||||||
|
|
||||||
#if wxUSE_UNICODE && (defined(__VISUALC__) || defined(__MINGW32__))
|
|
||||||
// NB: setlocale() from msvcrt.dll (used by VC++ and Mingw)
|
|
||||||
// can't set locale to language that can only be written using
|
|
||||||
// Unicode. Therefore wxSetlocale call failed, but we don't want
|
|
||||||
// to report it as an error -- so that at least message catalogs
|
|
||||||
// can be used. Watch for code marked with
|
|
||||||
// #ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS below.
|
|
||||||
#define SETLOCALE_FAILS_ON_UNICODE_LANGS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char *retloc = "C";
|
const char *retloc = "C";
|
||||||
if ( language != wxLANGUAGE_DEFAULT )
|
if ( language != wxLANGUAGE_DEFAULT )
|
||||||
{
|
{
|
||||||
@@ -1834,7 +1840,7 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
wxLogWarning(wxS("Locale '%s' not supported by OS."), name.c_str());
|
wxLogWarning(wxS("Locale '%s' not supported by OS."), name.c_str());
|
||||||
// retloc already set to "C"
|
// retloc already set to "C"
|
||||||
}
|
}
|
||||||
else
|
else // language supported by Windows
|
||||||
{
|
{
|
||||||
const wxUint32 lcid = info->GetLCID();
|
const wxUint32 lcid = info->GetLCID();
|
||||||
|
|
||||||
@@ -1854,40 +1860,29 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
else // have a valid locale
|
else // have a valid locale
|
||||||
{
|
{
|
||||||
retloc = wxSetlocale(LC_ALL, locale);
|
retloc = wxSetlocale(LC_ALL, locale);
|
||||||
|
|
||||||
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
|
|
||||||
if ( !retloc )
|
|
||||||
{
|
|
||||||
// GetLocaleName() returns a string without period only if
|
|
||||||
// there is no associated ANSI code page
|
|
||||||
if ( locale.find(_T('.')) == wxString::npos )
|
|
||||||
{
|
|
||||||
retloc = "C";
|
|
||||||
}
|
|
||||||
//else: locale has code page information and hence this is
|
|
||||||
// a real error
|
|
||||||
}
|
|
||||||
#endif // SETLOCALE_FAILS_ON_UNICODE_LANGS
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // language == wxLANGUAGE_DEFAULT
|
||||||
{
|
{
|
||||||
retloc = wxSetlocale(LC_ALL, wxEmptyString);
|
retloc = wxSetlocale(LC_ALL, wxEmptyString);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
|
#if wxUSE_UNICODE && (defined(__VISUALC__) || defined(__MINGW32__))
|
||||||
if (retloc == NULL)
|
// VC++ setlocale() (also used by Mingw) can't set locale to languages that
|
||||||
|
// can only be written using Unicode, therefore wxSetlocale() call fails
|
||||||
|
// for such languages but we don't want to report it as an error -- so that
|
||||||
|
// at least message catalogs can be used.
|
||||||
|
if ( !retloc )
|
||||||
{
|
{
|
||||||
wxChar buffer[16];
|
if ( wxGetANSICodePageForLocale(LOCALE_USER_DEFAULT).empty() )
|
||||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT,
|
|
||||||
LOCALE_IDEFAULTANSICODEPAGE, buffer, 16) > 0 &&
|
|
||||||
wxStrcmp(buffer, wxS("0")) == 0)
|
|
||||||
{
|
{
|
||||||
|
// we set the locale to a Unicode-only language, don't treat the
|
||||||
|
// inability of CRT to use it as an error
|
||||||
retloc = "C";
|
retloc = "C";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // SETLOCALE_FAILS_ON_UNICODE_LANGS
|
#endif // CRT not handling Unicode-only languages
|
||||||
}
|
|
||||||
|
|
||||||
if ( !retloc )
|
if ( !retloc )
|
||||||
ret = false;
|
ret = false;
|
||||||
|
Reference in New Issue
Block a user