From 4c658ce62064f8577708f70df8615461f5a79bc9 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 18 Sep 2023 17:35:49 +0200 Subject: [PATCH] [Translation] Give current locale to locale switcher runWithLocale callback --- src/Symfony/Component/Translation/CHANGELOG.md | 5 +++++ src/Symfony/Component/Translation/LocaleSwitcher.php | 4 ++-- .../Component/Translation/Tests/LocaleSwitcherTest.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) 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()); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy