| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QCoreApplication> |
| 5 | #include <QObject> |
| 6 | #include <QTranslator> |
| 7 | |
| 8 | #include <iostream> |
| 9 | |
| 10 | int main(int argc, char *argv[]) |
| 11 | { |
| 12 | QCoreApplication app(argc, argv); |
| 13 | |
| 14 | std::cout << "Loading German translation..." << std::endl; |
| 15 | QTranslator translator; |
| 16 | if (translator.load(":/i18n/myapp_de.qm")) { |
| 17 | app.installTranslator(&translator); |
| 18 | } else { |
| 19 | std::cerr << "Cannot load .qm file." << std::endl; |
| 20 | return 1; |
| 21 | } |
| 22 | |
| 23 | std::cout << "Checking translation for context 'myapp'..." << std::endl; |
| 24 | if (QCoreApplication::translate("myapp", "message from the application") |
| 25 | != "Nachricht von der Anwendung") { |
| 26 | std::cerr << "The app's translation doesn't work. This is surprising." << std::endl; |
| 27 | return 2; |
| 28 | } |
| 29 | |
| 30 | std::cout << "Checking translation for context 'qtbase'..." << std::endl; |
| 31 | if (QCoreApplication::translate("qtbase", "message from qtbase") |
| 32 | != "Nachricht von qtbase") { |
| 33 | std::cerr << "The qtbase translation catalog has not been merged into the app's .qm file." |
| 34 | << std::endl; |
| 35 | return 3; |
| 36 | } |
| 37 | |
| 38 | std::cout << "The test was successful." << std::endl; |
| 39 | return 0; |
| 40 | } |