使用 lrelease

lrelease 命令行工具从 TS 文件生成 QM 文件。QM 文件格式是本地化应用程序使用的一种紧凑型二进制格式。它能提供极快的翻译查找速度。

使用 qmake 制作时,请在命令行或 .pro 文件中指定要处理的文件。

使用 CMake 构建时,使用CMake 命令添加创建或更新 TS 文件的目标,并将其转换为 QM 文件。在构建目标时,lrelease 工具会根据您传递给命令的选项运行。

只要您想发布应用程序,从最初的测试版本到最终的发布版本,都可以运行lrelease 。程序运行不需要 QM 文件,但如果有 QM 文件,程序会自动检测并使用它们。

注意: lrelease 工具只包含您标记为已完成的翻译。否则,它将使用原文。

lrelease 语法

lrelease [options] -project project-file
lrelease [options] ts-files [-qm qm-file]

其中

  • options 指一个或多个lrelease 选项
  • project-file 是项目配置文件。
  • ts-files 是作为 QM 文件输入的 TS 文件。
  • qm-file 是要生成的 QM 文件的名称。

注意: 将 .pro 文件传递给lrelease 已被弃用。使用 qmake 时,请使用lrelease-pro 工具或lrelease.prf 功能。

要查看最新帮助,请输入

lrelease -help

lrelease options

选项操作
-help显示最新帮助信息并退出。
-idbased使用 ID 代替源字符串进行信息键入。
-compress压缩 QM 文件。
-nounfinished不包含未完成的翻译。
-removeidentical如果翻译文本与源代码文本相同,则排除该信息。
-markuntranslated <prefix>如果信息没有真正的翻译,则使用以给定字符串为前缀的源文本。
-project <filename>包含项目描述的 JSON 格式文件的名称。您可以使用lprodump 工具从 .pro 文件生成该文件。
-silent不要解释正在做什么。
-version显示lrelease 的版本并退出。

示例

在 CMake 中使用 lrelease

使用 CMake 进行编译时,使用CMake 命令将目标的翻译添加到 CMakeLists.txt 文件,然后编译目标。

选择以下选项之一:

构建目标(例如app_lrelease )以更新其 .qm 文件。要更新所有目标的 .qm 文件,请构建目标release_translations

在 qmake 中使用 lrelease

运行lrelease 而无需指定项目文件:

lrelease.exe main_en.ts languages\main_fr.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.