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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-09 10:49:17 +01:00 committed by Dirk Hohndel
parent 889ca23999
commit cf990b0f39

View file

@ -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()) {