除了您自己的 .qm 文件外,您还需要加载 Qt 翻译文件。该文件位于 Qt 安装文件夹的翻译子文件夹中(例如./usr/share/qt5/translations/
)。对于某些语言,加载 qt_xx (其中 XX 应替换为您的语言环境)似乎就足够了,但对于德语,我必须加载“qtbase_XX”来翻译“下一步”和“取消”按钮。在fr
语言环境的示例中,它们被命名为qt_fr.qm
和qtbase_fr.qm
。
编辑:
由于 John Smith 的评论,我检查了 Installer 框架源,并且该框架无法加载多个翻译文件:
看installer-framework/src/libs/installer/component.cpp
/*!
Loads the translations matching the name filters \a qms inside \a directory. Only translations
with a base name matching the current locale's name are loaded. For more information, see
\l{Translating Pages}.
*/
void Component::loadTranslations(const QDir &directory, const QStringList &qms)
所以我上面的原始答案(这会导致翻译QWizard::CancelButton
)不起作用。
Quit
通过更正框架源中提供的 de.ts 文件,我将 Installer Frameworks 翻译示例的按钮翻译为德语installer-framework/src/sdk/translations
feramework 附带的原始翻译缺少&
:
所以,改变:
<context>
<name>QInstaller::IntroductionPage</name>
...
<message>
<source>Quit</source>
<translation>Beenden</translation>
</message>
至
<context>
<name>QInstaller::IntroductionPage</name>
...
<message>
<source>&Quit</source>
<translation>Beenden</translation>
</message>
并且重新编译框架会导致框架内的翻译退出按钮(Beenden)。
我没试过,但是学习/installer-framework/src/libs/installer/packagemanagergui.cpp
应该也能让你翻译 Next 按钮。
![在此处输入图像描述](https://i.stack.imgur.com/L8wH2.png)