Allow creating wxUILocale objects for any locale

Creating such objects (without using them for the UI) is supported under
all platforms, so allow doing it.

Note that this is only supported under Unix systems when locale_t and
related functionality is available, but this should be the case just
about everywhere by now.

Add a test (or, rather, replace an existing test which was disabled by
default) checking that we can now get locale information about any
locale, not necessarily the currently used one.
This commit is contained in:
Vadim Zeitlin
2021-08-29 14:50:54 +02:00
parent 07e79b7736
commit 45f9908e05
8 changed files with 193 additions and 38 deletions

View File

@@ -240,17 +240,17 @@ TEST_CASE("wxLocale::Default", "[locale]")
#endif // wxUSE_UNICODE
// This test doesn't run by default as it only works in locales using decimal
// point as separator, which doesn't need to be the case.
TEST_CASE("wxUILocale::GetInfo", "[.][uilocale]")
TEST_CASE("wxUILocale::GetInfo", "[uilocale]")
{
REQUIRE( wxUILocale::UseDefault() );
CHECK( wxUILocale("en").GetInfo(wxLOCALE_DECIMAL_POINT) == "." );
CHECK( wxUILocale("de").GetInfo(wxLOCALE_DECIMAL_POINT) == "," );
CHECK( wxUILocale("ru").GetInfo(wxLOCALE_DECIMAL_POINT) == "," );
const wxUILocale& loc = wxUILocale::GetCurrent();
WARN( "Using locale " << loc.GetName() );
CHECK( loc.GetInfo(wxLOCALE_DECIMAL_POINT) == "." );
// This one shows that "Swiss High German" locale (de_CH) correctly uses
// dot, and not comma, as decimal separator, even under macOS, where POSIX
// APIs use incorrect (identical to "German") definitions for this locale.
CHECK( wxUILocale(wxLocaleIdent("de").Region("CH")).
GetInfo(wxLOCALE_DECIMAL_POINT) == "." );
}
// Just a small helper to make the test below shorter.