6. QT国际化 translate QT语言家 翻译

时间:2022-05-14 21:38:21

main.

QTranslator  *qtTranslator = new QTranslator();

 if (IsChinese()) {
qtTranslator->load(":/language/tr_zh.qm");
QTranslator *translator_Zh = new QTranslator();
translator_Zh->load(":/language/qt_zh_CN.qm");
qApp->installTranslator(translator_Zh); QTranslator *widgetsTranslator_Zh = new QTranslator();
widgetsTranslator_Zh->load(":/language/widgets.qm");
qApp->installTranslator(widgetsTranslator_Zh);
}
else {
qtTranslator->load(":/language/tr_en.qm");
}
qApp->installTranslator(qtTranslator);

在_zh_CN.qm中

<message>
<location filename="View/LoginDialog.cpp" line="26"/>
<source>YOU</source>
<translation>你/translation>
</message>

  

在_en.qm中

<message>
<location filename="View/LoginDialog.cpp" line="26"/>
<source>YOU</source>
<translation>YOU/translation>
</message>