From 2c580c9190e30391c0e69c0cf1534d9b6d1e1860 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 5 Sep 2021 00:59:28 +0200 Subject: [PATCH] Add wxUILocale::FromTag() helper This is exactly the same as wxUILocale(wxLocaleIdent::FromTag()) but shorter. --- include/wx/uilocale.h | 6 ++++++ interface/wx/uilocale.h | 12 ++++++++++++ tests/intl/intltest.cpp | 12 ++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/wx/uilocale.h b/include/wx/uilocale.h index e95d50afa1..4a379c59fa 100644 --- a/include/wx/uilocale.h +++ b/include/wx/uilocale.h @@ -106,6 +106,12 @@ public: // Get the object corresponding to the currently used locale. static const wxUILocale& GetCurrent(); + // A helper just to avoid writing wxUILocale(wxLocaleIdent::FromTag(...)). + static wxUILocale FromTag(const wxString& tag) + { + return wxUILocale(wxLocaleIdent::FromTag(tag)); + } + // Create the object corresponding to the given locale. explicit wxUILocale(const wxLocaleIdent& localeId); diff --git a/interface/wx/uilocale.h b/interface/wx/uilocale.h index c6cd0f7a52..96516ba062 100644 --- a/interface/wx/uilocale.h +++ b/interface/wx/uilocale.h @@ -99,6 +99,18 @@ public: */ static const wxUILocale& GetCurrent(); + /** + Creates the local corresponding to the given language tag. + + This is exactly equivalent to using wxUILocale constructor with + the locale identifier returned by wxLocaleIdent::FromTag(), but + shorter. + + See wxLocaleIdent::FromTag() for more information about the syntax of + the @a tag string. + */ + static wxUILocale FromTag(const wxString& tag); + /** Creates the locale corresponding to the given locale identifier. diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index e4b7131b2c..1fe64c5623 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -260,16 +260,16 @@ static inline bool CheckSupported(const wxUILocale& loc, const char* desc) TEST_CASE("wxUILocale::IsSupported", "[uilocale]") { - CheckSupported(wxUILocale(wxLocaleIdent::FromTag("en")), "English"); + CheckSupported(wxUILocale::FromTag("en"), "English"); CheckSupported(wxUILocale(wxLocaleIdent().Language("fr").Region("FR")), "French"); - CHECK( !wxUILocale(wxLocaleIdent::FromTag("bloordyblop")).IsSupported() ); + CHECK( !wxUILocale::FromTag("bloordyblop").IsSupported() ); } TEST_CASE("wxUILocale::GetInfo", "[uilocale]") { - CHECK( wxUILocale(wxLocaleIdent::FromTag("en")).GetInfo(wxLOCALE_DECIMAL_POINT) == "." ); + CHECK( wxUILocale::FromTag("en").GetInfo(wxLOCALE_DECIMAL_POINT) == "." ); - const wxUILocale locDE(wxLocaleIdent::FromTag("de")); + const wxUILocale locDE(wxUILocale::FromTag("de")); if ( CheckSupported(locDE, "German") ) CHECK( locDE.GetInfo(wxLOCALE_DECIMAL_POINT) == "," ); @@ -288,7 +288,7 @@ TEST_CASE("wxUILocale::CompareStrings", "[uilocale]") { SECTION("English") { - const wxUILocale l(wxLocaleIdent::FromTag("en")); + const wxUILocale l(wxUILocale::FromTag("en")); // This is not very interesting, but check that comparison works at all. CHECK( l.CompareStrings("x", "x") == 0 ); @@ -344,7 +344,7 @@ TEST_CASE("wxUILocale::CompareStrings", "[uilocale]") if ( wxIsRunningUnderWine() ) return; - const wxUILocale l(wxLocaleIdent::FromTag("sv")); + const wxUILocale l(wxUILocale::FromTag("sv")); if ( !CheckSupported(l, "Swedish") ) return;