From 41277a162fa2ae4672cfcf29f76916ba0b0905e1 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 20 Sep 2023 13:35:10 +0200 Subject: [PATCH] [Translation] Give current locale to LocaleSwitcher::runWithLocale()'s callback --- translation.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/translation.rst b/translation.rst index 3d8bfb8a519..58c0112360c 100644 --- a/translation.rst +++ b/translation.rst @@ -1069,10 +1069,25 @@ of: }); + // you can optionally declare an argument in your callback to receive the + // injected locale + $this->localeSwitcher->runWithLocale('es', function(string $locale) { + + // here, the $locale argument will be set to 'es' + + }); + // ... } } +.. versionadded:: 6.4 + + The support of declaring an argument in the callback to inject the locale + being used in the + :method:`Symfony\\Component\\Translation\\LocaleSwitcher::runWithLocale` + method was introduced in Symfony 6.4. + When using :ref:`autowiring `, type-hint any controller or service argument with the :class:`Symfony\\Component\\Translation\\LocaleSwitcher` class to inject the locale switcher service. Otherwise, configure your services