- Qt 6.11
- Qt Linguist Manual
- Using lconvert
- Qt 6.11.1 Reference Documentation

Using lrelease-pro ◦ Using lcheck

# Using lconvert

The `lconvert` command line tool filters and converts translation data files.

It supports the following file formats:

- `pot` - GNU Gettext localization template files
- `qph` - Qt Linguist Phrase Book
- `ts` - Qt translation sources
- `po` - GNU Gettext localization files
- `qm` - Compiled Qt translations
- `xlf` - XLIFF localization files

## lconvert syntax

     lconvert [options] <infile> [<infile>...]

Where:

- `options` means one or several lconvert options.
- `infile` is an input file. You can specify multiple input files.

If you specify multiple input files, they are merged with translations from later files taking precedence.

To view the latest `lconvert` help, enter:

     lconvert -help

### lconvert options

Option | Action
--- | ---
`-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>` | Drop named extra tags when writing `TS` or `XLIFF` files. You can specify this option repeatedly.
`-drop-translations` | Drop existing translations and reset the status to `unfinished`. That implies `--no-obsolete`.
`-source-language <language>[_<region>]` | Specify/override the language of the source strings. Defaults to POSIX if not specified and the file does not name it yet.
`-target-language <language>[_<region>]` | Specify or override the language of the translation. By default, the target language is read from the file content or guessed from the file name.
`-no-obsolete` | Drop obsolete messages.
`-no-finished` | Drop finished messages.
`-no-untranslated` | Drop untranslated messages.
`-sort-contexts` | Sort contexts in the output `TS` file alphabetically.
`-sort-messages` | Sort messages in a context alphabetically in `TS` files.
`-locations {absolute|relative|none}` | Override how source code references are saved in `TS` files. Default is `absolute`.
`-no-ui-lines` | Drop line numbers from references to `UI` files.
`-pluralonly` | Drop non-plural form messages.
`-verbose` | Explain what is being done.

## Examples

### Convert TS file to XLIFF

To convert a single TS file to XLIFF, run the following command in the terminal:

     lconvert -o myapp_de.xlf myapp_de.ts

### Merge multiple QM files

The following command merges multiple QM files into `full_de.qm`:

     lconvert -o full_de.qm qtbase_de.qm myapp_de.qm mylib_de.qm

### Using lconvert with CMake

To call `lconvert` when configuring or building your CMake project, load the `Qt6LinguistTools` package and use `$<TARGET_FILE_NAME:Qt6::lconvert>` for locating the `lconvert` executable.

The following example adds a custom target `xlf_de` that converts a single TS file to 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"
     )

## PO format-specific options

When converting to PO format, you can disable automatic line wrapping by setting the `no-wrap` flag in the `po-flags` extra metadata field. By default, lines longer than 79 characters are wrapped. Set this field in source code using the //~ meta string (for example, `//~ po-flags no-wrap`) or directly in TS files using the `<extra-po-flags>` element.

Other PO flags (see the GNU gettext documentation) are preserved when converting between TS and PO formats but do not affect `lconvert` processing.

Note: The `po-flags` metadata is only preserved when converting directly from TS to PO format.

Using lrelease-pro ◦ Using lcheck