Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rebase of #4989#5099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
weaverryan wants to merge6 commits into2.6fromsolazs-patch-1
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletionsbook/translation.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -427,17 +427,28 @@ via the ``request`` object::
public function indexAction(Request $request)
{
$locale = $request->getLocale();

$request->setLocale('en_US');
}

.. tip::
To set the user's locale, you may want to create a custom event listener
so that it's set before any other parts of the system (i.e. the translator)
need it::

Read :doc:`/cookbook/session/locale_sticky_session` to learn how to store
the user's locale in the session.
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();

.. index::
single: Translations; Fallback and default locale
// some logic to determine the $locale
$request->getSession()->set('_locale', $locale);
}

Read :doc:`/cookbook/session/locale_sticky_session` for more on the topic.

.. note::

Setting the locale using ``$request->setLocale()`` in the controller
is too late to affect the translator. Either set the locale via a listener
(like above), the URL (see next) or call ``setLocale()`` directly on
the ``translator`` service.

See the :ref:`book-translation-locale-url` section below about setting the
locale via routing.
Expand DownExpand Up@@ -518,6 +529,9 @@ in your application.
Read :doc:`/cookbook/routing/service_container_parameters` to learn how to
avoid hardcoding the ``_locale`` requirement in all your routes.

.. index::
single: Translations; Fallback and default locale

Setting a default Locale
~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp