本页内容

qt_create_translation

设置Qt Linguist 翻译工具链。

该命令定义在Qt6 包的LinguistTools 组件中。使用以下命令加载该包:

find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

警告:此 函数已弃用。建议改用基于目标的函数qt_add_lupdate()或qt_add_translations()。

语法

qt_create_translation(<VAR> ts-file-or-sources [ts-file-or-sources2 ...]
                      [OPTIONS ...])

如果禁用了无版本号的命令,请改用qt6_create_translation 。它支持与本命令相同的参数集。

描述

处理给定的源文件(目录或单个文件)以生成Qt Linguist 和.ts 文件。随后,.ts 文件会被编译成具有相同基名的.qm 文件,并存储在构建目录中。生成的.qm 文件的路径会被添加到<VAR> 中。

需要创建或更新的翻译文件必须带有.ts 后缀。如果给定的文件路径不是绝对路径,则将其解析为相对于当前源目录的相对路径。如果未将.ts 文件作为参数传递,则该宏不执行任何操作。

任何不带.ts 后缀的参数都将作为输入传递给lupdate 。lupdate 接受目录和源文件作为输入。有关更多详细信息,请参阅lupdate的文档。

选项

您可以设置在调用lupdate 时应传递的额外OPTIONS 。可在lupdate 文档中查阅可用选项。

示例

从当前目录的源文件中递归查找 Qt 翻译,并使用lupdate 生成或更新helloworld_en.ts 和helloworld_de.ts 文件。将上述文件编译为构建目录中的helloworld_en.qm 和helloworld.de.qm 文件:

qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} helloworld_en.ts helloworld_de.ts)

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.