module/Core/Module.php
public function onDispatch( MvcEvent $event )
    {
        if ( $this->response )
        {
            $event->stopPropagation();
            return $this->response;
        }

        $routeMatch = $event->getRouteMatch();
        $sm         = $event->getApplication()
                            ->getServiceManager();

        // Set current timezone, when first get
        $sm->get( 'Timezone' );

        if ( $routeMatch )
        {
            $locale = $routeMatch->getParam( 'locale' );
        }

        if ( ! $locale )
        {
            $request = $event->getRequest();

            if ( $request instanceof HttpRequest )
            {
                $header = $request->getHeader( 'Accept-Language' );

                if ( $header )
                {
                    $availables = null;
                    $controller = $event->getController();

                    if ( $controller instanceof LocaleSelectorInterface )
                    {
                        $availables = $controller->getAvailableLocales();
                    }

                    $locale = $sm->get( 'Locale' )
                                 ->acceptFromHttp( $header->getFieldValue(),
                                                   $availables );
                }
            }
        }

        if ( $locale )
        {
            $sm->get( 'Locale' )
               ->setCurrent( $locale );
        }
    }
public function onDispatch( MvcEvent $event )
    {
        if ( $this->response )
        {
            $event->stopPropagation();
            return $this->response;
        }

        $routeMatch = $event->getRouteMatch();
        $sm         = $event->getApplication()
                            ->getServiceManager();

        // Set current timezone, when first get
        $sm->get( 'Timezone' );

        if ( $routeMatch )
        {
            $locale = $routeMatch->getParam( 'locale' );
        }

        if ( ! $locale )
        {
            $request = $event->getRequest();

            if ( $request instanceof HttpRequest )
            {
                $header = $request->getHeader( 'Accept-Language' );

                if ( $header )
                {
                    $availables = null;
                    $controller = $event->getController();

                    if ( $controller instanceof LocaleSelectorInterface )
                    {
                        $availables = $controller->getAvailableLocales();
                    }

                    $locale = $sm->get( 'Locale' )
                                 ->acceptFromHttp( $header->getFieldValue(),
                                                   $availables );
                }
            }
        }

        if ( $locale )
        {
            $sm->get( 'Locale' )
               ->setCurrent( $locale );
        }
    }
public function onDispatch ( MvcEvent $ event ) { if ( $ this -> response ) { $ event -> stopPropagation ( ) ; return $ this -> response ; } $ routeMatch = $ event -> getRouteMatch ( ) ; $ sm = $ event -> getApplication ( ) -> getServiceManager ( ) ; // Set current timezone, when first get $ sm -> get ( 'Timezone' ) ; if ( $ routeMatch ) { $ locale = $ routeMatch -> getParam ( 'locale' ) ; } if ( ! $ locale ) { $ request = $ event -> getRequest ( ) ; if ( $ request instanceof HttpRequest ) { $ header = $ request -> getHeader ( 'Accept-Language' ) ; if ( $ header ) { $ availables = null ; $ controller = $ event -> getController ( ) ; if ( $ controller instanceof LocaleSelectorInterface ) { $ availables = $ controller -> getAvailableLocales ( ) ; } $ locale = $ sm -> get ( 'Locale' ) -> acceptFromHttp ( $ header -> getFieldValue ( ) , $ availables ) ; } } } if ( $ locale ) { $ sm -> get ( 'Locale' ) -> setCurrent ( $ locale ) ; } }
General dispatch listener

@param \Zend\Mvc\MvcEvent $event
General dispatch listener