Skip to content
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

[Translator] Make sure a null locale is handled properly #38127

Merged
merged 1 commit into from Sep 18, 2020

Conversation

jschaedl
Copy link
Contributor

@jschaedl jschaedl commented Sep 9, 2020

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #38124
License MIT
Doc PR -

src/Symfony/Component/Translation/Translator.php Outdated Show resolved Hide resolved
src/Symfony/Component/Translation/Translator.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented Sep 10, 2020

Tests seems broken by this change.

@ro0NL
Copy link
Contributor

ro0NL commented Sep 10, 2020

@jschaedl we need to ensure a fixed default locale still, see e.g. 7fce86f#diff-59203b25094d9f89c0a4abd9864d8a9c

@jschaedl
Copy link
Contributor Author

@ro0NL Thanks for the hint :-)

@jschaedl jschaedl force-pushed the translation-issue-38124 branch 2 times, most recently from 53e2d66 to 1fb1f46 Compare September 16, 2020 16:10
@@ -171,7 +171,7 @@ public function setLocale($locale)
*/
public function getLocale()
{
return $this->locale;
return $this->locale ?: \Locale::getDefault();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Borrowed from https://github.com/symfony/contracts/blob/master/Translation/TranslatorTrait.php#L38 which implies that an empty locale is not a valid locale.

Copy link
Contributor

Choose a reason for hiding this comment

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

if we want to take this route, i would preserve the empty string (as given by the user)

and validate as such in assertValidLocale, rather than silently ignoring it.

I think it's worth a discussion on master.

Copy link
Contributor Author

@jschaedl jschaedl Sep 16, 2020

Choose a reason for hiding this comment

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

I think we could do this:
For now we deprecate the possibility to set en empty locale in 4.4 and stick with $this->locale ?? \Locale::getDefault(); for now and afterwards we add a proper validation in assertValidLocale on master.

WDYT?

Copy link
Contributor

@ro0NL ro0NL Sep 16, 2020

Choose a reason for hiding this comment

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

we cannot add new deprecations in a patch release either :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah true 🙈

@@ -622,7 +650,6 @@ public function getInvalidLocalesTests()
public function getValidLocalesTests()
{
return [
[''],
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we should change this behavior in a patch release :/
the previous ?? \Locale::getDefault() approach was fine no?

Copy link
Contributor Author

@jschaedl jschaedl Sep 16, 2020

Choose a reason for hiding this comment

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

Actually I am not sure too, but good point.

I thought it would be good to have both Translator and TranslatorTrait work the same way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it would be good have both Translator and TranslatorTrait work the same way.

i think that's worth pursuing yes ... on master, then we wait for @nicolas-grekas's review also :)

@jschaedl
Copy link
Contributor Author

@ro0NL I reverted things as discussed.

@fabpot
Copy link
Member

fabpot commented Sep 18, 2020

Thank you @jschaedl.

@fabpot fabpot merged commit 785a066 into symfony:4.4 Sep 18, 2020
@Aliance
Copy link
Contributor

Aliance commented Sep 23, 2020

@fabpot are you planning to release a new version with this fix?

@jschaedl
Copy link
Contributor Author

@Aliance A new patch version comes out at the end of every month.
See: https://symfony.com/doc/current/contributing/community/releases.html

A new Symfony patch version (e.g. 4.4.9, 5.0.9, 5.1.1) comes out roughly every month. It only contains bug fixes, so you can safely upgrade your applications;

You can subscribe for release notifications on this site: https://symfony.com/account/notifications

This was referenced Sep 27, 2020
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.

None yet

7 participants