From 8f50c9c1b343c31c3c797b5eba5512ca85f35150 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 10 Mar 2024 15:37:32 -0700 Subject: [PATCH] Improve automated language handling This mimics the code added in commit cf990b0f39 ("preferences: choose language code with one '-'") and adds some debugging for the mobile case - some people are being presented with Subsurface-mobile in Korean for some reason. Signed-off-by: Dirk Hohndel --- core/qthelper.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 7ef8a95c6..3eefd196f 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -466,18 +466,22 @@ void initUiLanguage() auto it = std::find_if(languages.begin(), languages.end(), [](const QString &s) { return s.count('-') == 1; }); uiLang = it == languages.end() ? languages[0] : *it; +#ifdef SUBSURFACE_MOBILE + qDebug() << "uiLanguages was" << languages << ", picked" << uiLang; +#endif // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; QStringList languages = loc2.uiLanguages(); - if (languages[0].contains('-')) - uiLang = languages[0]; - else if (languages.count() > 1 && languages[1].contains('-')) - uiLang = languages[1]; - else if (languages.count() > 2 && languages[2].contains('-')) - uiLang = languages[2]; + + it = std::find_if(languages.begin(), languages.end(), [](const QString &s) + { return s.contains('-'); }); + uiLang = it == languages.end() ? languages[0] : *it; +#ifdef SUBSURFACE_MOBILE + qDebug() << "bcp47 based languages was" << languages << ", picked" << uiLang; +#endif } free((void*)prefs.locale.lang_locale);