diff options
author | Katja Marttila <katja.marttila@qt.io> | 2021-06-15 13:43:45 +0300 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2021-06-17 09:41:25 +0300 |
commit | 081613fe8a5fa8dc419d3bf6205f9f0ca303c8da (patch) | |
tree | 975c4189755670af349f937669c37d4f5c0b8f10 | |
parent | bd10266110689199ad86d9d314b342f836c5cade (diff) |
Load and install translations as early as possible
This will ensure that any early error messages are translated if
there are any translations for them. Such as the already running
instance string. As a result this means that a check if the
installer is already running is done slightly later to allow the
loading of the translations first before checking.
Fixes: QTIFW-1888
Change-Id: I75ef22d98ca4de9a05e7dd485b5afed5652529bc
Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r-- | src/sdk/installerbase.cpp | 47 | ||||
-rw-r--r-- | src/sdk/sdkapp.h | 68 |
2 files changed, 59 insertions, 56 deletions
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp index 78da6fb3a..32df0b550 100644 --- a/src/sdk/installerbase.cpp +++ b/src/sdk/installerbase.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -40,7 +40,6 @@ #include <QDir> #include <QDirIterator> #include <QFontDatabase> -#include <QTranslator> #ifdef ENABLE_SQUISH #include <qtbuiltinhook.h> @@ -74,49 +73,7 @@ int InstallerBase::run() qCDebug(QInstaller::lcInstallerInstallLog) << "Language:" << QLocale().uiLanguages() .value(0, QLatin1String("No UI language set")).toUtf8().constData(); -#ifndef IFW_DISABLE_TRANSLATIONS - const QString directory = QLatin1String(":/translations"); - // Check if there is a modified translation first to enable people - // to easily provide corrected translations to Qt/IFW for their installers - const QString newDirectory = QLatin1String(":/translations_new"); - const QStringList translations = m_core->settings().translations(); - - if (translations.isEmpty()) { - foreach (const QLocale locale, QLocale().uiLanguages()) { - QScopedPointer<QTranslator> qtTranslator(new QTranslator(QCoreApplication::instance())); - bool qtLoaded = qtTranslator->load(locale, QLatin1String("qt"), - QLatin1String("_"), newDirectory); - if (!qtLoaded) - qtLoaded = qtTranslator->load(locale, QLatin1String("qt"), - QLatin1String("_"), directory); - - if (qtLoaded || locale.language() == QLocale::English) { - if (qtLoaded) - QCoreApplication::instance()->installTranslator(qtTranslator.take()); - - QScopedPointer<QTranslator> ifwTranslator(new QTranslator(QCoreApplication::instance())); - bool ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), newDirectory); - if (!ifwLoaded) - ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), directory); - if (ifwLoaded) - QCoreApplication::instance()->installTranslator(ifwTranslator.take()); - - // To stop loading other translations it's sufficient that - // qt was loaded successfully or we hit English as system language - emit m_core->defaultTranslationsLoadedForLanguage(locale.language()); - break; - } - } - } else { - foreach (const QString &translation, translations) { - QScopedPointer<QTranslator> translator(new QTranslator(QCoreApplication::instance())); - if (translator->load(translation, QLatin1String(":/translations"))) - QCoreApplication::instance()->installTranslator(translator.take()); - } - QLocale currentLocale(translations.at(0).section(QLatin1Char('_'), 1)); - emit m_core->defaultTranslationsLoadedForLanguage(currentLocale.language()); - } -#endif + { QDirIterator fontIt(QStringLiteral(":/fonts")); while (fontIt.hasNext()) { diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index 7778effbc..f1f3cf25c 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -58,6 +58,7 @@ #include <QUuid> #include <QMessageBox> #include <QMetaEnum> +#include <QTranslator> template<class T> class SDKApp : public T @@ -93,17 +94,6 @@ public: bool init(QString &errorMessage) { QString appname = qApp->applicationName(); - if (m_runCheck.isRunning(RunOnceChecker::ConditionFlag::Lockfile)) { - // It is possible to install an application and thus the maintenance tool into a - // directory that requires elevated permission to create a lock file. Since this - // cannot be done without requesting credentials from the user, we silently ignore - // the fact that we could not create the lock file and check the running processes. - if (m_runCheck.isRunning(RunOnceChecker::ConditionFlag::ProcessList)) { - errorMessage = QObject::tr("Another %1 instance is already running. Wait " - "until it finishes, close it, or restart your system.").arg(qAppName()); - return false; - } - } QFile binary(binaryFile()); #ifdef Q_OS_WIN // On some admin user installations it is possible that the installer.dat @@ -206,6 +196,62 @@ public: QInstaller::Protocol::Mode::Production, userArgs, isCommandLineInterface); } +#ifndef IFW_DISABLE_TRANSLATIONS + if (!isCommandLineInterface) { + const QString directory = QLatin1String(":/translations"); + // Check if there is a modified translation first to enable people + // to easily provide corrected translations to Qt/IFW for their installers + const QString newDirectory = QLatin1String(":/translations_new"); + const QStringList translations = m_core->settings().translations(); + + if (translations.isEmpty()) { + foreach (const QLocale locale, QLocale().uiLanguages()) { + QScopedPointer<QTranslator> qtTranslator(new QTranslator(QCoreApplication::instance())); + bool qtLoaded = qtTranslator->load(locale, QLatin1String("qt"), + QLatin1String("_"), newDirectory); + if (!qtLoaded) + qtLoaded = qtTranslator->load(locale, QLatin1String("qt"), + QLatin1String("_"), directory); + + if (qtLoaded || locale.language() == QLocale::English) { + if (qtLoaded) + QCoreApplication::instance()->installTranslator(qtTranslator.take()); + + QScopedPointer<QTranslator> ifwTranslator(new QTranslator(QCoreApplication::instance())); + bool ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), newDirectory); + if (!ifwLoaded) + ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), directory); + if (ifwLoaded) + QCoreApplication::instance()->installTranslator(ifwTranslator.take()); + + // To stop loading other translations it's sufficient that + // qt was loaded successfully or we hit English as system language + emit m_core->defaultTranslationsLoadedForLanguage(locale.language()); + break; + } + } + } else { + foreach (const QString &translation, translations) { + QScopedPointer<QTranslator> translator(new QTranslator(QCoreApplication::instance())); + if (translator->load(translation, QLatin1String(":/translations"))) + QCoreApplication::instance()->installTranslator(translator.take()); + } + } + } +#endif + + if (m_runCheck.isRunning(RunOnceChecker::ConditionFlag::Lockfile)) { + // It is possible to install an application and thus the maintenance tool into a + // directory that requires elevated permission to create a lock file. Since this + // cannot be done without requesting credentials from the user, we silently ignore + // the fact that we could not create the lock file and check the running processes. + if (m_runCheck.isRunning(RunOnceChecker::ConditionFlag::ProcessList)) { + errorMessage = QObject::tr("Another %1 instance is already running. Wait " + "until it finishes, close it, or restart your system.").arg(qAppName()); + return false; + } + } + // From Qt5.8 onwards system proxy is used by default. If Qt is built with // QT_USE_SYSTEM_PROXIES false then system proxies are not used by default. if (m_parser.isSet(CommandLineOptions::scNoProxyLong)) { |