/** * Load translation data * * @param string|array $data * @param string $locale Locale/Language to add data for, identical with locale identifier, * see Zend_Locale for more information * @param array $options OPTIONAL Options to use * @return array */ protected function _loadTranslationData($data, $locale, array $options = array()) { if (isset($options['section'])) { self::$_section = $options['section']; } /* @var $translateCache Application_Model_TranslateMapper */ $translateCache = HCMS_Cache::getInstance()->getObjectCache(Application_Model_TranslateMapper::getInstance()); //read data from cache object $data = $translateCache->__call("load", array($locale, self::$_section)); $options = array_merge($this->_options, $options); if (isset($this->_options['clear']) && $this->_options['clear'] === true || !isset($this->_translate[$locale])) { $this->_translate[$locale] = array(); } $this->_translate[$locale] = array_merge($this->_translate[$locale], $data); }
protected function _initLanguage() { $singleLang = Zend_Controller_Front::getInstance()->getParam('singleLang'); if (isset($singleLang) && $singleLang != "") { //1. get language from app.ini $language = $singleLang; $this->getRequest()->setParam("lang", $singleLang); } else { //1. get language from request $language = $this->getRequest()->getParam("lang"); } //$this->_log("Request: " . json_encode($this->getRequest()->getParams()), Zend_Log::DEBUG); if ($language == '') { $language = null; } //2. get language from cookie if (!isset($language)) { $language = $this->getRequest()->getCookie("saved_lang", null); } //3. get from geoip if (!isset($language)) { $country = new Application_Model_Country(); if (Application_Model_CountryMapper::getInstance()->getCountryByGeoIp(HCMS_Utils::getRealIpAddr(), $country)) { $language = strtolower($country->get_def_lang()); } } //4. get default if (!isset($language)) { $language = $this->_getPrimaryLang(); } //check if lang available if (!HCMS_Translate_Adapter_Db::isLangAvailable($language, $this->_isFrontEnd)) { $language = $this->_getPrimaryLang(); } //redirect if lang is not in url if ($language != $this->getRequest()->getParam("lang")) { //redirect only if lang not exists...otherwise let it 404 if (!$this->getRequest()->getParam("lang")) { $this->_log("redirecting to {$language}", Zend_Log::DEBUG); $redirector = new Zend_Controller_Action_Helper_Redirector(); $redirector->gotoRouteAndExit(array('lang' => $language), 'default', false); } } //activate lang HCMS_Translate_Adapter_Db::activate($language); //store lang in cookie $cookieRes = setcookie('saved_lang', $language, time() + 3600, '/', null, false, true); if (!$cookieRes) { $this->_logger->log("Error storing lang cookie", Zend_Log::WARN); } //and in router Zend_Controller_Front::getInstance()->getRouter()->setGlobalParam('lang', $language); //set view and js var if ($this->view) { $this->view->availableLang = Application_Model_TranslateMapper::getInstance()->getLanguages(); $this->view->currLang = $language; $this->view->headScript()->appendScript("var CURR_LANG = '" . $language . "';"); $this->view->singleLang = $this->isSingleLang(); //$this->addLinkAlternateLang(); } //define php const if (!defined("CURR_LANG")) { define("CURR_LANG", $language); } }