Using lcheck | Qt Linguist Manual

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

Using lconvert ◦ Using ltext2id

# Using lcheck

The `lcheck` command line tool validates Qt `TS` translation files and produces a human-readable report. It is part of the Qt Linguist toolchain and is intended for batch or CI usage to catch common localization issues early. By default, `lcheck` runs a set of checks and returns a non-zero exit code if at least one enabled check fails.

The default checks are:

- Accelerator check — Verifies that the number of ampersands (mnemonics) in source and translation match.
- Surrounding whitespace check — Verifies that leading and trailing whitespace of source and translation match.
- Ending punctuation check — Verifies that source and translation end with the same punctuation.
- Place marker check — Verifies consistent usage of `%1`, `%2`, and so on, between source and translation.

Each check can be disabled individually using command line options.

## lcheck syntax

     lcheck [options] -o report-output-file ts-file
     lcheck [options] ts-file

Where:

- `options` means one or several lcheck options.
- `ts-file` is the `TS` file to validate.
- `report-output-file` is the path of the file to write the report to. If omitted, the report is written to the standard error stream.

To view the latest help, enter:

     lcheck -help

### lcheck options

Option | Action
--- | ---
`-help` | Display up-to-date help information and exit.
`-no-accelerator` | Disable the accelerator (ampersand) consistency check.
`-no-punctuation` | Disable the ending punctuation consistency check.
`-no-place-marker` | Disable the check that ensures `%1`, `%2`, … are used consistently between source and translation.
`-no-whitespaces` | Disable the surrounding whitespace consistency check.
`-check-finished` | Also check messages marked as finished. By default, finished translations are not checked.
`-o <outfile>` | Write the validation report to `<outfile>`. If not specified, the report is written to standard error.
`-version` | Display the version of `lcheck` and exit.

Note: The process exit status is non-zero if any enabled check fails. This makes `lcheck` suitable for use in CI pipelines.

## Examples

### Write a report to a file

     lcheck -o lcheck_report.txt translations/myapp_de.ts

### Disable selected checks

The following command runs all checks except accelerator and punctuation:

     lcheck -no-accelerator -no-punctuation translations/myapp_de.ts

### Check finished translations as well

     lcheck -check-finished translations/myapp_de.ts

### Use lcheck in a CI step

     lcheck translations/myapp_de.ts && echo "Translations OK" || echo "Issues found"

### Using lcheck with CMake

To call `lcheck` when configuring or building your CMake project, load the `Qt6LinguistTools` package and use `$<TARGET_FILE:Qt6::lcheck>` to locate the `lcheck` executable.

The following example adds a custom target `check_translations` that runs `lcheck` over a TS file and writes a report next to the build artifacts.

     find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

     add_custom_command(
         OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
         COMMAND $<TARGET_FILE:Qt6::lcheck>
                 -o "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
                 "${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
         DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
         VERBATIM
     )

     add_custom_target(check_translations
         DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
     )

### Using lcheck with qmake

You can run `lcheck` directly on a TS file without specifying a project file:

     lcheck translations/myapp_de.ts

Using lconvert ◦ Using ltext2id