aboutsummaryrefslogtreecommitdiff
path: root/autotests/kdesktopfiletest.cpp
diff options
context:
space:
mode:
authorMartin Gräßlin <mgraesslin@kde.org>2014-06-12 11:30:24 +0200
committerMartin Gräßlin <mgraesslin@kde.org>2014-06-21 07:41:18 +0200
commita52b00f31eb5df1cd603975bdd31794233898a59 (patch)
tree4f302c61a3f77216b9cf29208b4c7cd79eb60edf /autotests/kdesktopfiletest.cpp
parent9aeacb07b1169fa3dc9b7653e8f30070a91569d5 (diff)
downloadkconfig-a52b00f31eb5df1cd603975bdd31794233898a59.tar.gz
kconfig-a52b00f31eb5df1cd603975bdd31794233898a59.tar.bz2
Fix reading of entries for language/country combinations
This fixes a regression introduced in 988f09bb051dca0437ecec431ee44ed5b4a560d8. The mentioned commit ensures that if the locale is e.g. "de_DE" the entry "de" will be used. But this breaks if there is a translation for another country. E.g. for "de_CH" it would also pick the "de" entry. This change now operates on both just the language code and the locale. If an entry with the language code is present it will be picked. If another entry with the exact locale is found it will be overwritten. Modifiers are not supported as this is currently missing in QLocale. REVIEW: 118692
Diffstat (limited to 'autotests/kdesktopfiletest.cpp')
-rw-r--r--autotests/kdesktopfiletest.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp
index 6c3af4c2..12277331 100644
--- a/autotests/kdesktopfiletest.cpp
+++ b/autotests/kdesktopfiletest.cpp
@@ -50,6 +50,29 @@ void KDesktopFileTest::testRead()
QCOMPARE(df.fileName(), QFileInfo(fileName).canonicalFilePath());
}
+void KDesktopFileTest::testReadLocalized_data()
+{
+ QTest::addColumn<QLocale>("locale");
+ QTest::addColumn<QString>("translation");
+
+ const QString german = QStringLiteral("Meine Anwendung");
+ const QString swiss = QStringLiteral("Mein Anwendungsli");
+
+ QTest::newRow("de") << QLocale(QLocale::German) << german;
+ QTest::newRow("de_DE") << QLocale(QStringLiteral("de_DE")) << german;
+ QTest::newRow("de_DE@bayern") << QLocale(QStringLiteral("de_DE@bayern")) << german;
+ QTest::newRow("de@bayern") << QLocale(QStringLiteral("de@bayern")) << german;
+ QTest::newRow("de@freiburg") << QLocale(QStringLiteral("de@freiburg")) << QStringLiteral("Mein Anwendungsle");
+ // For CH we have a special translation
+ QTest::newRow("de_CH") << QLocale(QLocale::German, QLocale::Switzerland) << swiss;
+ QTest::newRow("de_CH@bern") << QLocale(QStringLiteral("de_CH@bern")) << swiss;
+ // Austria should fall back to "de"
+ QTest::newRow("de_AT") << QLocale(QLocale::German, QLocale::QLocale::Austria) << german;
+ QTest::newRow("de_AT@tirol") << QLocale(QStringLiteral("de_AT@tirol")) << german;
+ // no translation for French
+ QTest::newRow("fr") << QLocale(QLocale::French) << QStringLiteral("My Application");
+}
+
void KDesktopFileTest::testReadLocalized()
{
QTemporaryFile file("testReadLocalizedXXXXXX.desktop");
@@ -61,6 +84,8 @@ void KDesktopFileTest::testReadLocalized()
"Type=Application\n"
"Name=My Application\n"
"Name[de]=Meine Anwendung\n"
+ "Name[de@freiburg]=Mein Anwendungsle\n"
+ "Name[de_CH]=Mein Anwendungsli\n"
"Icon=foo\n"
"\n";
file.close();
@@ -68,15 +93,13 @@ void KDesktopFileTest::testReadLocalized()
QVERIFY(KDesktopFile::isDesktopFile(fileName));
DefaultLocale defaultLocale;
- // set language to German for which we have a translation
- QLocale::setDefault(QLocale(QLocale::German));
+
+ QFETCH(QLocale, locale);
+ QLocale::setDefault(locale);
KDesktopFile df(fileName);
- QCOMPARE(df.readName(), QString::fromLatin1("Meine Anwendung"));
- // set language to French for which we don't have a translation
- QLocale::setDefault(QLocale(QLocale::French));
- KDesktopFile df2(fileName);
- QCOMPARE(df2.readName(), QString::fromLatin1("My Application"));
+ QEXPECT_FAIL("de@freiburg", "QLocale doesn't support modifiers", Continue);
+ QTEST(df.readName(), "translation");
}
void KDesktopFileTest::testSuccessfulTryExec()