8000 feature #47377 [HttpKernel] Use Accept-Language header even if there … · symfony/symfony@4a97318 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a97318

Browse files
committed
feature #47377 [HttpKernel] Use Accept-Language header even if there are no enabled locales (MatTheCat)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [HttpKernel] Use Accept-Language header even if there are no enabled locales | 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 Commits ------- b20d074 [HttpKernel] Use Accept-Language header even if there are no enabled locales
2 parents 8eeea16 + b20d074 commit 4a97318

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ CHANGELOG
1818
`workflow.state_machine`
1919
* Add `rate_limiter` configuration option to `messenger.transport` to allow rate limited transports using the RateLimiter component
2020
* Remove `@internal` tag from secret vaults to allow them to be used directly outside the framework bundle and custom vaults to be added
21-
* Deprecate "framework.form.legacy_error_messages" config node
21+
* Deprecate `framework.form.legacy_error_messages` config node
22+
* Set locale from request rather than default locale if `framework.enabled_locales` is empty and `framework.set_locale_from_accept_language` is true
2223

2324
6.1
2425
---

src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function setLocale(Request $request)
6868
{
6969
if ($locale = $request->attributes->get('_locale')) {
7070
$request->setLocale($locale);
71-
} elseif ($this->useAcceptLanguageHeader && $this->enabledLocales && ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales))) {
71+
} elseif ($this->useAcceptLanguageHeader && ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales))) {
7272
$request->setLocale($preferredLanguage);
7373
$request->attributes->set('_vary_by_language', true);
7474
}

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function testRequestNoLocaleFromAcceptLanguageHeader()
179179

180180
$listener->setDefaultLocale($event);
181181
$listener->onKernelRequest($event);
182-
$this->assertEquals('de', $request->getLocale());
182+
$this->assertEquals('fr_FR', $request->getLocale());
183183
}
184184

185185
public function testRequestAttributeLocaleNotOverridenFromAcceptLanguageHeader()

0 commit comments

Comments
 (0)
0