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

Skip to content

Inconsistent locale handling in subrequests #6932

Closed
@stof

Description

@stof

If the master request uses a locale different from the default locale and the subrequest does not change the locale through the routing, the locale of the subrequest will be the app default locale instead of the master request locale.
This causes some issues as the translator will not change its locale (it retrieves it only once from the request and is in the container scope) but the routing context will change its _locale parameter and the intl default locale will change.
But this will also impact any rendering done in the master request after the subrequest as the locale is not reset to the master one.

An easy workaround a would be to set the locale of the master request as default locale for subrequest instead of the app default locale. But this would make the locale in the subrequest inconsistent when enablign ESI.

A way to fix it in a better way could be to trigger an event after the handling of a subrequest to announce the return to the master request. The request object available in this listener should be the master one (which means it cannot be achieved cleanly with a late kernel.response event listener on the subrequest). This listener would then reset the Intl and routing locale with the value from the request (and any other action needed).
@fabpot what do you think about it ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions