From cf990b0f39cc3d61a33a7f03a5add89737f831f1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 9 Mar 2024 10:49:17 +0100 Subject: [PATCH] preferences: choose language code with one '-' On initialization, the old code searched for the first language code containing a '-'. However, my Qt version gives de-Latn-DE as the first entry. That messed up the preferences code: it didn't recognize that entry. Thus, simply opening and closing the preferences switched the language to Bulgarian. Signed-off-by: Berthold Stoeger --- core/qthelper.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 4e427556f..7ef8a95c6 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -460,16 +460,12 @@ void initUiLanguage() loc = QLocale(QLocale().uiLanguages().first()); } + // Find language code with one '-', or use the first entry. QStringList languages = loc.uiLanguages(); QString uiLang; - 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]; - else - uiLang = languages[0]; + auto it = std::find_if(languages.begin(), languages.end(), [](const QString &s) + { return s.count('-') == 1; }); + uiLang = it == languages.end() ? languages[0] : *it; // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) {