Andrei Herford Andrei Herford - 1 month ago 8
Twig Question

Find missing "empty" translation in Symfony project

While checking the logs of my Symfony 2.8 project I came across the following warnings:

Translation not found.
Context: { "id": "", "domain": "messages", "locale": "de" }
Context: { "id": "form_cancel", "domain": "forms", "locale": "de" }


Finding and fixing the code that used the missing
form_cancel
translation was no problem. But how can I find the code that uses the empty
""
translation?


I already tried to use
grep
to find code like
''|trans
, etc. within my templates, without any result.

I think the most likely source of the problem is something like
{{ someVar|trans }}
within a template, where
someVar
is empty / not set. I already search for such code, but also with no result.

Isn't there any option/possibility to get more detailed information about the source the missing translation? Other warning are created with information about the source file and even the line of code. Is it possible to get this information for missing translations as well?

Answer

As explained in the documentation, you can use the console to find the missing translations:

php bin/console debug:translation de AcmeDemoBundle --only-missing

You can also specify the domain you want to search in:

php bin/console debug:translation de AcmeDemoBundle --only-missing --domain=messages