当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Locale::setLocale方法代码示例

本文整理汇总了PHP中Zend_Locale::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale::setLocale方法的具体用法?PHP Zend_Locale::setLocale怎么用?PHP Zend_Locale::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Locale的用法示例。


在下文中一共展示了Zend_Locale::setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preDispatch

 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) {
         }
     }
 }
开发者ID:rogercastaneda,项目名称:owlsys,代码行数:33,代码来源:Locale.php

示例2: preDispatch

 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);
 }
开发者ID:br00k,项目名称:tnc-web,代码行数:32,代码来源:LangSelector.php

示例3: _initToken

 /**
  * 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;
 }
开发者ID:GemsTracker,项目名称:gemstracker-library,代码行数:36,代码来源:AskAction.php

示例4: setLocale

 /**
  * 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);
 }
开发者ID:pansot2,项目名称:PadCMS-backend,代码行数:34,代码来源:Localizer.php

示例5: init

 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');
         }
     }
 }
开发者ID:Arteaga2k,项目名称:nolotiro,代码行数:47,代码来源:Checklang.php

示例6: setLocale

 /**
  * 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;
 }
开发者ID:nvdnkpr,项目名称:Enlight,代码行数:15,代码来源:Locale.php

示例7: testBadLang

 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');
 }
开发者ID:HardSkript,项目名称:unsee.cc,代码行数:9,代码来源:IndexControllerTest.php

示例8: preDispatch

 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);
 }
开发者ID:hukumonline,项目名称:admin,代码行数:10,代码来源:LangSelector.php

示例9: setUpBeforeClass

 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()));
     }
 }
开发者ID:rukzuk,项目名称:rukzuk,代码行数:13,代码来源:ServiceTestCase.php

示例10: Field

 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();
 }
开发者ID:normann,项目名称:sapphire,代码行数:15,代码来源:CountryDropdownField.php

示例11: 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);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:17,代码来源:CountryDropdownField.php

示例12: preDispatch

 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);
 }
开发者ID:abtris,项目名称:ZF-Examples-Multilanguages,代码行数:18,代码来源:LangSelector.php

示例13: setLanguage

 /**
  * 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);
 }
开发者ID:besters,项目名称:My-Base,代码行数:50,代码来源:Translate.php

示例14: routeShutdown

 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);
 }
开发者ID:ncsuwebdev,项目名称:otframework,代码行数:21,代码来源:Language.php

示例15: preDispatch

 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());
     //}
 }
开发者ID:jannev,项目名称:site,代码行数:39,代码来源:Language.php


注:本文中的Zend_Locale::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。