使用 lconvert
lconvert
命令行工具可过滤和转换翻译数据文件。
它支持以下文件格式
pot
- GNU Gettext 本地化模板文件qph
-Qt Linguist 短语集ts
- Qt 翻译源代码po
- GNU Gettext 本地化文件qm
- 编译的 Qt 翻译xlf
- XLIFF 本地化文件
lconvert 语法
lconvert [options] <infile> [<infile>...]
其中
options
指一个或多个lconvert 选项。infile
是一个输入文件。可以指定多个输入文件。
如果指定多个输入文件,它们将被合并,并优先使用后面文件中的翻译。
要查看最新的lconvert
帮助,请输入
lconvert -help
lconvert options
选项 | 操作 |
---|---|
-h -help | Display up-to-date help information and exit. |
-i <infile> -input-file <infile> | Specify an input file. Use this option if <infile> starts with a dash. Use this option several times to merge inputs. May be - (standard input) for use in a pipe. |
-o <outfile> -output-file <outfile> | Specify an output file. Default is - (standard output). |
-if <informat> -input-format <format> | Specify input format for subsequent input files. The format is auto-detected from the file name and defaults to ts . |
-of <outformat> -output-format <outformat> | Specify output format. See -if . |
-drop-tags <regexp> | 在写入TS 或XLIFF 文件时,去掉已命名的额外标记。可以重复指定该选项。 |
-drop-translations | 删除现有翻译并将状态重置为unfinished 。这意味着--no-obsolete 。 |
-source-language <language>[_<region>] | 指定/覆盖源字符串的语言。如果未指定,且文件尚未命名,则默认为 POSIX。 |
-target-language <language>[_<region>] | 指定或覆盖翻译语言。默认情况下,目标语言从文件内容读取或从文件名猜测。 |
-no-obsolete | 删除过时的信息。 |
-no-finished | 删除已完成的信息。 |
-no-untranslated | 删除未翻译的信息。 |
-sort-contexts | 按字母顺序排序输出TS 文件中的上下文。 |
-sort-messages | 按字母顺序排序TS 文件中上下文的信息。 |
-locations {absolute|relative|none} | 覆盖TS 文件中源代码引用的保存方式。默认值为absolute 。 |
-no-ui-lines | 删除UI 文件引用中的行号。 |
-pluralonly | 删除非复数形式的信息。 |
-verbose | 解释正在做什么。 |
示例
将 TS 文件转换为 XLIFF
要将单个 TS 文件转换为 XLIFF,请在终端运行以下命令:
lconvert -o myapp_de.xlf myapp_de.ts
合并多个 QM 文件
以下命令将多个 QM 文件合并为full_de.qm
:
lconvert -o full_de.qm qtbase_de.qm myapp_de.qm mylib_de.qm
在 CMake 中使用 lconvert
要在配置或构建 CMake 项目时调用lconvert
,请加载Qt6LinguistTools
软件包,并使用$<TARGET_FILE_NAME:Qt6::lconvert>
查找lconvert
可执行文件。
下面的示例添加了一个自定义目标xlf_de
,可将单个 TS 文件转换为 XLIFF。
find_package(Qt6 REQUIRED COMPONENTS LinguistTools) add_custom_command( OUTPUT myapp_de.xlf COMMAND $<TARGET_FILE:Qt6::lconvert> -o myapp_de.xlf myapp_de.ts DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.ts" VERBATIM ) add_custom_target(xlf_de DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.xlf" )
© 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.