qt_create_translation
设置Qt Linguist 翻译工具链。
该命令在Qt6
软件包的LinguistTools
组件中定义。用以下命令加载软件包
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
警告: 此函数已过时。请考虑使用基于目标的函数qt6_add_lupdate或qt6_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 XML 翻译,并使用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)
© 2025 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.