How to Find Errors in Translation Files

How to Find Errors in Translation Files

Symfony processes all the application translation files as part of the process that compiles the application code before executing it. If there’s an error in any translation file, you’ll see an error message explaining the problem.

If you prefer, you can also validate the contents of any YAML and XLIFF translation file using the lint:yaml and lint:xliff commands:

  1. # lint a single file
  2. $ php bin/console lint:yaml translations/messages.en.yaml
  3. $ php bin/console lint:xliff translations/messages.en.xlf
  4. # lint a whole directory
  5. $ php bin/console lint:yaml translations
  6. $ php bin/console lint:xliff translations
  7. # lint multiple files or directories
  8. $ php bin/console lint:yaml translations path/to/trans
  9. $ php bin/console lint:xliff translations/messages.en.xlf translations/messages.es.xlf

The linter results can be exported to JSON using the --format option:

  1. $ php bin/console lint:yaml translations/ --format=json
  2. $ php bin/console lint:xliff translations/ --format=json

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.