Untangle Mac and POSIX code in wxLocale::GetSystemLanguage()

Most of the code in this function was Unix-specific and didn't make
sense for Mac, where we never have to apply the workarounds in it nor
deal with languages specified without the territory etc, so separate Mac
branch using CoreFouundation API from the rest of the Unix code to make
things more understandable.

No real changes.
This commit is contained in:
Vadim Zeitlin
2021-08-20 23:35:16 +02:00
parent 405bb3ecf7
commit d3a1abaab2

View File

@@ -634,9 +634,6 @@ inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value)
size_t i = 0,
count = ms_languagesDB->GetCount();
#if defined(__UNIX__)
// first get the string identifying the language from the environment
wxString langFull;
#ifdef __WXOSX__
wxCFRef<CFLocaleRef> userLocaleRef(CFLocaleCopyCurrent());
@@ -644,10 +641,34 @@ inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value)
// az_Cyrl_AZ@calendar=buddhist;currency=JPY we just recreate the base info as expected by wx here
wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode)));
langFull = str.AsString()+"_";
const wxString langPrefix = str.AsString() + "_";
str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
langFull += str.AsString();
#else
const wxString langFull = langPrefix + str.AsString();
int langOnlyMatchIndex = wxNOT_FOUND;
for ( i = 0; i < count; i++ )
{
const wxString& fullname = ms_languagesDB->Item(i).CanonicalName;
if ( langFull == fullname )
{
// Exact match, no need to look any further.
break;
}
if ( fullname.StartsWith(langPrefix) )
{
// Matched just the language, keep looking, but we'll keep this if
// we don't find an exact match later.
langOnlyMatchIndex = i;
}
}
if ( i == count && langOnlyMatchIndex != wxNOT_FOUND )
i = langOnlyMatchIndex;
#elif defined(__UNIX__)
// first get the string identifying the language from the environment
wxString langFull;
if (!wxGetNonEmptyEnvVar(wxS("LC_ALL"), &langFull) &&
!wxGetNonEmptyEnvVar(wxS("LC_MESSAGES"), &langFull) &&
!wxGetNonEmptyEnvVar(wxS("LANG"), &langFull))
@@ -656,8 +677,6 @@ inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value)
return wxLANGUAGE_ENGLISH_US;
}
#endif
// the language string has the following form
//
// lang[_LANG][.encoding][@modifier]