Skip to content

Commit 79f5865

Browse files
solazsweaverryan
authored andcommitted
Review note about setting the translator locale in a controller.
1 parent 3b136c8 commit 79f5865

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: book/translation.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ via the ``request`` object::
425425
$request->setLocale('en_US');
426426
}
427427
428-
429428
.. note::
430429

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

436436
.. tip::
437437

0 commit comments

Comments
 (0)