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

Skip to content

[HttpKernel] Use Accept-Language header even if there are no enabled locales #47377

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
Sep 23, 2022

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented Aug 24, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? no
Deprecations? no
Tickets Fix #47355
License MIT
Doc PR N/A

Don’t really know how I should consider this PR 🤔

It would affect people setting set_locale_from_accept_language to true with no enabled_locales when the request has a preferred language:

  • before: set the default locale as request locale
  • after: set the preferred language as request locale

@chalasr
Copy link
Member

chalasr commented Aug 31, 2022

Can you add a test case that breaks before your patch?

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Aug 31, 2022

@chalasr done.

While updating testRequestAttributeLocaleNotOverridenFromAcceptLanguageHeader I stumbled into a weird behavior which I think was caused by the Accept-Language header set the wrong way, so I updated tests doing this.

@MatTheCat MatTheCat force-pushed the ticket_47355 branch 2 times, most recently from c20d409 to 0a81366 Compare September 4, 2022 13:17
@MatTheCat MatTheCat force-pushed the ticket_47355 branch 2 times, most recently from 89c118d to 8a39eeb Compare September 19, 2022 06:23
@fabpot
Copy link
Member

fabpot commented Sep 20, 2022

@MatTheCat Can you create a PR on 4.4 for the tests fix?

@MatTheCat
Copy link
Contributor Author

MatTheCat commented Sep 21, 2022

@fabpot see #47638 (concerned tests were added by #43108 on 5.4). Should I copy its changes on this PR? Else tests will fail until it is merged and rebased 🤔

symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Sep 21, 2022
…ers (MatTheCat)

This PR was merged into the 5.4 branch.

Discussion
----------

[HttpKernel] Fix LocaleListenerTest Accept-Language headers

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix symfony/symfony#47377 (comment)
| License       | MIT
| Doc PR        | N/A

Commits
-------

b6ac197fa4 Fix LocaleListenerTest Accept-Language headers
@chalasr chalasr closed this in 3ad9620 Sep 21, 2022
@chalasr chalasr reopened this Sep 21, 2022
@chalasr
Copy link
Member

chalasr commented Sep 21, 2022

Looks like because #47638's description included "Fix #47377(some comment)", github closed this PR automatically when merging #47638.

Should I copy its changes on this PR? Else tests will fail until it is merged and rebased 🤔

Rebase unlocked, #47638 has been merged up to 6.2.

@MatTheCat
Copy link
Contributor Author

Damn okay sorry 😅

PR rebased!

@chalasr
Copy link
Member

chalasr commented Sep 21, 2022

No worries, I'd say it should be improved on Github :)
Can you please add a small entry in the framework-bundle CHANGELOG?

@MatTheCat
Copy link
Contributor Author

Set locale from request rather that default locale if "framework.enabled_locales" is empty and "framework.set_locale_from_accept_language" is true

WDYT? Don’t really know how to make it shorter.

@chalasr
Copy link
Member

chalasr commented Sep 21, 2022

Works for me!

@fabpot
Copy link
Member

fabpot commented Sep 23, 2022

Thank you @MatTheCat.

@nicolas-grekas
Copy link
Member

I'm a bit late here but this means we are going to always send the Vary: Accept-Language header, isn't it? I'm not sure this is legit.

@MatTheCat MatTheCat deleted the ticket_47355 branch September 23, 2022 08:26
@MatTheCat
Copy link
Contributor Author

MatTheCat commented Sep 23, 2022

@nicolas-grekas only if set_locale_from_accept_language is true and the Accept-Language header contains some locales.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 23, 2022

Oh, thanks. Two other issues: why on 6.2 and not on 6.1? And more importantly: the vary header should also be sent when $preferredLanguage is falsy. The code should look like this:

        } elseif ($this->useAcceptLanguageHeader) {
            if ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales)) {
                $request->setLocale($preferredLanguage);
            }
            $request->attributes->set('_vary_by_language', true);
        }

Can you please send a PR on 6.1 if you agree?

@MatTheCat
Copy link
Contributor Author

I’m not sure about you two questions 😞 so I’ll wait for the approval of other members before submitting another PR.

@chalasr
Copy link
Member

chalasr commented Sep 23, 2022

Nicolas is right, please go ahead if you want/can.

MatTheCat added a commit to MatTheCat/symfony that referenced this pull request Sep 23, 2022
chalasr added a commit that referenced this pull request Sep 23, 2022
…no enabled locales (MatTheCat)

This PR was squashed before being merged into the 6.1 branch.

Discussion
----------

[HttpKernel] Use Accept-Language header even if there are no enabled locales

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #47377
| License       | MIT
| Doc PR        | N/A

Commits
-------

d97d51c [HttpKernel] Use Accept-Language header even if there are no enabled locales
@fabpot fabpot mentioned this pull request Oct 24, 2022
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.

framework.enabled_locales does not behave as documented
5 participants