src/Locale/EventListener/LocaleListener.php
public function kernelView(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->query->has('locale')) {
            return;
        }

        $controllerResult = $event->getControllerResult();
        $locale = $request->query->get('locale');

        if ($controllerResult instanceof Paginator || is_array($controllerResult)) {
            foreach ($controllerResult as $model) {
                if ($model instanceof Localizable) {
                    $this->localeService->localize($model, $locale);
                }
            }
        } elseif ($controllerResult instanceof Localizable) {
            $this->localeService->localize($controllerResult, $locale);
        }

        $event->setControllerResult($controllerResult);
    }
public function kernelView(GetResponseForControllerResultEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->query->has('locale')) {
            return;
        }

        $controllerResult = $event->getControllerResult();
        $locale = $request->query->get('locale');

        if ($controllerResult instanceof Paginator || is_array($controllerResult)) {
            foreach ($controllerResult as $model) {
                if ($model instanceof Localizable) {
                    $this->localeService->localize($model, $locale);
                }
            }
        } elseif ($controllerResult instanceof Localizable) {
            $this->localeService->localize($controllerResult, $locale);
        }

        $event->setControllerResult($controllerResult);
    }
public function kernelView ( GetResponseForControllerResultEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( ! $ request -> query -> has ( 'locale' ) ) { return ; } $ controllerResult = $ event -> getControllerResult ( ) ; $ locale = $ request -> query -> get ( 'locale' ) ; if ( $ controllerResult instanceof Paginator || is_array ( $ controllerResult ) ) { foreach ( $ controllerResult as $ model ) { if ( $ model instanceof Localizable ) { $ this -> localeService -> localize ( $ model , $ locale ) ; } } } elseif ( $ controllerResult instanceof Localizable ) { $ this -> localeService -> localize ( $ controllerResult , $ locale ) ; } $ event -> setControllerResult ( $ controllerResult ) ; }
Filter the returned data for a given locale

@param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
Filter the returned data for a given locale