public function beforeDispatch(Event $event)
    {
        /* @var \Cake\Http\ServerRequest $request */
        $request = $event->getData('request');
        $locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));

        if (!$locale || (!empty($this->_locales) && !in_array($locale, $this->_locales))) {
            return;
        }

        I18n::setLocale($locale);
    }
public function beforeDispatch(Event $event)
    {
        /* @var \Cake\Http\ServerRequest $request */
        $request = $event->getData('request');
        $locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));

        if (!$locale || (!empty($this->_locales) && !in_array($locale, $this->_locales))) {
            return;
        }

        I18n::setLocale($locale);
    }
public function beforeDispatch ( Event $ event ) { /* @var \Cake\Http\ServerRequest $request */ $ request = $ event -> getData ( 'request' ) ; $ locale = Locale :: acceptFromHttp ( $ request -> getHeaderLine ( 'Accept-Language' ) ) ; if ( ! $ locale || ( ! empty ( $ this -> _locales ) && ! in_array ( $ locale , $ this -> _locales ) ) ) { return ; } I18n :: setLocale ( $ locale ) ; }
Inspects the request for the Accept-Language header and sets the
Locale for the current runtime if it matches the list of valid locales
as passed in the configuration.

@param \Cake\Event\Event $event The event instance.
@return void
Inspects the request for the Accept - Language header and sets the Locale for the current runtime if it matches the list of valid locales as passed in the configuration .