qt_add_translations

概要

qt_add_translations(target TS_FILES file1.ts [file2.ts ...]
                    [RESOURCE_PREFIX [OUTPUT_TARGETS variable-name]]
                    [QM_FILES_OUTPUT_VARIABLE variable-name]
                    [SOURCES]
                    [INCLUDE_DIRECTORIES]
                    [LUPDATE_OPTIONS]
                    [LRELEASE_OPTIONS])
					

无版本命令 被禁用,使用 qt6_add_translations() 代替。它支持如此命令的一组相同自变量。

注意: This command is in technology preview and may change in future releases.

描述

Creates targets for updating Qt Linguist .ts files and for transforming them into .qm files. This function is a convenience wrapper around qt_add_lupdate and qt_add_lrelease and aims to offer the most common usage of both functions with one call.

参数 target is an existing executable or library target that contains sources with translatable strings. This function will create the targets ${target}_lupdate , ${target}_lrelease , update_translations and release_translations . The latter targets are umbrella targets that build all ${target}_lupdate and ${target} _lrelease targets.

${target}_lrelease is built automatically whenever ${target} needs to be built.

.ts files must be specified with the argument TS_FILES .

选项

You can set additional options for lupdate and lrelease with LUPDATE_OPTIONS and LRELEASE_OPTIONS . You can find possible options in the translations documentation .

默认情况下, .qm files will be placed in the current build directory ( CMAKE_CURRENT_BINARY_DIR ). To change this, you can set OUTPUT_LOCATION as a property of the source .ts 文件。

For example, with the following code, the .qm files are generated in a translations directory below the current build directory.

set_source_files_properties(app_en.ts app_de.ts
    PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")
					

Embedding Generated .qm Files in Resources

By default, the generated .qm files are embedded in a Qt resource that will be linked into ${target} . The files in the resource are accessible under the resource prefix "/i18n" .

You can set the resource prefix with RESOURCE_PREFIX .

In a static Qt build, when a resource target is created, additional targets can be created. You can instruct qt_add_translations to store these targets in a variable, by passing OUTPUT_TARGETS <variable-name> .

The automatic resource embedding can be turned off by giving the QM_FILES_OUTPUT_VARIABLE option, followed by the name of a variable in which the command should store the list of generated .qm 文件。

范例

Add a German translation to a target super_calc 使用 qt_add_translations .

qt_add_translations(super_calc TS_FILES super_calc_de.ts)
					

This is roughly equivalent to the following.

qt_add_lupdate(super_calc TS_FILES super_calc_de.ts)
qt_add_lrelease(super_calc
    TS_FILES super_calc_de.ts
    QM_FILES_OUTPUT_VARIABLE qm_files)
qt_add_resources(super_calc "translations"
    PREFIX "/i18n"
    BASE "${CMAKE_CURRENT_BINARY_DIR}"
    FILES "${qm_files}")
					

Add a Norwegian translation to frogger_game with a custom resource prefix.

qt_add_translations(frogger_game
    TS_FILES frogger_game_no.ts
    RESOURCE_PREFIX "/translations")
					

Add a Finnish translation to business_logic , and install the generated .qm 文件。

qt_add_translations(business_logic
    TS_FILES myapp_fi.ts
    QM_FILES_OUTPUT_VARIABLE qm_files)
install(FILES ${qm_files} DESTINATION "translations")