/** * Retrieve locale object * * @static * @return Zend_Locale */ public static function getLocale() { if (!Zend_Registry::isRegistered('Zend_Locale')) { if (Axis_Area::isFrontend() && Axis_Controller_Router_Route_Front::hasLocaleInUrl()) { self::setLocale(Axis_Controller_Router_Route_Front::getCurrentLocale()); } elseif (Axis_Area::isBackend() && isset(Axis::session()->locale)) { self::setLocale(Axis::session()->locale); } elseif (Axis_Area::isInstaller() && isset(Axis::session('install')->current_locale)) { self::setLocale(Axis::session('install')->current_locale); } elseif (Axis_Area::isInstaller()) { self::setLocale(self::DEFAULT_LOCALE); } else { self::setLocale(Axis::config('locale/main/locale')); } } return Zend_Registry::get('Zend_Locale'); }
protected function _initRouter() { $this->bootstrap('FrontController'); $router = new Axis_Controller_Router_Rewrite(); // pre router config $defaultLocale = Axis_Locale::getDefaultLocale(); $locales = Axis_Locale::getLocaleList(true); Axis_Controller_Router_Route_Front::setDefaultLocale($defaultLocale); Axis_Controller_Router_Route_Front::setLocales($locales); // include routes files $routeFiles = Axis::app()->getRoutes(); foreach ($routeFiles as $routeFile) { if (!is_readable($routeFile)) { continue; } include_once $routeFile; } $router->removeDefaultRoutes(); if (!$router instanceof Axis_Controller_Router_Rewrite) { throw new Axis_Exception('Incorrect routes'); } $front = $this->getResource('FrontController'); $front->setRouter($router); $sslRedirectorActionHelper = new Axis_Controller_Action_Helper_SecureRedirector(); Zend_Controller_Action_HelperBroker::addHelper($sslRedirectorActionHelper); return $router; }
/** * Matches a user submitted path with parts defined by a map. Assigns and * returns an array of variables on a successful match. * * @param string $path Path used to match against this routing map * @return array|false An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { $path = trim($path, $this->_urlDelimiter); $pathParts = explode($this->_urlDelimiter, $path, 2); if (in_array($pathParts[0], self::$_locales)) { $path = sizeof($pathParts) > 1 ? $pathParts[1] : ''; $currentLocale = $pathParts[0]; self::$_hasLocaleInUrl = true; } else { if (isset($this->_defaults['locale'])) { $currentLocale = $this->_defaults['locale']; } else { $currentLocale = self::$_defaultLocale; } } self::$_currentLocale = $currentLocale; $params = parent::match($path, $partial); if ($params) { Axis_Area::frontend(); $params = array_merge($params, array('locale' => $currentLocale)); } return $params; }
/** * Matches a user submitted path with parts defined by a map. Assigns and * returns an array of variables on a successful match. * * @param string $path Path used to match against this routing map * @return array|false An array of assigned values or a false on a mismatch */ public function match($path, $partial = false) { $path = trim($path, $this->_urlDelimiter); $pathParts = explode($this->_urlDelimiter, $path, 2); if (!empty($pathParts[0]) && strlen($pathParts[0]) > 1) { foreach (self::$_locales as $locale) { // preventing duplicate urls: // site.com/uk and site.com/uk_UA - only one will work after next check if (trim(Axis_Locale::getLanguageUrl($locale), '/') == $pathParts[0]) { self::$_hasLocaleInUrl = true; break; } } } if (self::$_hasLocaleInUrl) { $path = sizeof($pathParts) > 1 ? $pathParts[1] : ''; $currentLocale = $pathParts[0]; } elseif (isset($this->_defaults['locale'])) { $currentLocale = $this->_defaults['locale']; } else { $currentLocale = self::$_defaultLocale; } self::$_currentLocale = $currentLocale; $params = parent::match($path, $partial); if ($params) { Axis_Area::frontend(); $params = array_merge($params, array('locale' => $currentLocale)); } return $params; }