diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index 70ca19d0dc31a..d82c37d38090c 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.4 +--- + + * Give current locale to `LocaleSwitcher::runWithLocale()`'s callback + 6.3 --- diff --git a/src/Symfony/Component/Translation/LocaleSwitcher.php b/src/Symfony/Component/Translation/LocaleSwitcher.php index 48ef4396f29d8..c07809c58cbcc 100644 --- a/src/Symfony/Component/Translation/LocaleSwitcher.php +++ b/src/Symfony/Component/Translation/LocaleSwitcher.php @@ -55,7 +55,7 @@ public function getLocale(): string * * @template T * - * @param callable():T $callback + * @param callable(string $locale):T $callback * * @return T */ @@ -65,7 +65,7 @@ public function runWithLocale(string $locale, callable $callback): mixed $this->setLocale($locale); try { - return $callback(); + return $callback($locale); } finally { $this->setLocale($original); } diff --git a/src/Symfony/Component/Translation/Tests/LocaleSwitcherTest.php b/src/Symfony/Component/Translation/Tests/LocaleSwitcherTest.php index f75370a063f66..8b8f33a7240ab 100644 --- a/src/Symfony/Component/Translation/Tests/LocaleSwitcherTest.php +++ b/src/Symfony/Component/Translation/Tests/LocaleSwitcherTest.php @@ -66,10 +66,11 @@ public function testCanSwitchLocaleForCallback() $this->assertSame('en', $service->getLocale()); $this->assertSame('en', $switcher->getLocale()); - $switcher->runWithLocale('fr', function () use ($switcher, $service) { + $switcher->runWithLocale('fr', function (string $locale) use ($switcher, $service) { $this->assertSame('fr', \Locale::getDefault()); $this->assertSame('fr', $service->getLocale()); $this->assertSame('fr', $switcher->getLocale()); + $this->assertSame('fr', $locale); }); $this->assertSame('en', \Locale::getDefault());
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: