Example #1
0
 public function preDispatch($request)
 {
     try {
         $locale = new Zend_Locale();
         $locale->setDefault('en');
         $locale->setLocale(Zend_Locale::BROWSER);
         $requestedLanguage = key($locale->getBrowser());
         $formatter = new Zend_Log_Formatter_Simple('%message%' . PHP_EOL);
         $writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'translations.log');
         $writer->setFormatter($formatter);
         $logger = new Zend_Log($writer);
         $frontendOptions = array('cache_id_prefix' => 'translation', 'lifetime' => 86400, 'automatic_serialization' => true);
         $backendOptions = array('cache_dir' => APPLICATION_CACHE_PATH);
         $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         $options = array('adapter' => 'gettext', 'scan' => Zend_Translate::LOCALE_FILENAME, 'content' => APPLICATION_PATH . '/languages/en/en.mo', 'locale' => 'auto', 'disableNotices' => true);
         $translate = new Zend_Translate($options);
         if (!$translate->isAvailable($locale->getLanguage())) {
             $locale->setLocale('en');
         } else {
             $translate->setLocale($locale);
         }
         $translate->setCache($cache);
         Zend_Registry::set('locale', $locale->getLanguage());
         Zend_Registry::set('Zend_Translate', $translate);
     } catch (Exception $e) {
         try {
             $writer = new Zend_Log_Writer_Stream(APPLICATION_LOG_PATH . 'plugin-locale.log');
             $logger = new Zend_Log($writer);
             $logger->log($e->getMessage(), Zend_Log::ERR);
         } catch (Exception $e) {
         }
     }
 }
Example #2
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // Get our translate object from registry.
     $translate = Zend_Registry::get('Zend_Translate');
     $currLocale = $translate->getLocale();
     // Create Session block and save the locale
     $session = new Zend_Session_Namespace('session');
     $lang = $request->getParam('language', '');
     // Register all your "approved" locales below.
     switch ($lang) {
         case "nl":
             $langLocale = 'nl_NL';
             break;
         case "en":
             $langLocale = 'en_US';
             break;
         default:
             /**
              * Get a previously set locale from session or set
              * the current application wide locale (set in
              * Bootstrap) if not.
              */
             $langLocale = isset($session->lang) ? $session->lang : $currLocale;
     }
     $newLocale = new Zend_Locale();
     $newLocale->setLocale($langLocale);
     Zend_Registry::set('Zend_Locale', $newLocale);
     $translate->setLocale($langLocale);
     $session->lang = $langLocale;
     // Save the modified translate back to registry
     Zend_Registry::set('Zend_Translate', $translate);
 }
 /**
  * Common handler utility to initialize tokens from parameters
  *
  * @return boolean True if there is a real token specified in the request
  */
 protected function _initToken()
 {
     if ($this->tracker) {
         return $this->token && $this->token->exists;
     }
     $this->tracker = $this->loader->getTracker();
     $this->tokenId = $this->tracker->filterToken($this->_getParam(\MUtil_Model::REQUEST_ID));
     if (!$this->tokenId) {
         return false;
     }
     $this->token = $this->tracker->getToken($this->tokenId);
     if (!$this->token->exists) {
         return false;
     }
     if (!($this->currentUser->isActive() || $this->token->getSurvey()->isTakenByStaff())) {
         $tokenLang = strtolower($this->token->getRespondentLanguage());
         // \MUtil_Echo::track($tokenLang, $this->locale->getLanguage());
         if ($tokenLang != $this->locale->getLanguage()) {
             $this->locale->setLocale($tokenLang);
             $this->translateAdapter->setLocale($this->locale);
             $this->currentUser->setLocale($tokenLang);
             \Gems_Cookies::setLocale($tokenLang, $this->basepath->getBasePath());
         }
         $currentOrg = $this->loader->getOrganization();
         $tokenOrgId = $this->token->getOrganizationId();
         if ($tokenOrgId != $currentOrg->getId()) {
             $this->loader->getOrganization($tokenOrgId)->setAsCurrentOrganization();
         }
     }
     return true;
 }
