1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include <QTranslator>
46 #include "../../shared/util.h"
48 class tst_qdeclarativetranslation : public QDeclarativeDataTest
52 tst_qdeclarativetranslation() {}
57 void translationInQrc();
60 void tst_qdeclarativetranslation::translation()
62 QTranslator translator;
63 translator.load(QLatin1String("qml_fr"), dataDirectory());
64 QCoreApplication::installTranslator(&translator);
66 QDeclarativeEngine engine;
67 QDeclarativeComponent component(&engine, testFileUrl("translation.qml"));
68 QObject *object = component.create();
71 QCOMPARE(object->property("basic").toString(), QLatin1String("bonjour"));
72 QCOMPARE(object->property("basic2").toString(), QLatin1String("au revoir"));
73 QCOMPARE(object->property("basic3").toString(), QLatin1String("bonjour"));
74 QCOMPARE(object->property("disambiguation").toString(), QLatin1String("salut"));
75 QCOMPARE(object->property("disambiguation2").toString(), QString::fromUtf8("\xc3\xa0 plus tard"));
76 QCOMPARE(object->property("disambiguation3").toString(), QLatin1String("salut"));
77 QCOMPARE(object->property("noop").toString(), QLatin1String("bonjour"));
78 QCOMPARE(object->property("noop2").toString(), QLatin1String("au revoir"));
79 QCOMPARE(object->property("singular").toString(), QLatin1String("1 canard"));
80 QCOMPARE(object->property("singular2").toString(), QLatin1String("1 canard"));
81 QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards"));
82 QCOMPARE(object->property("plural2").toString(), QLatin1String("2 canards"));
84 QCoreApplication::removeTranslator(&translator);
88 void tst_qdeclarativetranslation::idTranslation()
90 QTranslator translator;
91 translator.load(QLatin1String("qmlid_fr"), dataDirectory());
92 QCoreApplication::installTranslator(&translator);
94 QDeclarativeEngine engine;
95 QDeclarativeComponent component(&engine, testFileUrl("idtranslation.qml"));
96 QObject *object = component.create();
99 QCOMPARE(object->property("idTranslation").toString(), QLatin1String("bonjour tout le monde"));
100 QCOMPARE(object->property("idTranslation2").toString(), QLatin1String("bonjour tout le monde"));
101 QCOMPARE(object->property("idTranslation3").toString(), QLatin1String("bonjour tout le monde"));
103 QCoreApplication::removeTranslator(&translator);
107 void tst_qdeclarativetranslation::translationInQrc()
109 QTranslator translator;
110 translator.load(":/qml_fr.qm");
111 QCoreApplication::installTranslator(&translator);
113 QDeclarativeEngine engine;
114 QDeclarativeComponent component(&engine, QUrl("qrc:/translation.qml"));
115 QObject *object = component.create();
116 QVERIFY(object != 0);
118 QCOMPARE(object->property("basic").toString(), QLatin1String("bonjour"));
119 QCOMPARE(object->property("basic2").toString(), QLatin1String("au revoir"));
120 QCOMPARE(object->property("basic3").toString(), QLatin1String("bonjour"));
121 QCOMPARE(object->property("disambiguation").toString(), QLatin1String("salut"));
122 QCOMPARE(object->property("disambiguation2").toString(), QString::fromUtf8("\xc3\xa0 plus tard"));
123 QCOMPARE(object->property("disambiguation3").toString(), QLatin1String("salut"));
124 QCOMPARE(object->property("noop").toString(), QLatin1String("bonjour"));
125 QCOMPARE(object->property("noop2").toString(), QLatin1String("au revoir"));
126 QCOMPARE(object->property("singular").toString(), QLatin1String("1 canard"));
127 QCOMPARE(object->property("singular2").toString(), QLatin1String("1 canard"));
128 QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards"));
129 QCOMPARE(object->property("plural2").toString(), QLatin1String("2 canards"));
131 QCoreApplication::removeTranslator(&translator);
135 QTEST_MAIN(tst_qdeclarativetranslation)
137 #include "tst_qdeclarativetranslation.moc"