Description
For CI purposes it would be nice to have an easy way to check if there are any translation keys found in the source code that are missing in the translation file(s) for a particular locale. The command should return a non-zero exit code if translations are missing. Ideally it would also fail on translations that exist but only contain an empty string.
For example:
If one of my Twig templates contains the following:
{{ 'message.foo'|trans }}
But translations/messages.en.xlf
does NOT contain message.foo
, and I run bin/console translation:check en
, it should output that the translation is missing and return a non-zero exit code.
I could then run this check for instance in pull request builds to enforce that the author of the pull request provides an English source translation.
Our current solution to achieve this is based on the existing bin/console translation:extract
:
exit $(expr $(bin/console translation:extract --hide-errors | grep 'New messages' | cut -c25-28))
but this is obviously quite fragile and will break if the output of translation:extract
is changed. Also, if the translation of message.foo
already exists but is an empty string, it doesn't break the build.