Example #4
0
 /**
  * Try to set given locale
  * Throw Zend_Translate_Exception if cannot
  */
 public function setLocale($name = null)
 {
     try {
         if (!$this->localeName) {
             $this->locale = new Zend_Locale($name);
         } else {
             $this->locale->setLocale($name);
         }
         if (array_key_exists($this->locale->getLanguage(), $this->translationsPaths)) {
             if (!isset($this->translate)) {
                 $this->translate = new Zend_Translate($this->translationAdapter, $this->translationsPaths[$this->locale->getLanguage()], $this->locale->getLanguage());
             } elseif ($this->translate->isAvailable($this->locale->getLanguage())) {
                 $this->translate->setLocale($this->locale->getLanguage());
             } else {
                 $this->translate->addTranslation($this->translationsPaths[$this->locale->getLanguage()], $this->locale->getLanguage());
             }
         } else {
             include_once 'Zend/Translate/Exception.php';
             throw new Zend_Translate_Exception("Unsupported language");
         }
     } catch (Zend_Exception $e) {
         if ($this->localeName) {
             $this->setLocale($this->localeName);
         }
         throw $e;
     }
     $this->localeName = $this->session->localeName = $this->locale->getLanguage() . ($this->locale->getRegion() ? "_" . $this->locale->getRegion() : "");
     Zend_Registry::set('Zend_Locale', $this->locale);
     Zend_Locale::setDefault($this->locale);
 }
Example #5
0
 function init()
 {
     Zend_Registry::set('languages', array('en' => 'English', 'es' => 'Español', 'ca' => 'Català', 'gl' => 'Galego', 'eu' => 'Euskara', 'nl' => 'Nederlands', 'de' => 'Deutsch', 'fr' => 'Français', 'pt' => 'Português', 'it' => 'Italiano'));
     $activelangs = array('en' => 0, 'es' => 0, 'ca' => 1, 'gl' => 1, 'eu' => 1, 'nl' => 1, 'de' => 1, 'fr' => 1, 'pt' => 1, 'it' => 1);
     Zend_Registry::set('activelangs', $activelangs);
     $this->lang = $this->getRequest()->getParam("language");
     if ($this->lang == null) {
         $auth = Zend_Auth::getInstance();
         if ($auth->hasIdentity()) {
             $this->lang = $auth->getIdentity()->lang;
         }
     }
     if ($this->lang == null && isset($_COOKIE['lang'])) {
         $this->lang = $_COOKIE['lang'];
     }
     $locale = new Zend_Locale();
     // El setLocale del Zend está malito...
     // uso también el nativo de php
     $locale->setLocale($this->lang . '_' . strtoupper($this->lang) . '.utf8');
     setlocale(LC_ALL, $this->lang . '_' . strtoupper($this->lang) . '.utf8');
     if (!isset($activelangs[$locale->getLanguage()])) {
         $locale->setLocale('es_ES.utf8');
     }
     $this->lang = $locale->getLanguage();
     $this->langtest = $activelangs[$this->lang] == 1;
     $options = array('scan' => Zend_Translate::LOCALE_FILENAME);
     $translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/', $this->lang, $options);
     if ($translate->isAvailable($this->lang)) {
         $translate->setLocale($locale);
         Zend_Form::setDefaultTranslator($translate);
         Zend_Registry::set('Zend_Translate', $translate);
     } else {
         header('Location: /es');
         exit;
     }
     if ($this->langtest && (!isset($_COOKIE['langtest']) || $_COOKIE['langtest'] != "0")) {
         $controller = $this->getActionController();
         if (isset($controller->view)) {
             $controller->view->extra .= " advices";
             if (!$controller->view->advices) {
                 $controller->view->advices = array();
             }
             $controller->view->advices["langtest"] = $controller->view->translate("BetaTranslation", "/{$this->lang}/page/translate?lang={$this->lang}");
             $controller->view->headScript()->appendFile('/js/jquery.advice.js');
         }
     }
 }
