move-elevator/composer-translation-validator

A Composer plugin that validates translations files in your project regarding mismatches between language source and target files.

1.0.1 2025-07-17 12:40 UTC

README

Composer Translation Validator

Coverage CGL Tests Supported PHP Versions

A Composer plugin that validates translation files in your project. Provides a command validate-translations to check for translations mismatches, duplicates, schema validation and more. Supports XLIFF, YAML, JSON and PHP translation files.

✨ Features

🔥 Installation

Packagist Packagist Downloads

composer require --dev move-elevator/composer-translation-validator

📊 Usage

Validate your translation files by running the command:

composer validate-translations ./translations

console.png

The command validate-translations can be used to validate translation files in your project. It will automatically detect the translation files based on the supported formats and run the configured validators.

composer validate-translations [<path>...] [--dry-run] [--strict] [--format|-f <cli|json>] [--skip|-s <VALIDATOR>...] [--only|-o <VALIDATOR>...] [--recursive|-r] [--verbose|-v] [--config|-c <CONFIG>]```
Argument / Option Shortcut Description
<path> (Optional) Path to the translation files or directories to validate (can be used multiple times).
--format -f Sets the output format (cli, json).
--skip -s Skips specific validators (can be used multiple times).
--only -o Runs only the specified validators (can be used multiple times).
--recursive -r Search for translation files recursively in subdirectories
--verbose -v Shows additional output for detailed information.
--strict Enables strict mode, treating warnings as errors.
--dry-run Runs the validation in test mode without saving changes.
--config -c Path to a configuration file (e.g. translation-validator.yaml).

Find more information about store a config file.

📝 Documentation

Supported Translation File Formats

The plugin supports the following translation file formats (and targets the following frameworks):

Format Description Framework Example files
XLIFF Supports source/target translations in xliff language files. TYPO3 CMS locallang.xlf, de.locallang.xlf
YAML Supports yaml language files. Symfony messages.en.yaml, messages.de.yaml
JSON Supports JSON language files with nested key support. Laravel / Symfony messages.en.json, messages.de.json
PHP Supports PHP array-based translation files with Laravel and Symfony styles. Laravel / Symfony resources/lang/en/messages.php, translations/messages.en.php

Note

The translation files will be grouped to file sets based on the file name prefix or suffix. For example, locallang.xlf and de.locallang.xlf will be grouped together as they share the same prefix (locallang), while messages.en.yaml and messages.de.yaml will be grouped by their suffix (.en, .de). See the File Detectors for more details.

Translation Validators

The following translation validators are available:

Validator Function Supports Throws
DuplicateKeysValidator This validator checks for duplicate keys in translation files. XLIFF, YAML, JSON, PHP ERROR
DuplicateValuesValidator This validator checks for duplicate values in translation files. XLIFF, YAML, JSON, PHP WARNING
EmptyValuesValidator Finds empty or whitespace-only translation values. XLIFF, YAML, JSON, PHP WARNING
EncodingValidator Validates file encoding, checks for BOM, invisible characters and Unicode normalization issues. XLIFF, YAML, JSON, PHP WARNING
MismatchValidator This validator checks for keys that are present in some files but not in others. It helps to identify mismatches in translation keys across different translation files. XLIFF, YAML, JSON, PHP WARNING
PlaceholderConsistencyValidator Validates placeholder consistency across files. XLIFF, YAML, JSON, PHP WARNING
XliffSchemaValidator Validates the XML schema of translation files against the XLIFF standard. See available schemas. XLIFF ERROR

🧑‍💻 Contributing

Please have a look at CONTRIBUTING.md.

⭐ License

This project is licensed under GNU General Public License 3.0 (or later).