diff options
author | Martin Gräßlin <mgraesslin@kde.org> | 2014-06-05 14:05:44 +0200 |
---|---|---|
committer | Martin Gräßlin <mgraesslin@kde.org> | 2014-06-12 07:06:07 +0200 |
commit | 988f09bb051dca0437ecec431ee44ed5b4a560d8 (patch) | |
tree | e86c5d2303b0fc1ee4c68ac3dd59ba326c464af1 /autotests/kdesktopfiletest.cpp | |
parent | 0ed55dfa5d25bdcbef24f1b06be34467b620ae99 (diff) | |
download | kconfig-988f09bb051dca0437ecec431ee44ed5b4a560d8.tar.gz kconfig-988f09bb051dca0437ecec431ee44ed5b4a560d8.tar.bz2 |
Fix locale-aware reading in KDesktopFile
The underlying KConfig used QLocale::name() for getting the locale
aware part. But this returns "de_DE" while the desktop files store
"de".
In addition it constructs a QLocale object instead of using the
system locale. This has the advantage that the usage of
QLocale::setDafault() gets honored by KConfig.
REVIEW: 118564
Diffstat (limited to 'autotests/kdesktopfiletest.cpp')
-rw-r--r-- | autotests/kdesktopfiletest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp index 494a43c0..6c3af4c2 100644 --- a/autotests/kdesktopfiletest.cpp +++ b/autotests/kdesktopfiletest.cpp @@ -16,6 +16,7 @@ * Boston, MA 02110-1301, USA. */ #include "kdesktopfiletest.h" +#include "helper.h" #include <kconfiggroup.h> #include <qtemporaryfile.h> @@ -49,6 +50,35 @@ void KDesktopFileTest::testRead() QCOMPARE(df.fileName(), QFileInfo(fileName).canonicalFilePath()); } +void KDesktopFileTest::testReadLocalized() +{ + QTemporaryFile file("testReadLocalizedXXXXXX.desktop"); + QVERIFY(file.open()); + const QString fileName = file.fileName(); + QTextStream ts(&file); + ts << + "[Desktop Entry]\n" + "Type=Application\n" + "Name=My Application\n" + "Name[de]=Meine Anwendung\n" + "Icon=foo\n" + "\n"; + file.close(); + QVERIFY(QFile::exists(fileName)); + QVERIFY(KDesktopFile::isDesktopFile(fileName)); + + DefaultLocale defaultLocale; + // set language to German for which we have a translation + QLocale::setDefault(QLocale(QLocale::German)); + 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")); +} + void KDesktopFileTest::testSuccessfulTryExec() { QTemporaryFile file; |