summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Mordvinov <dvvsrd@gmail.com>2015-05-07 05:25:07 +0300
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-05-08 11:42:02 +0000
commitff19df37415ead8d26597d861b4d0311ac971c74 (patch)
tree677388c7d6e8e71fcf8467b1e2bc6e8af5337626
parentd74b5e575dfbc3d39f5a2970cc698cc389542116 (diff)
Implemented xml:lang attribute support for DisplayName tag.
Components in tree view are often need to be localized. Therefore packages.xml syntax is extended with possibility to specify xml:lang attribute for DisplayName tag (similarly to Description one). Test data extended with root component localization. Added new testcase that changes default locale and checks that loaded component names correspond to hard-coded ones. Docs updated with new feature description. Change-Id: Ic330c3c6684e763eb48a2e99e71784913544e686 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
-rw-r--r--doc/installerfw.qdoc5
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfo.cpp21
-rw-r--r--src/libs/kdtools/kdupdaterupdatesinfodata_p.h3
-rw-r--r--tests/auto/installer/componentmodel/data/updates.xml2
-rw-r--r--tests/auto/installer/componentmodel/tst_componentmodel.cpp32
5 files changed, 54 insertions, 9 deletions
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index 79c4d7962..0ca6e5b5e 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -548,11 +548,12 @@
\row
\li DisplayName
\li Human-readable name of the component. Required.
+ Specify translations for the name of the component as values of additional
+ DisplayName tags, with the xml:lang attribute set to the correct locale.
\row
\li Description
\li Human-readable description of the component. Required.
- Specify translations for the description as values of additional
- Description tags, with the xml:lang attribute set to the correct locale.
+ Translations may be specified similarly to DisplayName tag.
If a localization that matches the locale is not found and an untranslated
version exists, that one will be used. Otherwise no Description will be
shown for that locale.
diff --git a/src/libs/kdtools/kdupdaterupdatesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
index b46d96943..ffc907923 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfo.cpp
+++ b/src/libs/kdtools/kdupdaterupdatesinfo.cpp
@@ -140,14 +140,10 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
info.data.insert(QLatin1String("inheritVersionFrom"),
childE.attribute(QLatin1String("inheritVersionFrom")));
info.data[childE.tagName()] = childE.text();
+ } else if (childE.tagName() == QLatin1String("DisplayName")) {
+ processLocalizedTag(childE, info.data);
} 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();
+ processLocalizedTag(childE, info.data);
} else if (childE.tagName() == QLatin1String("UpdateFile")) {
info.data[QLatin1String("CompressedSize")] = childE.attribute(QLatin1String("CompressedSize"));
info.data[QLatin1String("UncompressedSize")] = childE.attribute(QLatin1String("UncompressedSize"));
@@ -173,6 +169,17 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE)
return true;
}
+void UpdatesInfoData::processLocalizedTag(const QDomElement &childE, QHash<QString, QVariant> &info) const
+{
+ QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower();
+ if (!info.contains(childE.tagName()) && (languageAttribute.isEmpty()))
+ info[childE.tagName()] = childE.text();
+
+ // overwrite default if we have a language specific description
+ if (QLocale().name().startsWith(languageAttribute, Qt::CaseInsensitive))
+ info[childE.tagName()] = childE.text();
+}
+
//
// UpdatesInfo
diff --git a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
index 19e44fa10..786c96f1c 100644
--- a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
+++ b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h
@@ -62,6 +62,9 @@ public:
bool parsePackageUpdateElement(const QDomElement &updateE);
void setInvalidContentError(const QString &detail);
+
+private:
+ void processLocalizedTag(const QDomElement &childE, QHash<QString, QVariant> &info) const;
};
} // namespace KDUpdater
diff --git a/tests/auto/installer/componentmodel/data/updates.xml b/tests/auto/installer/componentmodel/data/updates.xml
index e1f72de10..cfd756a5c 100644
--- a/tests/auto/installer/componentmodel/data/updates.xml
+++ b/tests/auto/installer/componentmodel/data/updates.xml
@@ -5,6 +5,8 @@
<PackageUpdate>
<Name>com.vendor.product</Name>
<DisplayName>The root component</DisplayName>
+ <DisplayName xml:lang="ru_RU">Корневая компонента</DisplayName>
+ <DisplayName xml:lang="de_DE">Wurzel Komponente</DisplayName>
<Description>Install this example.</Description>
<Version>0.1.0-1</Version>
<ReleaseDate>2010-09-21</ReleaseDate>
diff --git a/tests/auto/installer/componentmodel/tst_componentmodel.cpp b/tests/auto/installer/componentmodel/tst_componentmodel.cpp
index 287c1bb42..f764a9371 100644
--- a/tests/auto/installer/componentmodel/tst_componentmodel.cpp
+++ b/tests/auto/installer/componentmodel/tst_componentmodel.cpp
@@ -4,6 +4,7 @@
#include "packagemanagercore.h"
#include <QTest>
+#include <QtCore/QLocale>
using namespace KDUpdater;
using namespace QInstaller;
@@ -20,6 +21,12 @@ static const char vendorSecondProductSubnode[] = "com.vendor.second.product.subn
static const char vendorSecondProductSubnodeSub[] = "com.vendor.second.product.subnode.sub";
static const char vendorThirdProductVirtual[] = "com.vendor.third.product.virtual";
+static const QMap<QString, QString> rootComponentDisplayNames = {
+ {"", QLatin1String("The root component")},
+ {"ru_ru", QString::fromUtf8("Корневая компонента")},
+ {"de_de", QString::fromUtf8("Wurzel Komponente")}
+};
+
class tst_ComponentModel : public QObject
{
Q_OBJECT
@@ -311,6 +318,31 @@ private slots:
delete component;
}
+ void testComponentsLocalization()
+ {
+ QStringList localesToTest = { "en_US", "ru_RU", "de_DE", "fr_FR" };
+ foreach (const QString &localeToTest, localesToTest) {
+ QLocale::setDefault(localeToTest);
+ QString expectedName = rootComponentDisplayNames.contains(localeToTest.toLower())
+ ? rootComponentDisplayNames[localeToTest.toLower()]
+ : rootComponentDisplayNames[QString()];
+
+ setPackageManagerOptions(NoFlags);
+
+ QList<Component*> rootComponents = loadComponents();
+ testComponentsLoaded(rootComponents);
+
+ // setup the model with 1 column
+ ComponentModel model(1, &m_core);
+ model.setRootComponents(rootComponents);
+
+ const QModelIndex root = model.indexFromComponentName(vendorProduct);
+ QCOMPARE(model.data(root, Qt::DisplayRole).toString(), expectedName);
+
+ qDeleteAll(rootComponents);
+ }
+ }
+
private:
void setPackageManagerOptions(Options flags) const
{