diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-06-19 14:29:32 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-06-30 08:47:39 +0000 |
commit | 360a8c20aa1c1c6980a033956ff79bac54d246e5 (patch) | |
tree | 3d8648c632230685915ab329d280973323023321 /src/libs/installer/component.cpp | |
parent | 0f114d791574e6cd6fa17b65d34f97e5a670d854 (diff) |
Unify handling of translations
Mimic the logic implemented in installerbase/QTranslator::load() by
- using QLocale().uiLanguages()
- splitting up the locales into candidates (first en-US, then en ...)
- implicitly assuming the default is English
Task-number: QTIFW-390
Change-Id: I294288d5fc739ebf12c93a0e1a43d613b3834721
Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/component.cpp')
-rw-r--r-- | src/libs/installer/component.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index dddca9f14..b49bfe3a4 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -42,6 +42,7 @@ #include "packagemanagercore.h" #include "remoteclient.h" #include "settings.h" +#include "utils.h" #include <kdupdaterupdatesourcesinfo.h> #include <kdupdaterupdateoperationfactory.h> @@ -604,23 +605,32 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar if (!ProductKeyCheck::instance()->isValidLicenseTextFile(fileName)) continue; - QFileInfo fileInfo(fileName); - QFile file(QString::fromLatin1("%1%2_%3.%4").arg(directory, fileInfo.baseName(), - QLocale().name().toLower(), fileInfo.completeSuffix())); - if (!file.exists()) { - file.setFileName(QString::fromLatin1("%1%2_%3.%4").arg(directory, fileInfo.baseName(), - QLocale().name().left(2), fileInfo.completeSuffix())); + QFileInfo fileInfo(directory, fileName); + foreach (const QString &lang, QLocale().uiLanguages()) { + if (QLocale(lang).language() == QLocale::English) // we assume English is the default language + break; + + QList<QFileInfo> fileCandidates; + foreach (const QString &locale, QInstaller::localeCandidates(lang.toLower())) { + fileCandidates << QFileInfo(QString::fromLatin1("%1%2_%3.%4").arg( + directory, fileInfo.baseName(), locale, + fileInfo.completeSuffix())); + } + + auto fInfo = std::find_if(fileCandidates.constBegin(), fileCandidates.constEnd(), + [](const QFileInfo &file) { + return file.exists(); + }); + if (fInfo != fileCandidates.constEnd()) { + fileInfo = *fInfo; + break; + } } + QFile file(fileInfo.filePath()); if (!file.open(QIODevice::ReadOnly)) { - // No translated license, use untranslated file - qDebug().nospace() << "Unable to open translated license file" << file.fileName() - << ". Using untranslated fallback."; - file.setFileName(directory + fileName); - if (!file.open(QIODevice::ReadOnly)) { - throw Error(tr("Could not open the requested license file '%1'. Error: %2").arg(fileName, - file.errorString())); - } + throw Error(tr("Could not open the requested license file '%1'. Error: %2").arg( + file.fileName(), file.errorString())); } QTextStream stream(&file); stream.setCodec("UTF-8"); |