aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autotests/helper.h43
-rw-r--r--autotests/kconfigtest.cpp3
-rw-r--r--autotests/kdesktopfiletest.cpp30
-rw-r--r--autotests/kdesktopfiletest.h1
-rw-r--r--src/core/kconfig.cpp2
5 files changed, 78 insertions, 1 deletions
diff --git a/autotests/helper.h b/autotests/helper.h
new file mode 100644
index 00000000..83f1a8bc
--- /dev/null
+++ b/autotests/helper.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) version 3, or any
+ * later version accepted by the membership of KDE e.V. (or its
+ * successor approved by the membership of KDE e.V.), which shall
+ * act as a proxy defined in Section 6 of version 3 of the license.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef KCONFIG_AUTOTESTS_HELPER_H
+#define KCONFIG_AUTOTESTS_HELPER_H
+
+#include <QLocale>
+
+/**
+ * @brief Helper to store the current default QLocale and resetting to it in the dtor.
+ **/
+class DefaultLocale
+{
+public:
+ DefaultLocale()
+ : m_defaultLocale()
+ {
+ }
+ ~DefaultLocale()
+ {
+ QLocale::setDefault(m_defaultLocale);
+ }
+private:
+ QLocale m_defaultLocale;
+};
+
+#endif
diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp
index 2b6de0d7..a8482b70 100644
--- a/autotests/kconfigtest.cpp
+++ b/autotests/kconfigtest.cpp
@@ -21,6 +21,7 @@
#undef QT_NO_CAST_FROM_BYTEARRAY
#include "kconfigtest.h"
+#include "helper.h"
#include <QtTest/QtTest>
#include <qtemporarydir.h>
@@ -927,6 +928,8 @@ void KConfigTest::testCascadingWithLocale()
void KConfigTest::testMerge()
{
+ DefaultLocale defaultLocale;
+ QLocale::setDefault(QLocale::c());
KConfig config(TEST_SUBDIR "mergetest", KConfig::SimpleConfig);
KConfigGroup cg = config.group("some group");
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;
diff --git a/autotests/kdesktopfiletest.h b/autotests/kdesktopfiletest.h
index d57351fd..f854d6cc 100644
--- a/autotests/kdesktopfiletest.h
+++ b/autotests/kdesktopfiletest.h
@@ -26,6 +26,7 @@ class KDesktopFileTest : public QObject
Q_OBJECT
private Q_SLOTS:
void testRead();
+ void testReadLocalized();
void testUnsuccessfulTryExec();
void testSuccessfulTryExec();
void testActionGroup();
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp
index ea9746c0..cfa6c207 100644
--- a/src/core/kconfig.cpp
+++ b/src/core/kconfig.cpp
@@ -95,7 +95,7 @@ KConfigPrivate::KConfigPrivate(KConfig::OpenFlags flags,
// mappingsRegistered = true;
// }
- setLocale(QLocale::system().name());
+ setLocale(QLocale().name().split(QStringLiteral("_")).at(0));
}
bool KConfigPrivate::lockLocal()