Exemplo n.º 1
0
 public function convert(Money $money, $target)
 {
     $locale = \Zend_Locale::getLocaleToTerritory($target);
     if (null === $locale) {
         throw new InvalidCountryException(sprintf('Cannot find locale for "%s" country.', $target));
     }
     return $this->converter->convert($money, $locale);
 }
Exemplo n.º 2
0
 public function setLanguage($selectedLanguage)
 {
     $sessionHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('session');
     $cacheHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('cache');
     $locale = $sessionHelper->locale;
     $newLocale = Zend_Locale::getLocaleToTerritory($selectedLanguage);
     if ($newLocale !== null) {
         $locale->setLocale($newLocale);
     } else {
         if (Zend_Locale::isLocale($selectedLanguage)) {
             $locale->setLocale($selectedLanguage);
         }
     }
     $sessionHelper->locale = $locale;
     Zend_Registry::get('Zend_Translate')->setLocale($locale);
     $cacheHelper->clean(false, false, array('locale', 'language'));
     return $locale->getLanguage();
 }
Exemplo n.º 3
0
 /**
  * Finds the proper locale based on the input
  * Checks if it exists, degrades it when necessary
  * Detects registry locale and when all fails tries to detect a automatic locale
  * Returns the found locale as string
  *
  * @param string $locale
  * @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
  * @return string
  */
 public static function findLocale($locale = null)
 {
     if ($locale === null) {
         require_once 'Zend/Registry.php';
         if (Zend_Registry::isRegistered('Zend_Locale')) {
             $locale = Zend_Registry::get('Zend_Locale');
         }
     }
     if ($locale === null) {
         $locale = new Zend_Locale();
     }
     if (!Zend_Locale::isLocale($locale, true, false)) {
         if (!Zend_Locale::isLocale($locale, false, false)) {
             $locale = Zend_Locale::getLocaleToTerritory($locale);
             if (empty($locale)) {
                 require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("The locale '{$locale}' is no known locale");
             }
         } else {
             $locale = new Zend_Locale($locale);
         }
     }
     $locale = self::_prepareLocale($locale);
     return $locale;
 }
Exemplo n.º 4
0
 private function _findLanguages()
 {
     $translate = Zend_Registry::get('Zend_Translate');
     $availLanguages = $translate->getAdapter()->getList();
     $flags = scandir(INSTALL_PATH . DIRECTORY_SEPARATOR . 'system/images/flags/');
     foreach ($flags as $flag) {
         if (!is_file(INSTALL_PATH . DIRECTORY_SEPARATOR . 'system/images/flags/' . $flag)) {
             continue;
         }
         $locale = new Zend_Locale(Zend_Locale::getLocaleToTerritory(substr($flag, 0, 2)));
         $lang = $locale->getLanguage();
         if (array_key_exists($lang, $availLanguages)) {
             $availLanguages[$lang] = 'system/images/flags/' . $flag;
         }
         unset($locale, $lang, $flag);
     }
     return $availLanguages;
 }
Exemplo n.º 5
0
 protected function _initLocale()
 {
     $config = Application_Model_Mappers_ConfigMapper::getInstance()->getConfig();
     $name = Zend_Locale::getLocaleToTerritory($config['language']);
     if ($name !== null) {
         $locale = new Zend_Locale($name);
     } else {
         $locale = new Zend_Locale();
     }
     $locale->setCache(Zend_Registry::get('cache'));
     Zend_Registry::set('Zend_Locale', $locale);
 }
Exemplo n.º 6
0
 protected function _initLocale()
 {
     $locale = new Zend_Locale();
     $locale_code = Core_Model_Language::DEFAULT_LOCALE;
     $is_installing = $this->getRequest()->isInstalling();
     if ($this->getRequest()->isApplication() && $this->getApplication()->getLocale()) {
         $locale_code = $this->getApplication()->getLocale();
     } else {
         if (!$is_installing) {
             $currency_code = System_Model_Config::getValueFor("system_currency");
             if ($currency_code) {
                 $currency = new Zend_Currency(null, $currency_code);
                 Core_Model_Language::setCurrentCurrency($currency);
             }
             $territory = System_Model_Config::getValueFor("system_territory");
             if ($territory) {
                 $locale_code = $locale->getLocaleToTerritory($territory);
             } else {
                 $locale_code = new Zend_Locale(Core_Model_Language::getCurrentLocale());
             }
         }
     }
     if (!$is_installing) {
         $timezone = System_Model_Config::getValueFor("system_timezone");
         if ($timezone) {
             date_default_timezone_set($timezone);
         }
     }
     $locale->setLocale($locale_code);
     Zend_Registry::set('Zend_Locale', $locale);
 }
