From c87152f21e1a13ec78d02e178e7926363bdb5b65 Mon Sep 17 00:00:00 2001 From: MCleinman <9295855+mcleinman@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:21:13 -0700 Subject: [PATCH] VPN-6622: Fix broken device language for Chinese (#9933) (#9968) * VPN-6622 fix for iOS * make it generalizable to help with Android * make it generalizable to help with Android * better iOS explanation * make linter happy * update tests, improve logic for non-iOS --- src/localizer.cpp | 49 +++++++++++++++++++++++++++--- tests/unit_tests/testlocalizer.cpp | 8 ++--- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/localizer.cpp b/src/localizer.cpp index 69fc73093d..935c00eeaa 100644 --- a/src/localizer.cpp +++ b/src/localizer.cpp @@ -77,6 +77,14 @@ QList> Localizer::parseBCP47Languages( continue; } + // Chinese is often reported as `zh-Hant-HK`, and we want the middle + // section. + QString script = parts[1]; + if (script == "Hans" || script == "Hant") { + codes.append(QPair{parts[0], script}); + continue; + } + QString country = parts.last(); if (country.length() == 2) { codes.append(QPair{parts[0], country}); @@ -96,11 +104,23 @@ QList> Localizer::parseIOSLanguages( QList> codes; for (const QString& language : languages) { - // By documentation, the language code should be in the format - // -