move-elevator / composer-translation-validator
A Composer plugin that validates translations files in your project regarding mismatches between language source and target files.
Installs: 339
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: ^8.1
- composer-plugin-api: ^1.0 || ^2.0
- ext-libxml: *
- ext-mbstring: *
- ext-simplexml: *
- justinrainbow/json-schema: ^6.4
- psr/log: ^2.0 || ^3.0
- symfony/config: ^5.0 || ^6.0 || ^7.0
- symfony/console: ^5.0 || ^6.0 || ^7.0
- symfony/filesystem: ^5.0 || ^6.0 || ^7.0
- symfony/translation: ^5.0 || ^6.0 || ^7.0
- symfony/yaml: ^5.0 || ^6.0 || ^7.0
Requires (Dev)
- armin/editorconfig-cli: ^1.0 || ^2.0
- composer/composer: ^2.0
- eliashaeussler/rector-config: ^3.0
- ergebnis/composer-normalize: ^2.44
- friendsofphp/php-cs-fixer: ^3.52
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.2 || ^11.0 || ^12.0
- roave/security-advisories: dev-latest
Suggests
- ext-intl: Required for validating translations regarding unicode normalization issues.
- dev-main
- 1.0.1
- 1.0.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-xliff-target-language-fix
- dev-recursive
- dev-readme-adjustments
- dev-phpstan-7
- dev-encoding-validator
- dev-support-php
- dev-json-support
- dev-placeholder-validator
- dev-empty-value-validator
- dev-code-style
- dev-code-improvement
- dev-symfony-5-test
- dev-xliff-schema-1.0
- dev-warning-strict
- dev-config
- dev-parser-cache
- dev-result-message
- dev-statistics
- dev-output-style
- dev-validation-run
- dev-symfony-read-file
- dev-skip-only
- dev-duplicate-values
- dev-result-renderer
- dev-result-type
- dev-rename-duplicates-validator
- dev-format-json
- dev-unit-testing
This package is auto-updated.
Last update: 2025-07-17 12:40:54 UTC
README
Composer Translation Validator
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
- Autodetect coherent language files
- Supports various translation formats
- Provides multiple validators
🔥 Installation
composer require --dev move-elevator/composer-translation-validator
📊 Usage
Validate your translation files by running the command:
composer validate-translations ./translations
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).