Skip to content

Set locale for request #3161

Closed
Closed
@mxndshock

Description

@mxndshock

Hi, i'm using ApiPlatform + Symfony 4.3.3 to build a web application. I can't find a way to set the locale for my request. It always fallbacks back to the default locale set in Symfony.

I tried using a RequestListener but it ignores the value i set.

  public function onKernelRequest(RequestEvent $event)
    {

        $token = $this->tokenStorage->getToken();
        $user = ($token && $token->getUser()) ? $token->getUser() : null;
        $request = $event->getRequest();

        if(!$user || !($user instanceof User)) {
            $request->setLocale('it');
        } else {
            $request->setLocale($user->getLang()->getLang());
        }
    }

How can i set the locale for my request?

Thanks

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