Example #6
0
 /**
  * Sets a new locale
  *
  * @param  string|array|Zend_Locale $locale (Optional) New locale to set
  * @return Enlight_Components_Locale
  */
 public function setLocale($locale = null)
 {
     if (is_array($locale)) {
         $this->id = isset($locale['id']) ? (int) $locale['id'] : null;
         $locale = isset($locale['locale']) ? $locale['locale'] : null;
     }
     parent::setLocale($locale);
     return $this;
 }
 public function testBadLang()
 {
     $locale = new Zend_Locale();
     $locale->setLocale('qwerty');
     Zend_Registry::set('Zend_Locale', $locale);
     $this->setUp();
     $this->dispatch('/');
     $this->assertHeader('Content-Language', 'en');
 }
Example #8
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $lang = $request->getParam('lang', '');
     if ($lang !== 'id' && $lang !== 'en') {
         $request->setParam('lang', 'id');
     }
     $zl = new Zend_Locale();
     $zl->setLocale($lang);
     Zend_Registry::set('Zend_Locale', $zl);
 }
Example #9
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // Uebersetzung vorhanden?
     if (!Registry::isRegistered('Zend_Translate')) {
         // Locale erweitern; Lade Uebersetzungen und speichere Translate Objekt in der Registry
         $lang = 'de';
         $locale = new \Zend_Locale();
         $locale->setLocale($lang);
         $langFile = APPLICATION_PATH . '/translations/' . $lang . '.php';
         Registry::set('Zend_Translate', new \Zend_Translate('array', $langFile, $locale->getLanguage()));
     }
 }
