Files
qt-creator/share/qtcreator/templates/wizards/projects/qtwidgetsapplication/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

29 lines
733 B
C++

%{Cpp:LicenseTemplate}\
#include "%{HdrFileName}"
%{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ], [ 'QtWidgets/QApplication' ]) }\
@if %{HasTranslation}
#include <QLocale>
#include <QTranslator>
@endif
int main(int argc, char *argv[])
{
QApplication a(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)) {
a.installTranslator(&translator);
break;
}
}
@endif
%{Class} w;
w.show();
return a.exec();
}