Add targets to update and transform Qt Linguist .ts files into .qm files.

The command is defined in the LinguistTools component of the Qt6 package. Load the package with:

find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

This command was introduced in Qt 6.2.


qt_add_translations(target TS_FILES file1.ts [file2.ts ...]
                    [RESOURCE_PREFIX [OUTPUT_TARGETS variable-name]]
                    [QM_FILES_OUTPUT_VARIABLE variable-name]

If versionless commands are disabled, use qt6_add_translations() instead. It supports the same set of arguments as this command.

Note: 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.

The parameter 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.

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

By default, the .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 file.

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

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


Add a German translation to a target super_calc using 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)
    TS_FILES super_calc_de.ts
qt_add_resources(super_calc "translations"
    PREFIX "/i18n"
    FILES "${qm_files}")

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

    TS_FILES frogger_game_no.ts
    RESOURCE_PREFIX "/translations")

Add a Finnish translation to business_logic, and install the generated .qm files.

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

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