Example #10
0
 public function Field($properties = array())
 {
     $source = $this->getSource();
     if (!$this->value || !isset($source[$this->value])) {
         if ($this->config()->get('default_to_locale') && $this->locale()) {
             $locale = new Zend_Locale();
             $locale->setLocale($this->locale());
             $this->value = $locale->getRegion();
         }
     }
     if (!$this->value || !isset($source[$this->value])) {
         $this->value = $this->config()->get('default_country');
     }
     return parent::Field();
 }
 public function Field($properties = array())
 {
     $source = $this->getSource();
     // Default value to best availabel locale
     $value = $this->Value();
     if ($this->config()->default_to_locale && (!$value || !isset($source[$value])) && $this->locale()) {
         $locale = new Zend_Locale();
         $locale->setLocale($this->locale());
         $value = $locale->getRegion();
         $this->setValue($value);
     }
     // Default to default country otherwise
     if (!$value || !isset($source[$value])) {
         $this->setValue($this->config()->default_country);
     }
     return parent::Field($properties);
 }
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $lang = $request->getParam('lang', '');
     if ($lang !== 'en' && $lang !== 'cs') {
         $request->setParam('lang', 'en');
     }
     $lang = $request->getParam('lang');
     if ($lang == 'en') {
         $locale = 'en_UK';
     } else {
         $locale = 'cs_CZ';
     }
     $zl = new Zend_Locale();
     $zl->setLocale($locale);
     Zend_Registry::set('Zend_Locale', $zl);
     $translate = new Zend_Translate('csv', APPLICATION_PATH . '/configs/lang/' . $lang . '.csv', $lang);
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #13
0
 /**
  * Nastavuje funkcionalitu prekladani
  *
  * @return void
  * @todo nastavit cache pro Zend_Locale + otestovat vykon
  * @todo nastaveni Zend_Locale podle nastaveni v db
  * @todo pouziti $locale->getLanguage nebo neco podobneho - mohlo by to zkratit switch, pripadne by se nove jazyky mohly pridavat pres admin rozhrani
  */
 public function setLanguage()
 {
     $options = $this->getOptions();
     $locale = new Zend_Locale();
     switch ($locale) {
         case 'cs_CZ':
             $this->_lang->code = 'cs';
             $this->_lang->locale = $locale;
             $this->_lang->name = 'Czech';
             break;
         case 'de_AT':
         case 'de_BE':
         case 'de_CH':
         case 'de_DE':
         case 'de_LI':
         case 'de_LU':
         case 'de':
             $this->_lang->code = 'de';
             $this->_lang->locale = 'de';
             $this->_lang->name = 'German';
             break;
         default:
             $this->_lang->code = 'en';
             $this->_lang->locale = 'en_US';
             $this->_lang->name = 'English';
             break;
     }
     $locale->setLocale($this->_lang->locale);
     // Nastaveni locale - nejspis se to nastavi nekde v pluginu podle preferenci uzivatele a ulozi do registru nebo session
     Zend_Registry::set('Zend_Locale', $locale);
     $manager = $this->getBootstrap()->getResource('CacheManager');
     $cache = $manager->getCache('translate');
     Zend_Translate::setCache($cache);
     if (isset($options['logUntranslated']) and $options['logUntranslated'] == true) {
         $writer = new Unodor_Log_Writer_Translate(LANGUAGES_PATH . '/source/stringtable.php');
         $log = new Zend_Log();
         $log->addWriter($writer);
         $options = array('log' => $log, 'logUntranslated' => true, 'logMessage' => 'gettext(%message%);');
     }
     $translate = new Zend_Translate('Unodor_Translate_Adapter_Gettext', LANGUAGES_PATH . '/' . $this->_lang->name . '.mo', $this->_lang->code, $options);
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #14
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $locale = new Zend_Locale();
     $options = array('scan' => Zend_Translate::LOCALE_FILENAME, 'clear' => false, 'disableNotices' => true);
     Zend_Translate::setCache(Zend_Registry::get('cache'));
     if (isset($_COOKIE['language_select'])) {
         $language = $_COOKIE['language_select'];
     } else {
         $language = 'en';
     }
     $translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages', 'auto', $options);
     $translate->addTranslation(APPLICATION_PATH . '/languages/ot');
     $translate->addTranslation(APPLICATION_PATH . '/../overrides/languages');
     if (!$translate->isAvailable($language)) {
         throw new Exception('Language ' . $language . ' is not available');
     }
     $locale->setLocale($language);
     $translate->setLocale($locale);
     Zend_Registry::set('Zend_Locale', $locale);
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #15
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     //$config = Zend_Registry::get('config');
     // Get languages
     $locale = new Zend_Locale();
     $options = array('scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true);
     $cache = Zend_Registry::get('cache');
     Zend_Translate::setCache($cache);
     $translate = @new Zend_Translate('tmx', APPLICATION_PATH . '/languages/', 'auto', $options);
     $params = $this->getRequest()->getParams();
     $language = 'en';
     /*
     if(isset($params['language']))
     {
     	$language = $params['language'];
     }
     
     if($language == false)
     {
     	$language = $translate->isAvailable($locale->getLanguage) ? $locale->getLanguage() : $config->language->default;
     }
     
     if(!$translate->isAvailable($language))
     {
     	$language = 'en';
     	//throw new Zend_Controller_Action_Exception('This page does not exist', 404);
     }
     */
     //else
     //{
     $locale->setLocale($language);
     $translate->setLocale($locale);
     Zend_Form::setDefaultTranslator($translate);
     //setcookie('lang', $locale->getLanguage(), null, '/');
     Zend_Registry::set('Zend_Locale', $locale);
     Zend_Registry::set('Zend_Translate', $translate);
     Zend_Registry::set('Available_Translations', $translate->getList());
     //}
 }
Example #16
0
<?php

set_include_path(get_include_path() . PATH_SEPARATOR . './library');
// setup Zend autloading, this requires that the library is available via the include_path
require 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// define float value that will differ between rounding and cutoff
$floatvalue = 1298.85525;
$precision = 2;
$testLocale = 'en_GB';
// setup a fixed locale to get around differeing output formats regarding . and ,
$locale = new Zend_Locale();
$locale->setLocale('en_GB');
Zend_Registry::set('Zend_Locale', $locale);
// what is produced by php round function
// expected result is 1298.86
echo round($floatvalue, $precision);
echo "\n";
// what is produce by Zend_Locale_Math
// expected result is 1298.86
echo Zend_Locale_Math::round($floatvalue, $precision);
echo "\n";
// what is produced by Zend_Locale_Math without specifiying an explicit format
// expected result is 1,298.86
// this will return 1,298.85 instead!
echo Zend_Locale_Format::toNumber($floatvalue, array('precision' => $precision, 'locale' => $locale));
echo "\n";
// what is produced by Zend_Locale_Math with specifiying an explicit format
// expected result is 1,298.86
$format = Zend_Locale_Data::getContent((string) $locale, 'decimalnumber');
echo Zend_Locale_Format::toNumber($floatvalue, array('precision' => $precision, 'locale' => $locale, 'number_format' => $format));
Example #17
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);
 }
