本页面

qt_deploy_translations

部署可执行文件所需的 Qt 翻译。

该命令定义在Qt6 包的Core 组件中,可按以下方式加载:

find_package(Qt6 REQUIRED COMPONENTS Core)

与 Qt 提供的其他大多数 CMake 命令不同,qt_deploy_translations() 只能在部署脚本中调用。项目在配置阶段无法直接调用该命令。

该命令于 Qt 6.5 中引入。

注意: 通常无需直接调用此 命令。它由其他更高层次的命令在内部使用,但希望实现更定制化部署逻辑的项目可能会发现它很有用。

语法

qt_deploy_translations(
    [CATALOGS catalogs]
    [LOCALES locales]
    [LCONVERT lconvert_executable]
    [VERBOSE]
)

描述

在安装应用程序时,可能需要一并安装所用 Qt 模块对应的本地化文件。qt_deploy_translations 命令会从 Qt 安装目录中收集必要的.qm 文件,并将它们按语言编译成单个qt_${language}.qm 文件。生成的.qm 文件将安装到QT_DEPLOY_TRANSLATIONS_DIR 目录下。

参数

LOCALES 参数用于指定应为哪些语言环境部署翻译。该参数应为语言/地区组合的列表,具体格式请参阅Qt Linguist 翻译者手册中的说明。有效的语言环境示例包括:de 、pl 或pt_BR 。

如果省略LOCALES ,则将部署所有可用的语言环境。

CATALOGS 参数指定要部署的翻译目录列表。如果省略此参数,则会部署所有通过find_package 在项目中使用的 Qt 模块所属的翻译目录。

LCONVERT 参数指定用于合并翻译目录的lconvert 可执行文件。默认情况下,使用 Qt 安装目录下的lconvert 。

出于调试目的,可设置VERBOSE 参数以启用诊断信息。

示例

以下示例部署了 Qt 库的丹麦语和德语翻译。

qt_deploy_translations(
    LOCALES da de
)

另请参阅 QT_DEPLOY_TRANSLATIONS_DIR。

© 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.