Files
qt-creator/share/qtcreator/templates/wizards/projects/qtquickapplication/main.cpp
Christian Kandeler f19baeb9a5 Wizards: Extend translation support
Don't just create the ts file, but also make sure it is embedded in the
application (if supported by the build system) and make the application
load it if it matches the current locale.

Task-number: QTCREATORBUG-25079
Change-Id: Ie3a0b1975531b12acb008e8c1312dab97f158751
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-25 14:21:33 +00:00

54 lines
1.6 KiB
C++

%{Cpp:LicenseTemplate}\
%{JS: QtSupport.qtIncludes([], ["QtGui/QGuiApplication", "QtQml/QQmlApplicationEngine"])}
@if %{HasTranslation}
#include <QLocale>
#include <QTranslator>
@endif
int main(int argc, char *argv[])
{
@if %{UseVirtualKeyboard}
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
@endif
@if %{SetQPAPhysicalSize}
if (qEnvironmentVariableIsEmpty("QTGLESSTREAM_DISPLAY")) {
qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("213"));
qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("120"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
}
@else
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
@endif
QGuiApplication app(argc, argv);
@if %{HasTranslation}
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "%{JS: value('ProjectName') + '_'}" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
app.installTranslator(&translator);
break;
}
}
@endif
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}