Exemplo n.º 7
0
 /**
  * Find out locale from the request, settings or session
  * if language choice enabled, try the following:
  *      - REQUEST parameter "lang"
  *      - SESSION parameter "lang"
  *      - Am_App::getUser->lang
  *      - default in App
  *      - en_US
  * else use latter 2
  */
 static function initLocale(Am_Di $di)
 {
     if (defined('AM_ADMIN') && AM_ADMIN) {
         Zend_Locale::setDefault('en_US');
     } else {
         $possibleLang = array();
         if ($di->config->get('lang.display_choice')) {
             $auth = $di->auth;
             $user = $auth->getUserId() ? $auth->getUser() : null;
             if (!empty($_REQUEST['_lang'])) {
                 $possibleLang[] = filterId($_REQUEST['_lang']);
             } elseif (!empty($di->session->lang)) {
                 $possibleLang[] = $di->session->lang;
             } elseif ($user && $user->lang) {
                 $possibleLang[] = $user->lang;
             }
             $br = Zend_Locale::getBrowser();
             arsort($br);
             $possibleLang = array_merge($possibleLang, array_keys($br));
         }
         $possibleLang[] = $di->config->get('lang.default', 'en_US');
         $possibleLang[] = 'en_US';
         // last but not least
         // now choose the best candidate
         $enabledLangs = $di->config->get('lang.enabled', array());
         $checked = array();
         foreach ($possibleLang as $lc) {
             list($lang) = explode('_', $lc, 2);
             if (!in_array($lc, $enabledLangs) && !in_array($lang, $enabledLangs)) {
                 continue;
             }
             if ($lc == $lang) {
                 // we have not got entire locale,guess it
                 if ($lc == 'en') {
                     $lc = 'en_US';
                 } elseif ($lc == 'sv') {
                     $lc = 'sv_SE';
                 } elseif ($lc == 'et') {
                     $lc = 'et_EE';
                 } elseif ($lc == 'vi') {
                     $lc = 'vi_VN';
                 } else {
                     $lc = Zend_Locale::getLocaleToTerritory($lang);
                 }
                 if (!$lc && $lang == 'ko') {
                     $lc = 'ko_KR';
                 }
                 if (!$lc && $lang == 'ja') {
                     $lc = 'ja_JP';
                 }
                 if (!$lc && $lang == 'nb') {
                     $lc = 'nb_NO';
                 }
                 if (!$lc && $lang == 'zh') {
                     $lc = 'zh_Hans';
                 }
                 if (!$lc && $lang == 'el') {
                     $lc = 'el_GR';
                 }
                 if (!$lc && $lang == 'he') {
                     $lc = 'he_IL';
                 }
                 if (!$lc && $lang == 'da') {
                     $lc = 'da_DK';
                 }
                 if (!$lc && $lang == 'cs') {
                     $lc = 'cs_CZ';
                 }
                 if (!$lc && $lang == 'sq') {
                     $lc = 'sq_AL';
                 }
                 if (!$lc) {
                     continue;
                 }
             }
             if (isset($checked[$lc])) {
                 continue;
             }
             $checked[$lc] = true;
             // check if locale file is exists
             $lc = preg_replace('/[^A-Za-z0-9_]/', '', $lc);
             if (!Zend_Locale::isLocale($lc)) {
                 continue;
             }
             Zend_Locale::setDefault($lc);
             // then update user if it was request
             // and set to session
             break;
         }
         if ($di->config->get('lang.display_choice') && !empty($_REQUEST['_lang'])) {
             if (($_REQUEST['_lang'] == $lang || $_REQUEST['_lang'] == $lc) && $user && $user->lang != $lang) {
                 $user->updateQuick('lang', $lc);
             }
             // set to session
             $di->session->lang = $lc;
         }
     }
     Zend_Registry::set('Zend_Locale', new Zend_Locale());
     $amLocale = new Am_Locale();
     Zend_Registry::set('Am_Locale', $amLocale);
     $di->locale = $amLocale;
     Zend_Locale_Format::setOptions(array('date_format' => $amLocale->getDateFormat()));
 }
