2

我正在尝试使用我已经使用 Qt 安装程序框架的预构建版本创建的安装程序的翻译版本,但是文档不足,我需要知道应该将翻译文件放在哪里(en.qm我'已翻译成目标语言)

我尝试将翻译文件放在配置文件夹中并设置<Translations>元素,config.xml但与创建没有此元素的安装程序相比没有任何变化。我取得的唯一进展是当我将en.qm其中一个包文件夹放入 meta 文件夹并在其中添加<Translations>元素时package.xml。但在这个解决方案中,只有一半的页面被翻译。

这是我添加的翻译config.xml元素package.xml
<Translations> <Translation>en.qm</Translation> </Translations>

en.qm添加到元文件夹中的包文件时,新页面和一些默认页面被翻译,但第一页(欢迎...)和开始菜单快捷方式页面以及下一步和后退按钮永远不会被翻译。


PS:我需要我自己语言的安装程序,并且操作系统语言始终是英语。


P.S_2:我正在使用 Qt 5.9.1 和预构建的 Qt 安装程序框架 3.0.6,并且我en.qm使用以下命令在installerfw.pro安装程序框架版本 3.0.6 的源代码上创建了文件。
lupdate en.ts
接着
lrelease installerfw.pro -ts en.ts


谢谢

4

1 回答 1

0

不幸的是,您必须单独翻译每个包。

我用整个插值器翻译过程的自动化为自己制作了一个 pri 文件。

详细考虑一下:

安装程序.pri

QT_DIR = $$dirname(QMAKE_QMAKE)
win32:LUPDATE = $$QT_DIR/lupdate.exe
unix:LUPDATE = $$QT_DIR/lupdate

win32:LRELEASE = $$QT_DIR/lrelease.exe
unix:LRELEASE = $$QT_DIR/lrelease


SUPPORT_LANGS = ru

# this file search function with a specific extension
defineReplace(findFiles) {
    patern = $$1
    path = $$2

    all_files = $$files(*$${patern}, true)
    win32:all_files ~= s|\\\\|/|g
    win32:path ~= s|\\\\|/|g

    for(file, all_files) {
        result += $$find(file, $$path)
    }

    return($$result)
}

# here we get a list of our installer's xml files (since each package must contain its own config.xml, I consider each xml file a potential package)
XML_FILES = $$files(*.xml, true)

# and for each language I support
for(LANG, SUPPORT_LANGS) {
    # i add run lupdate command for all js and ui files of package
    for(XML, XML_FILES) {
        FILE_PATH = $$dirname(XML)

        JS_FILES = $$findFiles(".js", $$FILE_PATH)
        UI_FILES = $$findFiles(".ui", $$FILE_PATH)

        commands += "$$LUPDATE $$JS_FILES $$UI_FILES -ts $$FILE_PATH/$${LANG}.ts"
        TS_FILES += $$FILE_PATH/$${LANG}.ts

    }

    # I also add commands to lrelease for each ts file I created 
    for(TS, TS_FILES) {
        commands += "$$LRELEASE $$TS"
    }
}

# and execute all the accumulated commands 
for(command, commands) {
    system($$command)|error("Failed to run: $$command")
}

您只需将此installer.pri 文件放在安装程序的根目录中,然后将其连接到主pro 文件中

主程序

include($$PWD/installer/installer.pri)

于 2019-05-10T15:05:41.110 回答