Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translator] DataCollector always shows default instead of current locale #31600

Copy link
Copy link
Closed
@althaus

Description

@althaus
Issue body actions

Symfony version(s) affected: 4.3.0-BETA2

Description

The current BETA2 has an issue with the TranslationDataCollector in combination with the LocaleAwareListener. I'm running a page with _locale prefixed routes and all works fine, but the profiler shows an incorrect locale. It just shows my default en.

For me the LocaleAwareListener is to blame for this. It's subscribing to onKernelRequest and onKernelFinishRequest and therefore setting the locale twice.

The first time all wents fine, but on the finish part

    public function onKernelFinishRequest(FinishRequestEvent $event): void
    {
        if (null === $parentRequest = $this->requestStack->getParentRequest()) {
            $this->setLocale($event->getRequest()->getDefaultLocale());

            return;
        }

        $this->setLocale($parentRequest->getLocale(), $parentRequest->getDefaultLocale());
    }

we don't have a $parentRequest and setLocale() is called with the default value, which is then injected into the Translator and lately collected by the TranslationDataCollector.

How to reproduce

Setup a simple app with 2 locales and check the profiler.

Possible Solution

No clue what part is the broken one. Could also be the collector running too late.

Additional context

See attached screenshots. Locale shows "en" while it's using German messages. The intl part is also set correctly.

profiler_bad_locale

profiler_correct_intl

Cheers
Matthias

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.