Exemplo n.º 8
0
 public static function getCountriesList()
 {
     if (is_null(self::$_countries_list)) {
         self::$_countries_list = array();
         $locale = Zend_Registry::get('Zend_Locale');
         $currency = new Zend_Currency();
         foreach (Zend_Locale::getTranslationList('Territory', null, 2) as $ter => $name) {
             $country_code = Zend_Locale::getLocaleToTerritory($ter);
             if (!is_null($country_code)) {
                 try {
                     $symbol = $currency->getSymbol($country_code);
                     if (!empty($symbol)) {
                         $countries[$country_code] = array('code' => $country_code, 'name' => $name, 'symbol' => $symbol);
                     }
                 } catch (Exception $e) {
                 }
             }
         }
         uasort($countries, 'cmp');
         foreach ($countries as $currency) {
             self::$_countries_list[] = new Core_Model_Default($currency);
         }
     }
     return self::$_countries_list;
 }
Exemplo n.º 9
0
 private function _complete($pageContent, $pageData, $parserOptions)
 {
     $head = '';
     $body = '';
     //parsing seo data
     $seoData = Tools_Seo_Tools::loadSeodata();
     $seoData = $seoData->toArray();
     unset($seoData['id']);
     $seoData = array_map(function ($item) use($pageData, $parserOptions) {
         $parser = new Tools_Content_Parser(null, $pageData, $parserOptions);
         return !empty($item) ? $parser->setContent($item)->parseSimple() : $item;
     }, $seoData);
     preg_match('~(<body[^\\>]*>)(.*)</body>~usi', $pageContent, $body);
     // setting default charset
     if ($this->view->doctype()->isHtml5()) {
         $this->view->headMeta()->setCharset('utf-8');
     }
     $this->_extendHead($pageContent);
     $this->view->placeholder('seo')->exchangeArray($seoData);
     $this->view->websiteUrl = $parserOptions['websiteUrl'];
     $this->view->websiteMainPage = Helpers_Action_Website::DEFAULT_PAGE;
     $this->view->currentTheme = $parserOptions['currentTheme'];
     // building canonical url
     if ('' === ($canonicalScheme = $this->_config->getConfig('canonicalScheme'))) {
         $canonicalScheme = $this->getRequest()->getScheme();
     }
     $this->view->canonicalUrl = $canonicalScheme . '://' . parse_url($parserOptions['websiteUrl'], PHP_URL_HOST) . parse_url($parserOptions['websiteUrl'], PHP_URL_PATH) . ($pageData['url'] !== Helpers_Action_Website::DEFAULT_PAGE ? $pageData['url'] : '');
     $this->view->pageData = $pageData;
     if (Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_ADMINPANEL)) {
         unset($pageData['content']);
         $body[1] .= $this->_helper->admin->renderAdminPanel($this->_helper->session->getCurrentUser()->getRoleId());
     }
     $this->view->bodyTag = $body[1];
     $this->view->content = $body[2];
     $locale = Zend_Locale::getLocaleToTerritory($this->_config->getConfig('language'));
     $this->view->htmlLang = substr($locale, 0, strpos($locale, '_'));
     $this->view->minify = $this->_config->getConfig('enableMinify') && !Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_LAYOUT);
 }
Exemplo n.º 10
0
 /**
  * Go from language to territory
  *
  * @param string $lang
  * @return string
  */
 public static function languageToTerritory($lang)
 {
     $config = Zend_Registry::get('config');
     $territory = isset($config->resources->locale->territories->{$lang}) ? $config->resources->locale->territories->{$lang} : Zend_Locale::getLocaleToTerritory($lang);
     return $territory;
 }