Skip to content

[Translation] Wrap call to \Locale::setDefault from LocaleSwitcher in a class_exists call #49609

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

larowlan
Copy link
Contributor

@larowlan larowlan commented Mar 6, 2023

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets N/a - see below
License MIT
Doc PR n/a

In #45793 a new LocaleSwitcher was added which uses the \Locale class from ext-intl.
On upgrading an English only project from 5.4 to 6.2, I received the following error as we don't have the ext-intl extension

Error: Class "Locale" not found

I searched for previous PRs to add a dependency on ext-intl and came across one for the string component directing the user to install a polyfill.

Should symfony/translation therefore depend on the polyfill - otherwise updating is broken without manually installing the polyfill?

If so, here's a PR for that.

Keep up the good work folks ❤️

@carsonbot carsonbot added this to the 6.2 milestone Mar 6, 2023
@carsonbot carsonbot changed the title Add dependency on symfony/polyfill-intl-icu to symfony/translation [Translation] Add dependency on symfony/polyfill-intl-icu to symfony/translation Mar 6, 2023
@derrabus derrabus changed the title [Translation] Add dependency on symfony/polyfill-intl-icu to symfony/translation [Translation] Add dependency on symfony/polyfill-intl-icu Mar 6, 2023
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me.

@nicolas-grekas
Copy link
Member

What about wrapping the call to \Locale::setLocale() in a class_exists() check instead?

@derrabus
Copy link
Member

derrabus commented Mar 6, 2023

What about wrapping the call to \Locale::setLocale() in a class_exists() check instead?

You mean \Locale::setDefault()? You're right, if there's no Locale class, there's no reason to mutate the default locale here. And the locale switcher would work very well without it.

Let's do that instead.

@larowlan
Copy link
Contributor Author

larowlan commented Mar 6, 2023

No worries, will update

@larowlan larowlan changed the title [Translation] Add dependency on symfony/polyfill-intl-icu [Translation] Wrap call to \Locale::setDefault from LocaleSwitcher in a class_exists call Mar 7, 2023
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed @derrabus comment

@nicolas-grekas
Copy link
Member

Thank you @larowlan.

@nicolas-grekas nicolas-grekas merged commit fa72214 into symfony:6.2 Mar 7, 2023
@larowlan
Copy link
Contributor Author

larowlan commented Mar 7, 2023

Oh right I missed it was assigning too 🙂

Thanks!

@larowlan larowlan deleted the patch-4 branch March 7, 2023 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants