Search code examples
phpsymfonysymfony4

Symfony 4.3 wrong translator locale on prod


I've updated my web app from Symfony 4.1 to 4.3 and strange bug emerged. When on dev env, the translator is working correctly - it has locale set by request locale. But when I switch to prod env, the translator has always default locale regardless on request locale (see attached images).

The locale of the request is determined by subscribed event "onKernelRequest" with priority higher than "LocaleListener" according to documentation, see debug:

#8 App\EventSubscriber\LocaleSubscriber::onKernelRequest() 20
#9 ApiPlatform\Core\Filter\QueryParameterValidateListener::onKernelRequest() 16        
#10 Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest() 16  

Can you suggest some things to check? With 4.1 it was working correctly.

It's not cache issue, I've tried clear cache gazillion times with both clear:cache and deleting cache folder contents. I've also tried this on localhost and remote server and the behavior is always the same (with cleared cache).

DEV ENV PROD ENV

The locale of the translator should be set by request's locale in both dev and prod env. But it's working only on dev env.


Solution

  • Try to force the local in the translator:

    App\EventSubscriber\LocaleSubscriber::onKernelRequest
    $translator->setLocale($locale);