Example #18
0
 /**
  * test getScriptList
  * expected true
  */
 public function testgetScriptList()
 {
     $value = new Zend_Locale();
     $list = $value->getScriptList();
     $this->assertTrue(is_array($list), 'Script List not returned');
     $list = $value->getScriptList('de');
     $this->assertTrue(is_array($list), 'Script List not returned');
     $value->setLocale('de');
     $list = $value->getScriptDisplay('Arab');
     $this->assertEquals($list, 'Arabisch', 'Script Display not returned');
     $list = $value->getScriptDisplay('Arab', 'en');
     $this->assertEquals($list, 'Arabic', 'Script Display not returned');
     $list = $value->getScriptDisplay('xyz');
     $this->assertFalse(is_string($list), 'Script Display should be false');
 }
Example #19
0
 /**
  * Initialize localization
  *
  * @return void
  */
 protected function initializeLocalization()
 {
     $trFilePathPattern = $this->config['GUI_ROOT_DIR'] . '/i18n/locales/%s/LC_MESSAGES/%s.mo';
     if (PHP_SAPI != 'cli') {
         $lang = iMSCP_Registry::set('user_def_lang', isset($_SESSION['user_def_lang']) ? $_SESSION['user_def_lang'] : (isset($this->config['USER_INITIAL_LANG']) ? $this->config['USER_INITIAL_LANG'] : 'auto'));
         if (Zend_Locale::isLocale($lang)) {
             $locale = new Zend_Locale($lang);
             if ($lang == 'auto') {
                 $locale->setLocale('en_GB');
                 $browser = $locale->getBrowser();
                 arsort($browser);
                 foreach ($browser as $language => $quality) {
                     if (file_exists(sprintf($trFilePathPattern, $language, $language))) {
                         $locale->setLocale($language);
                         break;
                     }
                 }
             } elseif (!file_exists(sprintf($trFilePathPattern, $locale, $locale))) {
                 $locale->setLocale('en_GB');
             }
         } else {
             $locale = new Zend_Locale('en_GB');
         }
     } else {
         $locale = new Zend_Locale('en_GB');
     }
     // Setup cache object for translations
     $cache = Zend_Cache::factory('Core', 'File', array('caching' => true, 'lifetime' => null, 'automatic_serialization' => true, 'automatic_cleaning_factor' => 0, 'ignore_user_abort' => true, 'cache_id_prefix' => 'iMSCP_Translate'), array('hashed_directory_level' => 0, 'cache_dir' => CACHE_PATH . '/translations'));
     if ($this->config['DEBUG']) {
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     } else {
         Zend_Translate::setCache($cache);
     }
     // Setup primary translator for iMSCP core translations
     iMSCP_Registry::set('translator', new Zend_Translate(array('adapter' => 'gettext', 'content' => sprintf($trFilePathPattern, $locale, $locale), 'locale' => $locale, 'disableNotices' => true, 'tag' => 'iMSCP')));
 }
Example #20
0
 /**
  * test setLocaleFailedRoot
  * expected true
  */
 public function testsetLocaleFailedRoot()
 {
     $value = new Zend_Locale();
     $value->setLocale('xx_AA');
     $this->assertEquals($value->toString(), 'root', 'Environment Locale not set');
 }
Example #21
0
 /**
  * Initialize locale
  *
  * @return void
  */
 public function initLocale()
 {
     $locale = new Zend_Locale();
     $locale->setLocale('ja_JP');
     return $this;
 }
Example #22
0
 /**
  * Set the language object variable
  * @param $locale
  */
 public static function setDefaultLanguage($path, $locale)
 {
     $zl = new Zend_Locale();
     if (!empty($locale)) {
         $zl->setLocale($locale);
         Shineisp_Registry::set('Zend_Locale', $zl);
     }
 }
