Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@karimmorel
Copy link

@karimmorel karimmorel commented Apr 23, 2024

Q A
Branch 5.4
Bug fix yes
New feature no
Deprecations no
License MIT

When the Accept-Language header is used to set the locale, if it's value is not within the list of enabled_locales, the value for default_locale is overwritten by the first value of the list of enabled_locales.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@rosier
Copy link
Contributor

rosier commented Apr 23, 2024

This looks more like a configuration issue to me. For this feature the order of locales is important.

https://symfony.com/doc/current/translation.html#selecting-the-language-preferred-by-the-user

@Seb33300
Copy link
Contributor

Seb33300 commented Apr 23, 2024

Indeed, just found this in the documentation.

If it can't find a perfect match between them, this method returns the first locale passed as argument (that's why the order of the passed locales is important).

However, this behaviour looks wrong to me.
IMO, if it can't find a perfect match, I think it should return the default locale, not the first of the list.

And this PR fixes the issue by setting the default locale first in the list.

@rosier
Copy link
Contributor

rosier commented Apr 23, 2024

I may be missing something, but can't you put in your config the default as the first value of the list of enabled_locales

@karimmorel
Copy link
Author

I was not aware of that part of the documentation, but when I noticed that behaviour, I thought it was weirdly designed.

default_locale is used to set the locale, while enabled_locales is used to limit it. So to me, it is weird to use enabled_locales to set the locale.

@Seb33300
Copy link
Contributor

@karimmorel you should also open a PR to update the documentation in case this PR is merged:
https://github.com/symfony/symfony-docs/edit/6.4/translation.rst

@Seb33300
Copy link
Contributor

Just realized that the documentation concerns the method getPreferredLanguage() and you did not change that method.
So you dont need to update the doc.

@fabpot fabpot modified the milestones: 5.4, 6.4 Dec 14, 2024
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.

5 participants