Ignore empty LC_XXX variables in locale detection code.
If LC_ALL or LC_MESSAGES is set but empty, ignore it and use the next environment variable. This is consistent with the standard setlocale() behaviour which only uses LC_ALL if it is set and not empty. Closes #15006. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4da0f1bb88
commit
968b44d37b
@ -570,6 +570,18 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
#endif // !WX_NO_LOCALE_SUPPORT
|
#endif // !WX_NO_LOCALE_SUPPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// Small helper function: get the value of the given environment variable and
|
||||||
|
// return true only if the variable was found and has non-empty value.
|
||||||
|
inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value)
|
||||||
|
{
|
||||||
|
return wxGetEnv(name, value) && !value->empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
/*static*/ int wxLocale::GetSystemLanguage()
|
/*static*/ int wxLocale::GetSystemLanguage()
|
||||||
{
|
{
|
||||||
CreateLanguagesDB();
|
CreateLanguagesDB();
|
||||||
@ -592,9 +604,9 @@ bool wxLocale::Init(int language, int flags)
|
|||||||
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
|
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
|
||||||
langFull += str.AsString();
|
langFull += str.AsString();
|
||||||
#else
|
#else
|
||||||
if (!wxGetEnv(wxS("LC_ALL"), &langFull) &&
|
if (!wxGetNonEmptyEnvVar(wxS("LC_ALL"), &langFull) &&
|
||||||
!wxGetEnv(wxS("LC_MESSAGES"), &langFull) &&
|
!wxGetNonEmptyEnvVar(wxS("LC_MESSAGES"), &langFull) &&
|
||||||
!wxGetEnv(wxS("LANG"), &langFull))
|
!wxGetNonEmptyEnvVar(wxS("LANG"), &langFull))
|
||||||
{
|
{
|
||||||
// no language specified, treat it as English
|
// no language specified, treat it as English
|
||||||
return wxLANGUAGE_ENGLISH_US;
|
return wxLANGUAGE_ENGLISH_US;
|
||||||
|
Loading…
Reference in New Issue
Block a user