Skip to content

Commit

Permalink
Review note about setting the translator locale in a controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
solazs authored and weaverryan committed Mar 20, 2015
1 parent 3b136c8 commit 79f5865
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions book/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ via the ``request`` object::
$request->setLocale('en_US');
}
.. note::

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

.. tip::

Expand Down

0 comments on commit 79f5865

Please sign in to comment.