Example #23
0
 /**
  * Test empty float values
  */
 public function testEmptyFloat()
 {
     $locale = new Zend_Locale();
     $locale->setLocale('es_AR');
     $item = new Project_Models_Project(array('db' => $this->sharedFixture));
     $item->budget = '';
 }
 /**
  * Run the Country code through a converter to get the proper Country Name
  */
 function FullCountry()
 {
     $locale = new Zend_Locale();
     $locale->setLocale($this->owner->Country);
     return $locale->getRegion();
 }
Example #25
0
 /**
  * test setLocale
  * expected true
  */
 public function testsetLocale()
 {
     $value = new Zend_Locale('de_DE');
     $value->setLocale('en_US');
     $this->assertEquals($value->toString(), 'en_US', 'Environment Locale not set');
     $value->setLocale('en_AA');
     $this->assertEquals($value->toString(), 'en', 'Environment Locale not set');
     $value->setLocale('xx_AA');
     $this->assertEquals($value->toString(), 'root', 'Environment Locale not set');
 }
Example #26
0
 /**
  * Translations & languages
  */
 protected function _initSetTranslations()
 {
     $session = new Zend_Session_Namespace('Default');
     $available_languages = array();
     // load all php files from languages folder
     foreach (glob(APPLICATION_PATH . '/languages/*.php') as $file) {
         unset($data, $init);
         require_once $file;
         if (!isset($translate)) {
             $translate = new Zend_Translate('array', $data, $init['short']);
         }
         $translate->addTranslation($data, $init['short']);
         $available_languages[$init['short']] = $init['name'];
     }
     if (empty($available_languages)) {
         die('Error: language file is missing ' . APPLICATION_PATH . '/languages/*.php');
     }
     // init Zend_Locale
     $locale = new Zend_Locale();
     // set default language from options
     $default_language = Zend_Registry::get('config')->get('default_language');
     if (!in_array($default_language, $translate->getList())) {
         // in case someone forgot to update settings -> general
         reset($available_languages);
         $default_language = key($available_languages);
     }
     $translate->setLocale($default_language);
     $locale->setLocale($default_language);
     Zend_Registry::set('locale', $default_language);
     // set current language based on user session
     if ($session->language && in_array($session->language, $translate->getList())) {
         $translate->setLocale($session->language);
         $locale->setLocale($session->language);
         Zend_Registry::set('locale', $session->language);
     }
     // push translator to registry
     Zend_Registry::set('Zend_Translate', $translate);
     // push translator to views
     $this->_view->translate = $translate;
     // push translator to forms
     Zend_Form::setDefaultTranslator($translate);
     // sort default as first & save array for forms
     $available_languages_sorted = array();
     if (isset($available_languages[$default_language])) {
         $available_languages_sorted = array($default_language => $available_languages[$default_language]);
         unset($available_languages[$default_language]);
     }
     $available_languages_sorted = array_merge($available_languages_sorted, $available_languages);
     Zend_Registry::set('languages_array', $available_languages_sorted);
 }
Example #27
0
 /**
  * test setLocale
  * expected true
  */
 public function testsetLocale()
 {
     $value = new Zend_Locale('de_DE');
     $value->setLocale('en_US');
     $this->assertEquals('en_US', $value->toString());
     $value->setLocale('en_AA');
     $this->assertEquals('en', $value->toString());
     $value->setLocale('xx_AA');
     $this->assertEquals('root', $value->toString());
     $value->setLocale('auto');
     $this->assertTrue(is_string($value->toString()));
     $value->setLocale('browser');
     $this->assertTrue(is_string($value->toString()));
     $value->setLocale('environment');
     $this->assertTrue(is_string($value->toString()));
 }
 /**
  * Simple constructor that sets the country code and zip. If no
  * country is set, this class attempts to autodetect.
  * 
  * @param country_code 2 character country code
  * @param zipcode string of the zipo/postal code
  */
 public function __construct($zipcode, $country_code = null)
 {
     if ($country_code) {
         $this->country_code = $country_code;
     } else {
         $locale = new Zend_Locale();
         $locale->setLocale($this->locale());
         $this->country_code = $locale->getRegion();
     }
     if ($zipcode) {
         $this->zipcode = $zipcode;
     }
 }