创建翻译文件

应用程序中需要翻译的文本大多由单词或短语组成。这些文本通常显示为窗口标题、菜单项、工具提示以及按钮、复选框和单选按钮的标签。

开发人员在 QML 和 C++ 源代码中将短语标记为可翻译。Qt 工具会为每个短语提供上下文信息,帮助翻译人员理解其含义。开发人员可为短语添加注释。

翻译文件包括应用程序中所有用户可见的文本和Ctrl快捷键,以及这些文本的译文。

创建翻译文件

  1. 运行lupdate 生成第一套翻译源 (TS) 文件,其中包含所有用户可见文本,但没有翻译。
  2. 将 TS 文件交给翻译人员,由他们使用Qt Linguist 添加翻译。Qt Linguist 表示已更改和删除的源文本。
  3. 运行lupdate ,将添加到应用程序中的任何新文本纳入其中。lupdate 将应用程序中的用户可见文本与译文同步。保留 TS 文件中的现有翻译。
  4. 运行lrelease 可读取 TS 文件,并生成应用程序在运行时使用的 QM 文件。

要使lupdate 成功运行,它必须知道要生成哪些翻译文件。在应用程序的 Qt 项目文件中指定这些文件。

在使用 CMake 构建时,您可以使用CMake 命令来添加创建或更新 TS 文件的目标,并将它们转换为 QM 文件。翻译文件将在构建目标时生成。

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