Symfony -- Twig's trans filter not picking up locale
I figured out the answer through Symfony Documentation:
Setting the locale using
$request->setLocale()
in the controller is too late to affect the translator.Either set the locale
- Via a Listener (like above)
- Via the URL (see next)
- Or call
setLocale()
directly on the Translator Service.
I ended up fixing it by changing the priority of the service, like the accepted answer in this thread: Symfony 2.1 set locale
Mabey a late reply but I was facing the same problem, after a bit of reading i found a better solution. You can use the trans function
instead of the trans filter
which seems to be a cleaner solution.
{% trans from "your-trans-domain" into app.user.locale %} trans.key {% endtrans %}
See symfony docs: