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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2024-03-10 15:37:32 -07:00
parent c7a929a8a8
commit 8f50c9c1b3

View file

@ -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);