2

我想用英语或法语(取决于操作系统语言)翻译我的安装程序向导(基于 Qt 安装程序框架)。

我在“installscript.qs”文件中添加了这些行:

Component.prototype.retranslateUi = function()
{
    component.languageChanged();
}

我在“config.xml”文件中添加了这些:

<Installer>
    ...
    <Translations>
        <Translation>fr.qm</Translation>
    </Translations>
</Installer>

但是一切都很好(所有长文本都被翻译)(法语),但是像“下一步”、“取消”、“退出”这样的按钮没有被翻译(见截图):

在此处输入图像描述

ps:我不想使用C++代码。(仅脚本或 Xml)

4

2 回答 2

3

除了您自己的 .qm 文件外,您还需要加载 Qt 翻译文件。该文件位于 Qt 安装文件夹的翻译子文件夹中(例如./usr/share/qt5/translations/)。对于某些语言,加载 qt_xx (其中 XX 应替换为您的语言环境)似乎就足够了,但对于德语,我必须加载“qtbase_XX”来翻译“下一步”和“取消”按钮。在fr语言环境的示例中,它们被命名为qt_fr.qmqtbase_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 附带的原始翻译缺少&amp;

所以,改变:

<context>
    <name>QInstaller::IntroductionPage</name>
    ...
    <message>
        <source>Quit</source>
        <translation>Beenden</translation>
    </message>

<context>
    <name>QInstaller::IntroductionPage</name>
    ...
    <message>
        <source>&amp;Quit</source>
        <translation>Beenden</translation>
    </message>

并且重新编译框架会导致框架内的翻译退出按钮(Beenden)。

我没试过,但是学习/installer-framework/src/libs/installer/packagemanagergui.cpp应该也能让你翻译 Next 按钮。

在此处输入图像描述

于 2017-07-06T11:54:16.377 回答
1

添加上下文可能会有所帮助:

function Component()
{
  qsTranslate("QInstaller::IntroductionPage", "&Quit");
}

它在 Next 和 Back 之后醒来,但找不到在哪里写qsTranslate().

于 2020-07-17T08:36:50.950 回答