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:
Vadim Zeitlin 2013-02-05 20:46:26 +00:00
parent 4da0f1bb88
commit 968b44d37b

View File

@ -570,6 +570,18 @@ bool wxLocale::Init(int language, int flags)
#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()
{
CreateLanguagesDB();
@ -592,9 +604,9 @@ bool wxLocale::Init(int language, int flags)
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
langFull += str.AsString();
#else
if (!wxGetEnv(wxS("LC_ALL"), &langFull) &&
!wxGetEnv(wxS("LC_MESSAGES"), &langFull) &&
!wxGetEnv(wxS("LANG"), &langFull))
if (!wxGetNonEmptyEnvVar(wxS("LC_ALL"), &langFull) &&
!wxGetNonEmptyEnvVar(wxS("LC_MESSAGES"), &langFull) &&
!wxGetNonEmptyEnvVar(wxS("LANG"), &langFull))
{
// no language specified, treat it as English
return wxLANGUAGE_ENGLISH_US;