QMessageBox, QColorDialog, button Chinese display
Version: Qt5.9.9
Environment: QtCretator MinGW
qt_zh_CN.ts
Find and copy a copy to the project directory in the Qt source code directory , the file is: G:\install\Qt\Qt5.9.9\5.9.9\Src\qttranslations\translations
.
Open qt_zh_CN.ts
the file, find QColorDialog
the tag, and add the following:
<message>
<source>&Pick Screen Color</source>
<translation>拾取屏幕颜色(&P)</translation>
</message>
<message>
<source>Cursor at %1, %2
Press ESC to cancel</source>
<translation>坐标:%1,%2
按ECS键取消</translation>
</message>
As shown below:
Find QDialogButtonBox
the tags:
<context>
<name>QDialogButtonBox</name>
...
...
...
</context>
Make a complete copy of this label and paste it below, and name it: QPlatformTheme
,
As shown below:
Use to Linguist
open this file, if there is a question mark displayed, then there is a problem with the translation, just change it to the Chinese translation manually!
Then republish to generate the .qm file, main
just load the translation file in the function!
///
/// 加载翻译
///
QTranslator base;
if(base.load(":/translations/qt_zh_CN.qm"))
{
a.installTranslator(&base);
}else
{
QMessageBox::warning(nullptr, QObject::tr("警告"), QObject::tr("加载翻译文件qt_zh_CN.qm失败,部分界面可能无法汉化显示!"));
}
Note: The translation file must be loaded before the window is displayed!
ends…