Skip to content

Commit b7f7421

Browse files
committed
Update translation.rst
Clarify that changing the locale in the controller would not affect template rendering as the translator reads the request locale during the kernel.request event.
1 parent 6ba90ec commit b7f7421

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

book/translation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ via the ``request`` object::
428428

429429
$request->setLocale('en_US');
430430
}
431+
432+
433+
.. note::
434+
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()``.
431439

432440
.. tip::
433441

0 commit comments

Comments
 (0)