public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->isMasterRequest() && $this->getParameter('nyroDev_utility.setLocale')) {
            $locale = $event->getRequest()->getLocale();

            if (0 === strpos($locale, 'change_')) {
                $tmp = explode('change_', $locale);
                $locale = $tmp[1];
                // Update already instanciated objects
                $event->getRequest()->setLocale($locale);
                $this->get('translator')->setLocale($locale);
            }

            if (!defined('NYRO_LOCALE')) {
                define('NYRO_LOCALE', $locale);
            }

            $locales = [
                $locale,
                $locale.'@euro',
                $locale.'.utf8',
            ];
            if (2 == strlen($locale)) {
                $locUp = strtoupper($locale);
                $locale .= '_'.('ZH' == $locUp ? 'CN' : $locUp);
                $locales[] = $locale;
                $locales[] = $locale.'@euro';
                $locales[] = $locale.'.utf8';
            }
            foreach (array_reverse($locales) as $loc) {
                $tmp = setlocale(LC_ALL, $loc);
                if (mb_strtolower($tmp) == mb_strtolower($loc)) {
                    break;
                }
            }
        }
    }
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->isMasterRequest() && $this->getParameter('nyroDev_utility.setLocale')) {
            $locale = $event->getRequest()->getLocale();

            if (0 === strpos($locale, 'change_')) {
                $tmp = explode('change_', $locale);
                $locale = $tmp[1];
                // Update already instanciated objects
                $event->getRequest()->setLocale($locale);
                $this->get('translator')->setLocale($locale);
            }

            if (!defined('NYRO_LOCALE')) {
                define('NYRO_LOCALE', $locale);
            }

            $locales = [
                $locale,
                $locale.'@euro',
                $locale.'.utf8',
            ];
            if (2 == strlen($locale)) {
                $locUp = strtoupper($locale);
                $locale .= '_'.('ZH' == $locUp ? 'CN' : $locUp);
                $locales[] = $locale;
                $locales[] = $locale.'@euro';
                $locales[] = $locale.'.utf8';
            }
            foreach (array_reverse($locales) as $loc) {
                $tmp = setlocale(LC_ALL, $loc);
                if (mb_strtolower($tmp) == mb_strtolower($loc)) {
                    break;
                }
            }
        }
    }
public function onKernelRequest ( GetResponseEvent $ event ) { if ( $ event -> isMasterRequest ( ) && $ this -> getParameter ( 'nyroDev_utility.setLocale' ) ) { $ locale = $ event -> getRequest ( ) -> getLocale ( ) ; if ( 0 === strpos ( $ locale , 'change_' ) ) { $ tmp = explode ( 'change_' , $ locale ) ; $ locale = $ tmp [ 1 ] ; // Update already instanciated objects $ event -> getRequest ( ) -> setLocale ( $ locale ) ; $ this -> get ( 'translator' ) -> setLocale ( $ locale ) ; } if ( ! defined ( 'NYRO_LOCALE' ) ) { define ( 'NYRO_LOCALE' , $ locale ) ; } $ locales = [ $ locale , $ locale . '@euro' , $ locale . '.utf8' , ] ; if ( 2 == strlen ( $ locale ) ) { $ locUp = strtoupper ( $ locale ) ; $ locale .= '_' . ( 'ZH' == $ locUp ? 'CN' : $ locUp ) ; $ locales [ ] = $ locale ; $ locales [ ] = $ locale . '@euro' ; $ locales [ ] = $ locale . '.utf8' ; } foreach ( array_reverse ( $ locales ) as $ loc ) { $ tmp = setlocale ( LC_ALL , $ loc ) ; if ( mb_strtolower ( $ tmp ) == mb_strtolower ( $ loc ) ) { break ; } } } }
Kernel request listener to setLocale if configured.

@param GetResponseEvent $event Kernel request event
Kernel request listener to setLocale if configured .