summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-06-19 14:29:32 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2015-06-30 08:47:39 +0000
commit360a8c20aa1c1c6980a033956ff79bac54d246e5 (patch)
tree3d8648c632230685915ab329d280973323023321 /src/libs/kdtools
parent0f114d791574e6cd6fa17b65d34f97e5a670d854 (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/kdtools')
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfo.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
index b46d96943..67935100b 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
@@ -33,9 +33,12 @@
****************************************************************************/
#include "kdupdaterupdatesinfo_p.h"
+#include "utils.h"
#include <QFile>
#include <QLocale>
+#include <QPair>
+#include <QVector>
#include <QUrl>
using namespace KDUpdater;
@@ -116,6 +119,7 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
return false;
UpdateInfo info;
+ QMap<QString, QString> localizedDescriptions;
for (int i = 0; i < updateE.childNodes().count(); i++) {
QDomElement childE = updateE.childNodes().at(i).toElement();
if (childE.isNull())
@@ -141,13 +145,10 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
childE.attribute(QLatin1String("inheritVersionFrom")));
info.data[childE.tagName()] = childE.text();
} else if (childE.tagName() == QLatin1String("Description")) {
- QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower();
- if (!info.data.contains(QLatin1String("Description")) && (languageAttribute.isEmpty()))
- info.data[childE.tagName()] = childE.text();
-
- // overwrite default if we have a language specific description
- if (languageAttribute == QLocale().name().toLower())
- info.data[childE.tagName()] = childE.text();
+ if (!childE.hasAttribute(QLatin1String("xml:lang")))
+ info.data[QLatin1String("Description")] = childE.text();
+ QString languageAttribute = childE.attribute(QLatin1String("xml:lang"), QLatin1String("en"));
+ localizedDescriptions.insert(languageAttribute.toLower(), childE.text());
} else if (childE.tagName() == QLatin1String("UpdateFile")) {
info.data[QLatin1String("CompressedSize")] = childE.attribute(QLatin1String("CompressedSize"));
info.data[QLatin1String("UncompressedSize")] = childE.attribute(QLatin1String("UncompressedSize"));
@@ -156,6 +157,16 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
}
}
+ QStringList candidates;
+ foreach (const QString &lang, QLocale().uiLanguages())
+ candidates << QInstaller::localeCandidates(lang.toLower());
+ foreach (const QString &candidate, candidates) {
+ if (localizedDescriptions.contains(candidate)) {
+ info.data[QLatin1String("Description")] = localizedDescriptions.value(candidate);
+ break;
+ }
+ }
+
if (!info.data.contains(QLatin1String("Name"))) {
setInvalidContentError(tr("PackageUpdate element without Name"));
return false;