@@ -132,7 +132,7 @@ bool Application::configVersionMigration()
132132 AccountManager::backwardMigrationSettingsKeys (&deleteKeys, &ignoreKeys);
133133 FolderMan::backwardMigrationSettingsKeys (&deleteKeys, &ignoreKeys);
134134 configFile.setClientPreviousVersionString (configFile.clientVersionString ());
135-
135+
136136 qCDebug (lcApplication) << " Migration is in progress:" << configFile.isMigrationInProgress ();
137137 const auto versionChanged = configFile.isUpgrade () || configFile.isDowngrade ();
138138 if (versionChanged) {
@@ -992,23 +992,6 @@ void Application::handleEditLocallyFromOptions()
992992 _editFileLocallyUrl.clear ();
993993}
994994
995- QString substLang (const QString &lang)
996- {
997- // Map the more appropriate script codes
998- // to country codes as used by Qt and
999- // transifex translation conventions.
1000-
1001- // Simplified Chinese
1002- if (lang == QLatin1String (" zh_Hans" )) {
1003- return QLatin1String (" zh_CN" );
1004- }
1005- // Traditional Chinese
1006- if (lang == QLatin1String (" zh_Hant" )) {
1007- return QLatin1String (" zh_TW" );
1008- }
1009- return lang;
1010- }
1011-
1012995QString enforcedLanguage ()
1013996{
1014997 const ConfigFile cfg;
@@ -1023,11 +1006,6 @@ QString enforcedLanguage()
10231006
10241007void Application::setupTranslations ()
10251008{
1026- qCInfo (lcApplication) << " System UI languages are:" << QLocale::system ().uiLanguages ();
1027- const auto enforcedLocale = enforcedLanguage ();
1028- const auto lang = substLang (!enforcedLocale.isEmpty () ? enforcedLocale : QLocale::system ().uiLanguages (QLocale::TagSeparator::Underscore).first ());
1029- qCInfo (lcApplication) << " selected application language:" << lang;
1030-
10311009 auto *translator = new QTranslator (this );
10321010 auto *qtTranslator = new QTranslator (this );
10331011 auto *qtkeychainTranslator = new QTranslator (this );
@@ -1038,9 +1016,28 @@ void Application::setupTranslations()
10381016 qCWarning (lcApplication ()) << trPath << " folder containing translations is missing. Impossible to load translations" ;
10391017 return ;
10401018 }
1041- const QString trFile = QLatin1String (" client_" ) + lang;
1042- qCDebug (lcApplication ()) << " trying to load" << lang << " in" << trFile << " from" << trPath;
1043- if (translator->load (trFile, trPath) || lang.startsWith (QLatin1String (" en" ))) {
1019+
1020+ qCInfo (lcApplication) << " System UI languages are:" << QLocale::system ().uiLanguages ();
1021+ const QString enforcedLocale = enforcedLanguage ();
1022+ QString lang;
1023+ if (enforcedLocale.isEmpty ()) {
1024+ for (const QString &l : QLocale::system ().uiLanguages (QLocale::TagSeparator::Underscore)){
1025+ const QString trFile = QLatin1String (" client_" ) + l;
1026+ qCDebug (lcApplication ()) << " trying to load" << l << " in" << trFile << " from" << trPath;
1027+ if (translator->load (trFile, trPath)) {
1028+ lang = l;
1029+ break ;
1030+ }
1031+ }
1032+ } else {
1033+ lang = enforcedLocale;
1034+ const QString trFile = QLatin1String (" client_" ) + lang;
1035+ qCDebug (lcApplication ()) << " trying to load" << lang << " in" << trFile << " from" << trPath;
1036+ translator->load (trFile, trPath);
1037+ }
1038+
1039+ qCInfo (lcApplication) << " selected application language:" << lang;
1040+ if (!translator->isEmpty () || lang.startsWith (QLatin1String (" en" ))) {
10441041 // Permissive approach: Qt and keychain translations
10451042 // may be missing, but Qt translations must be there in order
10461043 // for us to accept the language. Otherwise, we try with the next.
0 commit comments