8000 Review note about setting the translator locale in a controller. · symfony/symfony-docs@1bfc46d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1bfc46d

Browse files
solazsweaverryan
authored andcommitted
Review note about setting the translator locale in a controller.
1 parent af46923 commit 1bfc46d

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
@@ -431,13 +431,13 @@ via the ``request`` object::
431431
$request->setLocale('en_US');
432432
}
433433
434-
435434
.. note::
436435

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

442442
.. tip::
443443

0 commit comments

Comments
 (0)
0