- Qt 6.4
- Qt Linguist Manual
- CMake Commands in Qt6 LinguistTools
- qt_add_lrelease
- Qt 6.4.3 Reference Documentation

# qt_add_lrelease

Add targets to 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.

## Synopsis

     qt_add_lrelease(target TS_FILES file1.ts [file2.ts ...]
                     [NO_TARGET_DEPENDENCY]
                     [NO_GLOBAL_TARGET]
                     [QM_FILES_OUTPUT_VARIABLE variable-name]
                     [OPTIONS ...])

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

## Description

Creates a target `${target}_lrelease` to transform `.ts` files into `.qm` files with lrelease.

The parameter `target` is an existing executable or library target that contains sources with translatable strings.

The `.ts` files must be specified with the argument `TS_FILES`.

This function is designed to be used in conjunction with qt_add_lupdate. See also the convenience wrapper qt_add_translations.

## 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")

## Processing Generated .qm Files

To further process the generated `.qm` files, for example to create install rules, `qt_add_lrelease` can store the paths of the `.qm` files in a variable. Pass `QM_FILES_OUTPUT_VARIABLE <variable-name>` to the function for that.

## Build by Default

By default, the command makes `${target}` depend on `${target}_lrelease`. This ensures that the `.qm` files are always up-to-date when `${target}` is built. This behavior can be turned off with `NO_TARGET_DEPENDENCY`. In this case, the user must build the `${target}_lrelease` target manually.

## Umbrella Target

In addition to the target `${target}_lrelease`, an umbrella target `release_translations` is created. This target will build all `${target}_lrelease` targets that were created with `qt_add_lrelease`.

Pass `NO_GLOBAL_TARGET` to `qt_add_lrelease` to prevent this behavior.

The name of this target can be overridden by setting the variable `QT_GLOBAL_LRELEASE_TARGET` before calling `qt_add_lrelease`.

## Examples

Add the targets `myapp_lrelease` and `update_translations` for updating the `.ts` file of an application `myapp`. Also, install the generated `.qm` files.

     qt_add_lrelease(myapp
         TS_FILES myapp_de.ts
         QM_FILES_OUTPUT_VARIABLE qm_files)
     install(FILES ${qm_files} DESTINATION "translations")