- Qt 6.8
- Qt Linguist Manual
- CMake Commands in Qt6 LinguistTools
- qt_add_translation
- Qt 6.8.0 Reference Documentation

# qt_add_translation

Compiles 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)

Warning: This function is deprecated. Consider using the target-based functions qt6_add_lrelease or qt6_add_translations instead.

## Synopsis

     qt_add_translation(<VAR> file1.ts [file2.ts ...]
                         [OPTIONS ...])

If versionless commands are disabled, use `qt6_add_translation` instead. It supports the same set of arguments as this command.

## Description

Calls `lrelease` on each `.ts` file passed as an argument, generating `.qm` files. The paths of the generated files are added to `<VAR>`.

## Options

You can set additional `OPTIONS` that should be passed when `lrelease` is invoked. You can find possible options in the lrelease 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
         PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")

## Examples

Generating `helloworld_en.qm`, `helloworld_de.qm` in the build directory:

     qt_add_translation(qmFiles helloworld_en.ts helloworld_de.ts)

Generating `helloworld_en.qm`, `helloworld_de.qm` in a `l10n` sub-directory:

     set(TS_FILES helloworld_en.ts helloworld_de.ts)
     set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "l10n")
     qt_add_translation(qmFiles ${TS_FILES})