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
#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()
{
CreateLanguagesDB();
/*static*/ int wxLocale::GetSystemLanguage()
{
CreateLanguagesDB();
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
langFull += str.AsString();
#else
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;
{
// no language specified, treat it as English
return wxLANGUAGE_ENGLISH_US;