diff options
Diffstat (limited to 'tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType')
5 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/CMakeLists.txt b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/CMakeLists.txt new file mode 100644 index 0000000000..66183bc9c8 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_standard_project_setup(REQUIRES 6.5 I18N_TRANSLATED_LANGUAGES fr) + +qt_internal_add_executable(i18nLoadFromModuleQmlType + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" + SOURCES + main.cpp + LIBRARIES + Qt::Gui + Qt::Qml +) + +qt_add_qml_module(i18nLoadFromModuleQmlType + URI TranslatedQml + QML_FILES Main.qml +) + +qt_internal_extend_target(i18nLoadFromModuleQmlType + ENABLE_AUTOGEN_TOOLS + uic +) + +qt_add_resources(i18nLoadFromModuleQmlType "loadFromModuleQmlTypeQmFile" + PREFIX + /qt/qml/TranslatedQml/ + FILES + i18n/qml_fr.qm +) diff --git a/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/Main.qml b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/Main.qml new file mode 100644 index 0000000000..9f8e1984e9 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/Main.qml @@ -0,0 +1,13 @@ +import QtQml + +QtObject { + property string expected: "placeholder" + property string actual: qsTr("Hello") + + function f() { + if (expected === actual) + Qt.exit(0) + else + Qt.exit(actual.charCodeAt(0)) + } +} diff --git a/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.qm b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.qm Binary files differnew file mode 100644 index 0000000000..a53cf121a2 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.qm diff --git a/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.ts b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.ts new file mode 100644 index 0000000000..87b46be9ca --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/i18n/qml_fr.ts @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1" language="fr_FR"> +<context> + <name>Main</name> + <message> + <location filename="../Main.qml" line="5"/> + <source>Hello</source> + <translation>Salut</translation> + </message> +</context> +</TS> diff --git a/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/main.cpp b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/main.cpp new file mode 100644 index 0000000000..6f28ec8148 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/loadFromModuleTranslationsQmlType/main.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QLocale::setDefault(QLocale(QLocale::Language(qEnvironmentVariableIntValue("qtlang")))); + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; + + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, + &app, []() { QCoreApplication::exit(-1); }, + Qt::QueuedConnection); + engine.loadFromModule("TranslatedQml", "Main"); + + QString expected = qgetenv("LOADFROMMODULE_TEST_EXPECTED_OUTPUT"); + auto *root = engine.rootObjects().first(); + root->setProperty("expected", expected); + root->metaObject()->invokeMethod(root, "f"); + return app.exec(); +} |