| 1 |
// Copyright (C) 2023 The Qt Company Ltd. |
| 2 |
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected], author Stephen Kelly <[email protected]> |
| 3 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 4 |
|
| 5 |
#include <QCoreApplication> |
| 6 |
#include <QTranslator> |
| 7 |
#include <QLocale> |
| 8 |
|
| 9 |
#include <cstdio> |
| 10 |
|
| 11 |
using namespace Qt::Literals::StringLiterals; |
| 12 |
|
| 13 |
int main(int argc, char **argv) |
| 14 |
{ |
| 15 |
QCoreApplication app(argc, argv); |
| 16 |
QTranslator *translator = new QTranslator(); |
| 17 |
QLocale frenchLocale = QLocale(QLocale::French); |
| 18 |
QLocale::setDefault(frenchLocale); |
| 19 |
if (!translator->load(QLocale(), "myobject.qm"_L1, {}, |
| 20 |
qApp->applicationDirPath() + "/fr/"_L1)) { |
| 21 |
qFatal("Could not load translation file!"); |
| 22 |
} |
| 23 |
|
| 24 |
app.installTranslator(translator); |
| 25 |
|
| 26 |
QString text = QCoreApplication::translate("main", "Hello, world!"); |
| 27 |
if (text != "Bonjour le monde!"_L1) |
| 28 |
qFatal("Translation not found!"); |
| 29 |
|
| 30 |
std::fprintf(stdout, "%s\n", qPrintable(text)); |
| 31 |
return 0; |
| 32 |
} |