Saman Mohamadi Saman Mohamadi - 9 months ago 51
PHP Question

Symfony Translation not work

I've override FosUser profile templates in

app/Resources/FosUserBundle


Every thing is ok but translations not working!.

example:

in
app/Resources/translations/messages.en.yml
:


foo.bar: baz


in
app/Resources/FosUserBundle/views/Profile/show_contect.html.twig


{{ 'foo.bar' | trans }} --> output: foo.bar


and there is no problem with locale:
app.request.locale
-->
en


$ php bin/console debug:translation en


enter image description here

Answer Source

Has suggested by @gp_sflover symfony is not using the default messages catalog for manage the template, so you can add the new files FOSUserBundle.en.yml with the translation of force the trans filter to use the messages catalog as follow:

 {{ 'foo.bar' | |trans({}, 'messages') }}

Hope this help