在本页中

使用 lrelease-pro

lrelease-pro 命令行工具可从 qmake 项目(.pro 文件)生成 QM 文件。它从项目文件中读取TRANSLATIONS 变量,并生成相应的 QM 文件。

如果您有一个 qmake 项目,并希望根据 .pro 文件中定义的翻译生成 QM 文件,请使用lrelease-pro

lrelease-pro 语法

lrelease-pro [options] [project-file]...

其中:

要查看最新帮助,请输入

lrelease-pro -help

lrelease-pro 选项

选项操作
-help显示最新帮助信息并退出。
-dump-json <file>生成 JSON 项目描述文件,而不生成 QM 文件。该文件可通过-project 选项传递给lrelease
-silent不解释正在做什么。
-removeidentical如果翻译的文本与源代码文本相同,则排除该信息。
-fail-on-unfinished如果发现未完成的翻译,则生成错误。
-fail-on-invalid如果发现翻译未通过以下检查,则失败:
  • 加速器的有效性检查
  • 周围空白的有效性检查
  • 结尾标点符号的有效性检查
  • 位置标记的有效性检查

如需了解更多详情,请参阅Qt Linguist 帮助

-nounfinished不包含未完成的翻译。
-markuntranslated <prefix>如果一条信息没有真正的翻译,则使用以给定字符串为前缀的源文本。
-version显示lrelease-pro 的版本并退出。

示例

从 qmake 项目生成 QM 文件

lrelease-pro myproject.pro

生成 JSON 项目描述

生成描述项目翻译的 JSON 文件:

lrelease-pro myproject.pro -dump-json project.json

然后在lrelease 中使用生成的 JSON 文件:

lrelease -project project.json

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