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