[solved]I try to load translation file (.qm file), but nothing happened
I have three files, main.cpp, main.qml, MainPage.qml.
First, I use @lupdate main.qml MainPage.qml -ts translation_zh_CN.ts@
Then I translate the ts file in Qt Linguist
Then I use @lrelease translation_zh_CN.ts@
Then I add translation_zh_CN.qm to my resource.qrc file
my main.cpp is like this
Q_DECL_EXPORT int main(int argc, char *argv)
QScopedPointer<QApplication> app(createApplication(argc, argv));
QLocale test = QLocale::system(); qDebug() << "System locale:" << test.name(); QmlApplicationViewer viewer; viewer.rootContext()->setContextProperty("installPath", "file:///" + QCoreApplication::applicationDirPath() + "/"); //viewer.setMainQmlFile(QLatin1String("qrc:/main.qml")); viewer.setMainQmlFile("qrc:/main.qml"); QTranslator myTr; //myTr.load("qrc:/transtation_" + QLocale::system().name()); myTr.load("qrc:/translation_" + QLocale::system().name()); app->installTranslator(&myTr); viewer.showExpanded(); return app->exec();
the qDebug() shows my locale is zh_CN, but the app just doesn't show my translation.
You have the line
myTr.load("qrc:/transtation_" + QLocale::system().name());
where "translation_" is misspelled. It's probably not seeing the proper file to load.
Thank you. But after I change the misspelling, the result is still the same.
Does it make a difference if you load the translator before you create your QApplicationViewer?
Thank you. It works when I put them before I create QApplicationViewer. Also, there is something tricky that I have to use.
@ myTr.load(":/translation_" + QLocale::system().name());@
@ myTr.load("qrc:/translation_" + QLocale::system().name());@
Is there difference between them? I used to think they are the same.
How did you solve it i have a similar issue, it works in debug but not in release ... I have it before the viewer as well but it does not help ..