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

Skip to content

framework.enabled_locales does not behave as documented #47355

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

Closed
lazka opened this issue Aug 22, 2022 · 2 comments · Fixed by #47377
Closed

framework.enabled_locales does not behave as documented #47355

lazka opened this issue Aug 22, 2022 · 2 comments · Fixed by #47377

Comments

@lazka
Copy link

lazka commented Aug 22, 2022

Symfony version(s) affected

5.4.11

Description

https://symfony.com/doc/5.4/reference/configuration/framework.html#enabled-locales states that "empty array = enable all locales", but if I set an empty array then set_locale_from_accept_language will not set the locale. I have to fill enabled_locales for it to work.

Here is the code doing this:

} elseif ($this->useAcceptLanguageHeader && $this->enabledLocales && ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales))) {
which was added in #43108 ($this->enabledLocales is checked to be non-empty)

@chalasr is this logic on purpose? Or does the documentation need adjustment that empty means no locale is enabled?

How to reproduce

Run the following I guess:

public function testRequestNoLocaleFromAcceptLanguageHeader()

which tests that no locale is set if enabled_locales isn't set

Possible Solution

No response

Additional Context

No response

@chalasr
Copy link
Member

chalasr commented Aug 22, 2022

IIRC this has been done consciously, but at a point in time where the feature was not fully opt-in yet.
So I personally don't see any blocker for changing this. PR welcome

@fabpot fabpot closed this as completed Sep 23, 2022
fabpot added a commit that referenced this issue Sep 23, 2022
…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
@lazka
Copy link
Author

lazka commented Oct 3, 2022

thanks @MatTheCat !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants