| 1 |
// Copyright (C) 2024 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <QtCore/QCoreApplication> |
| 5 |
#include <QtCore/QTranslator> |
| 6 |
|
| 7 |
#include <iostream> |
| 8 |
|
| 9 |
int main(int argc, char *argv[]) |
| 10 |
{ |
| 11 |
QCoreApplication app(argc, argv); |
| 12 |
|
| 13 |
const QString qmFile = ":/i18n/app1_de.qm"; |
| 14 |
std::cout << "Loading translation '" << qPrintable(qmFile) << "'..." << std::endl; |
| 15 |
QTranslator *translator = new QTranslator(&app); |
| 16 |
if (!translator->load(qmFile)) { |
| 17 |
std::cerr << "Error: failed to load the translation" << std::endl; |
| 18 |
return 1; |
| 19 |
} |
| 20 |
app.installTranslator(translator); |
| 21 |
|
| 22 |
std::cout << "Checking translated text..." << std::endl; |
| 23 |
const QString translated = QCoreApplication::translate("main", "Hello from main!"); |
| 24 |
if (!translated.startsWith("Hallo aus")) { |
| 25 |
std::cerr << "Error: translation doesn't seem to work. " |
| 26 |
<< "The translated text is '" << qPrintable(translated) << "'" << std::endl; |
| 27 |
return 2; |
| 28 |
} |
| 29 |
|
| 30 |
std::cout << "All good." << std::endl; |
| 31 |
return 0; |
| 32 |
} |