#include<QApplication>
#include<QTranslator>
#include<QObject>
#include<QTextCodec>
#include<QWidget>
int main(int argc, char* argv[])
{
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
QApplication app(argc, argv);
QTranslator translator;
translator.load("app_zh_CN.qm");
app.installTranslator(&translator);
QWidget widget;
widget.setWindowTitle(QObject::tr("Hello World!"));
widget.show();
return app.exec();
}
SOURCES += \
main.cpp
TRANSLATIONS += app_zh_CN.ts
The Gui interface is “Hello World!” also.. But in my file.qm is be translate to “你好!”(chinese)…
where is the preblem ? who can help me..
Your example works for me if I put the .qm file in the “correct” spot. (See below.) Make sure you are doing all the steps:
lupdateto create the .ts file.lreleaseto compile the .ts file to a .qm file.My guess is that #4 is going bad. The documentation for
QTranslator::loadstates:However, I had to put the .qm file in the folder above the executable to get it to work as is. Unless I’m misunderstanding the docs, this is a Qt bug, but one that is simple to workaround. If I explicitly gave the directory as
app.applicationDirPath, it worked in the executable folder. You could also specify a separate directory. For example:translator.load("app_zh_CN.qm");works with:translator.load("app_zh_CN.qm", app.applicationDirPath());works with: