Linters are static code analysis tools used to flag errors like syntactic and
stylistic issues. Symfony includes many linter commands to check YAML config files
(lint:yaml
), container services (lint:container
), Twig templates
(lint:twig
) and even the syntax of XLIFF translation files (lint:xliff
).
In Symfony 7.2 we're adding a new linter to check the content of translations.
Unlike the lint:xliff
command, this new lint:translations
command checks
all your translations, no matter which of the supported translation formats
you use:
1 2 3 4
$ php bin/console lint:translations
# you can also lint only some of the supported locales
$ php bin/console lint:translations --locale=en --locale=tr
This command will be especially helpful when using the ICU MessageFormat syntax
in your translations. This syntax is powerful but sometimes tricky, so it's common
to miss closing braces (}
), forget about the other
key when using plurals, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ php bin/console lint:translations
--------- -------------------------------- --------
Locale Domains Valid?
--------- -------------------------------- --------
ar validators, security, messages Yes
bn messages, validators No
de validators, security, messages Yes
en validators, security, messages Yes
es validators, security, messages Yes
tr validators, security, messages Yes
--------- -------------------------------- --------
Errors for locale "bn" and domain "messages"
--------------------------------------------
Translation key "post.num_comments" is invalid:
[ERROR] Invalid message format (error #65807): msgfmt_create: message formatter
creation failed: U_DEFAULT_KEYWORD_MISSING
Thank you for your efforts!
This will be a significant addition to assessing the code quality of my projects.
The way I usually do it is this:
In the
composer.json
I define: