Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool Application::configVersionMigration()
AccountManager::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
FolderMan::backwardMigrationSettingsKeys(&deleteKeys, &ignoreKeys);
configFile.setClientPreviousVersionString(configFile.clientVersionString());

qCDebug(lcApplication) << "Migration is in progress:" << configFile.isMigrationInProgress();
const auto versionChanged = configFile.isUpgrade() || configFile.isDowngrade();
if (versionChanged) {
Expand Down Expand Up @@ -992,23 +992,6 @@ void Application::handleEditLocallyFromOptions()
_editFileLocallyUrl.clear();
}

QString substLang(const QString &lang)
{
// Map the more appropriate script codes
// to country codes as used by Qt and
// transifex translation conventions.

// Simplified Chinese
if (lang == QLatin1String("zh_Hans")) {
return QLatin1String("zh_CN");
}
// Traditional Chinese
if (lang == QLatin1String("zh_Hant")) {
return QLatin1String("zh_TW");
}
return lang;
}

QString enforcedLanguage()
{
const ConfigFile cfg;
Expand All @@ -1023,11 +1006,6 @@ QString enforcedLanguage()

void Application::setupTranslations()
{
qCInfo(lcApplication) << "System UI languages are:" << QLocale::system().uiLanguages();
const auto enforcedLocale = enforcedLanguage();
const auto lang = substLang(!enforcedLocale.isEmpty() ? enforcedLocale : QLocale::system().uiLanguages(QLocale::TagSeparator::Underscore).first());
qCInfo(lcApplication) << "selected application language:" << lang;

auto *translator = new QTranslator(this);
auto *qtTranslator = new QTranslator(this);
auto *qtkeychainTranslator = new QTranslator(this);
Expand All @@ -1038,9 +1016,28 @@ void Application::setupTranslations()
qCWarning(lcApplication()) << trPath << "folder containing translations is missing. Impossible to load translations";
return;
}
const QString trFile = QLatin1String("client_") + lang;
qCDebug(lcApplication()) << "trying to load" << lang << "in" << trFile << "from" << trPath;
if (translator->load(trFile, trPath) || lang.startsWith(QLatin1String("en"))) {

qCInfo(lcApplication) << "System UI languages are:" << QLocale::system().uiLanguages();
const QString enforcedLocale = enforcedLanguage();
QString lang;
if (enforcedLocale.isEmpty()) {
for(const QString &l : QLocale::system().uiLanguages(QLocale::TagSeparator::Underscore)){
const QString trFile = QLatin1String("client_") + l;
qCDebug(lcApplication()) << "trying to load" << l << "in" << trFile << "from" << trPath;
if (translator->load(trFile, trPath)) {
lang = l;
break;
}
}
} else {
lang = enforcedLocale;
const QString trFile = QLatin1String("client_") + lang;
qCDebug(lcApplication()) << "trying to load" << lang << "in" << trFile << "from" << trPath;
translator->load(trFile, trPath);
}

qCInfo(lcApplication) << "selected application language:" << lang;
if (!translator->isEmpty() || lang.startsWith(QLatin1String("en"))) {
// Permissive approach: Qt and keychain translations
// may be missing, but Qt translations must be there in order
// for us to accept the language. Otherwise, we try with the next.
Expand Down