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

Merged
fabpot merged 1 commit into
symfony:6.2from
MatTheCat:ticket_47355
Sep 23, 2022
Merged

[HttpKernel] Use Accept-Language header even if there are no enabled locales#47377
fabpot merged 1 commit into
symfony:6.2from
MatTheCat:ticket_47355

Conversation

@MatTheCat

@MatTheCat MatTheCat commented Aug 24, 2022

Copy link
Copy Markdown
Contributor
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

chalasr commented Aug 31, 2022

Copy link
Copy Markdown
Member

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

@MatTheCat

MatTheCat commented Aug 31, 2022

Copy link
Copy Markdown
Contributor Author

@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

fabpot commented Sep 20, 2022

Copy link
Copy Markdown
Member

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

@MatTheCat

MatTheCat commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

@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

chalasr commented Sep 21, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

Damn okay sorry 😅

PR rebased!

@chalasr

chalasr commented Sep 21, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

chalasr commented Sep 21, 2022

Copy link
Copy Markdown
Member

Works for me!

Comment thread src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md Outdated
@fabpot

fabpot commented Sep 23, 2022

Copy link
Copy Markdown
Member

Thank you @MatTheCat.

@nicolas-grekas

Copy link
Copy Markdown
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

MatTheCat commented Sep 23, 2022

Copy link
Copy Markdown
Contributor Author

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

@nicolas-grekas

nicolas-grekas commented Sep 23, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

chalasr commented Sep 23, 2022

Copy link
Copy Markdown
Member

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