From 29678874201cfa47b195438bfe9cc0adae728218 Mon Sep 17 00:00:00 2001 From: Ulrich Telle Date: Thu, 18 Aug 2022 14:52:17 +0200 Subject: [PATCH 1/3] Fix script parsing in wxLocaleIdent The script part of a locale tag was incorrectly parsed due to a wrong index in the calls to `wxString::Mid`. This resulted in shortened script tags that couldn't be interpreted anymore. --- src/common/uilocale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/uilocale.cpp b/src/common/uilocale.cpp index 7a29dc2ca8..bfcae131ea 100644 --- a/src/common/uilocale.cpp +++ b/src/common/uilocale.cpp @@ -215,7 +215,7 @@ wxLocaleIdent wxLocaleIdent::FromTag(const wxString& tag) case 4: // Must be an ISO 15924 script. - locId.m_script = (*it).Left(1).Upper() + (*it).Mid(2).Lower(); + locId.m_script = (*it).Left(1).Upper() + (*it).Mid(1).Lower(); break; default: @@ -299,7 +299,7 @@ wxLocaleIdent& wxLocaleIdent::Script(const wxString& script) script.find_first_not_of(validCharsAlpha) == wxString::npos) { // Capitalize first character - m_script = script.Left(1).Upper() + script.Mid(2).Lower(); + m_script = script.Left(1).Upper() + script.Mid(1).Lower(); } else if (!script.empty()) { From 95619e95f284feaa3d25a9a1b579f1f369ebee35 Mon Sep 17 00:00:00 2001 From: Ulrich Telle Date: Thu, 18 Aug 2022 18:56:51 +0200 Subject: [PATCH 2/3] Simplify code to capitalize script part of a tag --- src/common/uilocale.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/uilocale.cpp b/src/common/uilocale.cpp index bfcae131ea..01d2e2ece3 100644 --- a/src/common/uilocale.cpp +++ b/src/common/uilocale.cpp @@ -215,7 +215,7 @@ wxLocaleIdent wxLocaleIdent::FromTag(const wxString& tag) case 4: // Must be an ISO 15924 script. - locId.m_script = (*it).Left(1).Upper() + (*it).Mid(1).Lower(); + locId.m_script = it->Capitalize(); break; default: @@ -299,7 +299,7 @@ wxLocaleIdent& wxLocaleIdent::Script(const wxString& script) script.find_first_not_of(validCharsAlpha) == wxString::npos) { // Capitalize first character - m_script = script.Left(1).Upper() + script.Mid(1).Lower(); + m_script = script.Capitalize(); } else if (!script.empty()) { From 34e9c2d53e79853a04d5bd9e2d983875d43f8d89 Mon Sep 17 00:00:00 2001 From: Ulrich Telle Date: Thu, 18 Aug 2022 19:16:54 +0200 Subject: [PATCH 3/3] Add test case for locale tag with script part This test checks that a locale tag that includes an explicit script part (like `sr-Latn-RS`) is correctly parsed and located in the internal language database. --- tests/intl/intltest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 956f729a96..ccc12176cf 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -415,6 +415,8 @@ TEST_CASE("wxUILocale::FindLanguageInfo", "[uilocale]") CheckFindLanguage("English", "en"); CheckFindLanguage("English_United States", "en_US"); CheckFindLanguage("English_United States.utf8", "en_US"); + // Test tag that includes an explicit script + CheckFindLanguage("sr-Latn-RS", "sr_RS@latin"); } // Test which can be used to check if the given locale tag is supported.