symfony twig translation not working after update

感情迁移 提交于 2020-01-14 05:21:07

问题


I upgraded my project from 2.5.x to 2.8.1 and suddenly twig is not using the correct translations anymore.

In the twig template i have something like this: {% trans %}something.abc{% endtrans %}

my config.yml looks like this:

...
framework:
    translator:      ~
...
templating:
    engines: ['twig']
default_locale:  en_US

in Controller action:

$request->setLocale('nl_BE');

The page is always showing the en_US translation and never something else.

Did something change?


回答1:


It is because the TranslatorListener (which was added in 2.6) sets the locale before the action is called in your controller. Use $this->get('translator')->setLocale('nl_BE'); instead, if you want to change the locale in your controller.



来源:https://stackoverflow.com/questions/34981732/symfony-twig-translation-not-working-after-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!