diff --git a/include/wx/localedefs.h b/include/wx/localedefs.h index 1f09ee7576..4656f36d5a 100644 --- a/include/wx/localedefs.h +++ b/include/wx/localedefs.h @@ -151,6 +151,9 @@ struct WXDLLIMPEXP_BASE wxLanguageInfo // supported wxString GetLocaleName() const; + // returns CanonicalRef if set, otherwise CanonicalName + wxString GetCanonicalWithRegion() const; + // Call setlocale() and return non-null value if it works for this language. // // This function is mostly for internal use, as changing locale involves diff --git a/interface/wx/intl.h b/interface/wx/intl.h index 7939c7f9ab..1fe8048392 100644 --- a/interface/wx/intl.h +++ b/interface/wx/intl.h @@ -87,6 +87,16 @@ struct wxLanguageInfo string is empty. */ wxString GetLocaleName() const; + + /** + Return the canonical locale name including the region, if known. + + The value is identical to @c CanonicalRef, if not empty, + otherwise it is identical to @c CanonicalName. + + @since 3.1.6 + */ + wxString GetCanonicalWithRegion() const; }; diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 7733b46b29..b5eeb2b36e 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -159,19 +159,24 @@ const char* wxLanguageInfo::TrySetLocale() const const char* wxLanguageInfo::TrySetLocale() const { - return wxSetlocale(LC_ALL, CanonicalRef.empty() ? CanonicalName : CanonicalRef); + return wxSetlocale(LC_ALL, GetCanonicalWithRegion()); } #endif // __WINDOWS__/!__WINDOWS__ wxString wxLanguageInfo::GetLocaleName() const { - wxString localeId = CanonicalRef.empty() ? CanonicalName : CanonicalRef; + wxString localeId = GetCanonicalWithRegion(); wxUILocale uiLocale = wxUILocale::FromTag(localeId); wxString localeName = uiLocale.IsSupported() ? uiLocale.GetName() : wxString(); return localeName; } +wxString wxLanguageInfo::GetCanonicalWithRegion() const +{ + return CanonicalRef.empty() ? CanonicalName : CanonicalRef; +} + // ---------------------------------------------------------------------------- // wxUILocale // ---------------------------------------------------------------------------- @@ -430,7 +435,7 @@ bool wxLocale::Init(int lang, int flags) else { name = info->Description; - shortName = info->CanonicalRef.empty() ? info->CanonicalName : info->CanonicalRef; + shortName = info->GetCanonicalWithRegion(); } DoInit(name, shortName, lang); @@ -738,7 +743,7 @@ bool wxLocale::IsAvailable(int lang) return false; } - wxString localeTag = info->CanonicalRef.empty() ? info->LocaleTag : info->CanonicalRef; + wxString localeTag = info->GetCanonicalWithRegion(); wxUILocale uiLocale(wxLocaleIdent::FromTag(localeTag)); return uiLocale.IsSupported(); diff --git a/src/unix/uilocale.cpp b/src/unix/uilocale.cpp index e0b9f18ff2..b06af8d752 100644 --- a/src/unix/uilocale.cpp +++ b/src/unix/uilocale.cpp @@ -157,7 +157,7 @@ locale_t TryCreateMatchingLocale(wxLocaleIdent& locId) it != infos.end(); ++it ) { - const wxString& fullname = it->CanonicalRef.empty() ? it->CanonicalName : it->CanonicalRef; + const wxString& fullname = it->GetCanonicalWithRegion(); if ( fullname.BeforeFirst('_') == lang ) { // We never have encoding in our canonical names, but we