Skip to content

Commit ff77282

Browse files
bug symfony#54468 [Translation] Fix LocaleSwitcher throws when intl not loaded (smnandre)
This PR was merged into the 6.4 branch. Discussion ---------- [Translation] Fix LocaleSwitcher throws when intl not loaded | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix issue [1505](symfony/demo#1505) (from Symfony demo) | License | MIT LocaleSwitcher::setDefault() throw an exception when intl is not installed > "The Symfony\Polyfill\Intl\Icu\Locale::setDefault() is not implemented. Please install the "intl" extension for full localization capabilities." Fixed by following `@stof` suggestion > Symfony should ignore this in the LocaleSwitcher, as already done in \Symfony\Component\HttpFoundation\Request::setLocale Commits ------- eff5e3c [Translation] Silence error when intl not loaded
2 parents ec6da07 + eff5e3c commit ff77282

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/Translation/LocaleSwitcher.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public function __construct(
3434

3535
public function setLocale(string $locale): void
3636
{
37-
if (class_exists(\Locale::class)) {
38-
\Locale::setDefault($locale);
37+
// Silently ignore if the intl extension is not loaded
38+
try {
39+
if (class_exists(\Locale::class, false)) {
40+
\Locale::setDefault($locale);
41+
}
42+
} catch (\Exception) {
3943
}
44+
4045
$this->locale = $locale;
4146
$this->requestContext?->setParameter('_locale', $locale);
4247

0 commit comments

Comments
 (0)