From 4c237217438076074024744e80e56fe0cb4817f8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 6 Jan 2023 03:20:57 +0100 Subject: [PATCH] Add a pseudo test to show system locale and language This can be useful to compare the results of calling wxUILocale::GetSystemLanguage() and the function with the same name in wxLocale (which actually corresponds to wxUILocale::GetSystemLocale()). --- tests/intl/intltest.cpp | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 9810199cfc..8826644021 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -430,4 +430,73 @@ TEST_CASE("wxUILocale::FromTag", "[.]") WARN("Locale \"" << tag << "\" supported: " << loc.IsSupported() ); } +namespace +{ + +const wxString GetLangName(int lang) +{ + switch ( lang ) + { + case wxLANGUAGE_DEFAULT: + return "DEFAULT"; + + case wxLANGUAGE_UNKNOWN: + return "UNKNOWN"; + + default: + return wxUILocale::GetLanguageName(lang); + } +} + +wxString GetLocaleDesc(const char* when) +{ + const wxUILocale& curloc = wxUILocale::GetCurrent(); + const wxLocaleIdent locid = curloc.GetLocaleId(); + + // Make the output slightly more readable. + wxString decsep = curloc.GetInfo(wxLOCALE_DECIMAL_POINT); + if ( decsep == "." ) + decsep = "point"; + else if ( decsep == "," ) + decsep = "comma"; + else + decsep = wxString::Format("UNKNOWN (%s)", decsep); + + return wxString::Format("%s\ncurrent locale:\t%s (decimal separator: %s)", + when, + locid.IsEmpty() ? wxString("NONE") : locid.GetTag(), + decsep); +} + +} // anonymous namespace + +// Test to show information about the system locale and the effects of various +// ways to change the current locale. +TEST_CASE("wxUILocale::ShowSystem", "[.]") +{ + WARN("System locale:\t" + << GetLangName(wxUILocale::GetSystemLocale()) << "\n" + "System language:\t" + << GetLangName(wxUILocale::GetSystemLanguage())); + + WARN(GetLocaleDesc("Before calling any locale functions")); + + wxLocale locDef; + CHECK( locDef.Init(wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT) ); + WARN(GetLocaleDesc("After wxLocale::Init(wxLANGUAGE_DEFAULT)")); + + REQUIRE( wxUILocale::UseDefault() ); + WARN(GetLocaleDesc("After wxUILocale::UseDefault()")); + + wxString preferredLangsStr; + const auto preferredLangs = wxUILocale::GetPreferredUILanguages(); + for (const auto& lang: preferredLangs) + { + if ( !preferredLangsStr.empty() ) + preferredLangsStr += ", "; + preferredLangsStr += lang; + } + WARN("Preferred UI languages:\n" << preferredLangsStr); +} + #endif // wxUSE_INTL