1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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"