コード例 #1
0
ファイル: Module.php プロジェクト: esase/dream-cms
 /**
  * Init user localization
  *
  * @param \Zend\Mvc\MvcEvent $e
  * @return void
  */
 public function initUserLocalization(MvcEvent $e)
 {
     try {
         // get a router
         $router = $this->serviceLocator->get('router');
         $matches = $e->getRouteMatch();
         if (!$matches->getParam('language') || !array_key_exists($matches->getParam('language'), $this->localizations)) {
             if (!$matches->getParam('language')) {
                 // set default language
                 $router->setDefaultParam('language', $this->defaultLocalization['language']);
                 // remember user's chose language
                 $this->setUserLanguage($this->defaultLocalization['language']);
                 return;
             }
             // show a 404 page
             $matches->setParam('action', 'not-found');
             return;
         }
         // init an user localization
         if ($this->defaultLocalization['language'] != $matches->getParam('language')) {
             $this->serviceLocator->get('translator')->setLocale($this->localizations[$matches->getParam('language')]['locale']);
             LocalizationService::setCurrentLocalization($this->localizations[$matches->getParam('language')]);
         }
         Locale::setDefault($this->localizations[$matches->getParam('language')]['locale']);
         $router->setDefaultParam('language', $matches->getParam('language'));
         // remember user's choose language
         $this->setUserLanguage($matches->getParam('language'));
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
 }