问题
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