Skip to content

Commit 94914c5

Browse files
committed
Review note about setting the translator locale in a controller.
1 parent b7f7421 commit 94914c5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

book/translation.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,13 @@ via the ``request`` object::
429429
$request->setLocale('en_US');
430430
}
431431
432-
433432
.. note::
434433

435-
Setting the locale using ``$request->setLocale()`` won't affect rendering
436-
in the same action as the translator reads the request locale during the
437-
kernel.request event, so changing it here would be too late. To manually
438-
change translation locale in the controller use ``$this->get('translator')->setLocale()``.
434+
Setting the locale using the ``$request->setLocale()`` method won't affect
435+
rendering in the same action. The translator locale is set during the
436+
kernel.request event. Either set the locale before the listener is called
437+
(e.g. in a custom listener) or use the ``setLocale()`` method of the
438+
``translator`` service.
439439

440440
.. tip::
441441

0 commit comments

Comments
 (0)