diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-14 18:46:38 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-14 19:02:37 +0200 |
commit | c2f8b9535d34da6948ccf45b7d5fd90de2f1bc9e (patch) | |
tree | c6f7e058a985d7c18b51cadc76283caf555071c9 /tests/auto/qml/qqmltranslation | |
parent | 9e633bbda7608ac0231809e2a6a97ae8f2d849d6 (diff) | |
parent | 803f18f02e5609a1ca00a5b78ea6d3613d44e1a0 (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Removed dependencies.yaml because we don't use it yet in wip/cmake.
Fixed conflict in qmlcachegen.cpp.
Change-Id: Ie1060c737bee1daa85779903598e5b6d5020d922
Diffstat (limited to 'tests/auto/qml/qqmltranslation')
4 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltranslation/data/mylibrary.js b/tests/auto/qml/qqmltranslation/data/mylibrary.js new file mode 100644 index 0000000000..5903db3b4b --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/mylibrary.js @@ -0,0 +1,5 @@ +Qt.include("nested_js_translation.js") + +function translation_success() { + return qsTr("English in mylibrary"); +} diff --git a/tests/auto/qml/qqmltranslation/data/nested_js_translation.js b/tests/auto/qml/qqmltranslation/data/nested_js_translation.js new file mode 100644 index 0000000000..336cdedfea --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/nested_js_translation.js @@ -0,0 +1,3 @@ +function translation_fail() { + return qsTr("English in translation") +} diff --git a/tests/auto/qml/qqmltranslation/data/preferjs.qml b/tests/auto/qml/qqmltranslation/data/preferjs.qml new file mode 100644 index 0000000000..040fa12e4e --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/preferjs.qml @@ -0,0 +1,8 @@ +import QtQml 2.12 + +import "mylibrary.js" as Lib + +QtObject { + property string german1: Lib.translation_fail() + property string german2: Lib.translation_success() +} diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp index dcfe914af6..a75a00bd01 100644 --- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp +++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp @@ -46,6 +46,7 @@ private slots: void translation(); void idTranslation(); void translationChange(); + void preferJSContext(); }; void tst_qqmltranslation::translation_data() @@ -175,6 +176,10 @@ class DummyTranslator : public QTranslator Q_UNUSED(n); if (!qstrcmp(sourceText, "translate me")) return QString::fromUtf8("xxx"); + if (!qstrcmp(sourceText, "English in mylibrary") && !qstrcmp(context, "mylibrary")) + return QString::fromUtf8("Deutsch in mylibrary"); + if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "nested_js_translation")) + return QString::fromUtf8("Deutsch in Setzung"); return QString(); } @@ -213,6 +218,24 @@ void tst_qqmltranslation::translationChange() QCoreApplication::removeTranslator(&translator); } +void tst_qqmltranslation::preferJSContext() +{ + DummyTranslator translator; + QCoreApplication::installTranslator(&translator); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("preferjs.qml")); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QCOMPARE(object->property("german1").toString(), + QStringLiteral("Deutsch in Setzung")); + QCOMPARE(object->property("german2").toString(), + QStringLiteral("Deutsch in mylibrary")); + + QCoreApplication::removeTranslator(&translator); +} + QTEST_MAIN(tst_qqmltranslation) #include "tst_qqmltranslation.moc" |