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


PHP Zend_Locale类代码示例

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


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

示例1: isValid

 /**
  * Validate the given value. Looks for the language translation list
  * in the registry (key 'Available_Languages'). If this key is not registered
  * the language list is obtained through a call to getLanguageTranslationList()
  * of Zend_Locale.
  *
  * @param string $value An enum string.
  * @return boolean True if the given enum string is known.
  */
 public function isValid($value)
 {
     if (false === is_array($value)) {
         $value = array($value);
     }
     $registry = Zend_Registry::getInstance();
     if ($registry->isRegistered('Available_Languages')) {
         $translationList = $registry->get('Available_Languages');
     } else {
         $locale = new Zend_Locale();
         $translationList = $locale->getLanguageTranslationList();
     }
     foreach ($value as $val) {
         $this->_setValue($val);
         if (is_string($val) === false) {
             $this->_error(self::MSG_LANGUAGE);
             return false;
         }
         if (array_key_exists($val, $translationList) === false) {
             $this->_error(self::MSG_LANGUAGE);
             return false;
         }
     }
     return true;
 }
开发者ID:alexukua,项目名称:opus4,代码行数:34,代码来源:Language.php

示例2: init

 public function init()
 {
     $this->setTitle('Locale Settings')->setDescription('CORE_FORM_ADMIN_SETTINGS_LOCALE_DESCRIPTION');
     // Init timezeon
     $this->addElement('Select', 'timezone', array('label' => 'Default Timezone', 'multiOptions' => array('US/Pacific' => '(UTC-8) Pacific Time (US & Canada)', 'US/Mountain' => '(UTC-7) Mountain Time (US & Canada)', 'US/Central' => '(UTC-6) Central Time (US & Canada)', 'US/Eastern' => '(UTC-5) Eastern Time (US & Canada)', 'America/Halifax' => '(UTC-4)  Atlantic Time (Canada)', 'America/Anchorage' => '(UTC-9)  Alaska (US & Canada)', 'Pacific/Honolulu' => '(UTC-10) Hawaii (US)', 'Pacific/Samoa' => '(UTC-11) Midway Island, Samoa', 'Etc/GMT-12' => '(UTC-12) Eniwetok, Kwajalein', 'Canada/Newfoundland' => '(UTC-3:30) Canada/Newfoundland', 'America/Buenos_Aires' => '(UTC-3) Brasilia, Buenos Aires, Georgetown', 'Atlantic/South_Georgia' => '(UTC-2) Mid-Atlantic', 'Atlantic/Azores' => '(UTC-1) Azores, Cape Verde Is.', 'Europe/London' => 'Greenwich Mean Time (Lisbon, London)', 'Europe/Berlin' => '(UTC+1) Amsterdam, Berlin, Paris, Rome, Madrid', 'Europe/Athens' => '(UTC+2) Athens, Helsinki, Istanbul, Cairo, E. Europe', 'Europe/Moscow' => '(UTC+3) Baghdad, Kuwait, Nairobi, Moscow', 'Iran' => '(UTC+3:30) Tehran', 'Asia/Dubai' => '(UTC+4) Abu Dhabi, Kazan, Muscat', 'Asia/Kabul' => '(UTC+4:30) Kabul', 'Asia/Yekaterinburg' => '(UTC+5) Islamabad, Karachi, Tashkent', 'Asia/Dili' => '(UTC+5:30) Bombay, Calcutta, New Delhi', 'Asia/Katmandu' => '(UTC+5:45) Nepal', 'Asia/Omsk' => '(UTC+6) Almaty, Dhaka', 'India/Cocos' => '(UTC+6:30) Cocos Islands, Yangon', 'Asia/Krasnoyarsk' => '(UTC+7) Bangkok, Jakarta, Hanoi', 'Asia/Hong_Kong' => '(UTC+8) Beijing, Hong Kong, Singapore, Taipei', 'Asia/Tokyo' => '(UTC+9) Tokyo, Osaka, Sapporto, Seoul, Yakutsk', 'Australia/Adelaide' => '(UTC+9:30) Adelaide, Darwin', 'Australia/Sydney' => '(UTC+10) Brisbane, Melbourne, Sydney, Guam', 'Asia/Magadan' => '(UTC+11) Magadan, Soloman Is., New Caledonia', 'Pacific/Auckland' => '(UTC+12) Fiji, Kamchatka, Marshall Is., Wellington')));
     // Init default locale
     $localeObject = Zend_Registry::get('Locale');
     $languages = Zend_Locale::getTranslationList('language', $localeObject);
     $territories = Zend_Locale::getTranslationList('territory', $localeObject);
     $localeMultiOptions = array();
     foreach (array_keys(Zend_Locale::getLocaleList()) as $key) {
         $languageName = null;
         if (!empty($languages[$key])) {
             $languageName = $languages[$key];
         } else {
             $tmpLocale = new Zend_Locale($key);
             $region = $tmpLocale->getRegion();
             $language = $tmpLocale->getLanguage();
             if (!empty($languages[$language]) && !empty($territories[$region])) {
                 $languageName = $languages[$language] . ' (' . $territories[$region] . ')';
             }
         }
         if ($languageName) {
             $localeMultiOptions[$key] = $languageName . ' [' . $key . ']';
         }
     }
     $localeMultiOptions = array_merge(array('auto' => '[Automatic]'), $localeMultiOptions);
     $this->addElement('Select', 'locale', array('label' => 'Default Locale', 'multiOptions' => $localeMultiOptions, 'value' => 'auto', 'disableTranslator' => true));
     // init submit
     $this->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true));
 }
开发者ID:robeendey,项目名称:ce,代码行数:31,代码来源:Locale.php

示例3: testDefaultLocale

    public function testDefaultLocale()
    {
        $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array());

        $defaultLocale = new Zend_Locale();
        $this->assertEquals($lang->getLocale(), $defaultLocale->toString());
    }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:7,代码来源:TranslateTest.php

示例4: build

 private static function build()
 {
     # recupera idioma requisitado ou tenta descobri-lo
     if (!($acronym = self::lang())) {
         $locale = new Zend_Locale();
         $acronym = $locale->getLanguage();
     }
     # seleciona idioma solicitado/utilizado
     $language = [];
     foreach (Ao_Data_Language::$data as $lang) {
         if ($acronym == $lang['acronym']) {
             $language = $lang;
             break;
         }
     }
     # set idioma padrão se nenhum for associado
     if (empty($language)) {
         $language = Ao_Data_Language::$data[self::LANG_ID];
     }
     # inicializa atributos
     $lang = new stdClass();
     $lang->id = $language['id'];
     $lang->acronym = $language['acronym'];
     $lang->name = $language['name'];
     # return
     return $lang;
 }
开发者ID:ao-lab,项目名称:ao-zend,代码行数:27,代码来源:Ao_Language.php

示例5: init

 public function init()
 {
     $this->setTitle('Language Manager')->setDescription('Create a new language pack')->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()));
     $localeObject = Zend_Registry::get('Locale');
     $languages = Zend_Locale::getTranslationList('language', $localeObject);
     $territories = Zend_Locale::getTranslationList('territory', $localeObject);
     $localeMultiOptions = array();
     foreach (array_keys(Zend_Locale::getLocaleList()) as $key) {
         $languageName = null;
         if (!empty($languages[$key])) {
             $languageName = $languages[$key];
         } else {
             $tmpLocale = new Zend_Locale($key);
             $region = $tmpLocale->getRegion();
             $language = $tmpLocale->getLanguage();
             if (!empty($languages[$language]) && !empty($territories[$region])) {
                 $languageName = $languages[$language] . ' (' . $territories[$region] . ')';
             }
         }
         if ($languageName) {
             $localeMultiOptions[$key] = $languageName . ' [' . $key . ']';
         }
     }
     //asort($languageNameList);
     $this->addElement('Select', 'language', array('label' => 'Language', 'description' => 'Which language do you want to create a language pack for?', 'multiOptions' => $localeMultiOptions));
     // Init submit
     $this->addElement('Button', 'submit', array('label' => 'Create', 'type' => 'submit', 'decorators' => array('ViewHelper')));
     $this->addElement('Cancel', 'cancel', array('prependText' => ' or ', 'link' => true, 'label' => 'cancel', 'onclick' => 'history.go(-1); return false;', 'decorators' => array('ViewHelper')));
 }
开发者ID:robeendey,项目名称:ce,代码行数:29,代码来源:Create.php

示例6: on_start

 public function on_start()
 {
     $this->error = Loader::helper('validation/error');
     if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == true) {
         $this->set('uNameLabel', t('Email Address'));
     } else {
         $this->set('uNameLabel', t('Username'));
     }
     $txt = Loader::helper('text');
     if (strlen($_GET['uName'])) {
         // pre-populate the username if supplied, if its an email address with special characters the email needs to be urlencoded first,
         $this->set("uName", trim($txt->email($_GET['uName'])));
     }
     $languages = array();
     $locales = array();
     if (Config::get('LANGUAGE_CHOOSE_ON_LOGIN')) {
         Loader::library('3rdparty/Zend/Locale');
         Loader::library('3rdparty/Zend/Locale/Data');
         $languages = Localization::getAvailableInterfaceLanguages();
         if (count($languages) > 0) {
             array_unshift($languages, 'en_US');
         }
         $locales = array('' => t('** Default'));
         Zend_Locale_Data::setCache(Cache::getLibrary());
         foreach ($languages as $lang) {
             $loc = new Zend_Locale($lang);
             $locales[$lang] = Zend_Locale::getTranslation($loc->getLanguage(), 'language', ACTIVE_LOCALE);
         }
     }
     $this->locales = $locales;
     $this->set('locales', $locales);
     $this->openIDReturnTo = BASE_URL . View::url("/login", "complete_openid");
 }
开发者ID:ricardomccerqueira,项目名称:rcerqueira.portfolio,代码行数:33,代码来源:login.php

示例7: getFromList

 public function getFromList(&$list)
 {
     $current_locale = I18n::getInstance()->getCurrentLanguage();
     $country = BizSystem::clientProxy()->getFormInputs("fld_region");
     $country = strtoupper($country);
     if (!$country) {
         $locale = explode('_', $current_locale);
         $country = strtoupper($locale[0]);
     }
     require_once 'Zend/Locale.php';
     $locale = new Zend_Locale($current_locale);
     $code2name = $locale->getTranslationList('territorytolanguage', $locale);
     $list = array();
     $i = 0;
     foreach ($code2name as $key => $value) {
         if (preg_match('/' . $country . '/', $value) || strtoupper($key) == $country) {
             $lang_list = explode(" ", $value);
             foreach ($lang_list as $lang) {
                 $list[$i]['txt'] = strtolower($key) . "_" . strtoupper($lang);
                 $list[$i]['val'] = strtolower($key) . "_" . strtoupper($lang);
                 $i++;
             }
         }
     }
     return $list;
 }
开发者ID:que273,项目名称:siremis,代码行数:26,代码来源:LanguageListbox.php

示例8: languageDetectionAction

 /**
  * @throws Exception
  */
 public function languageDetectionAction()
 {
     // Get the browser language
     $locale = new Zend_Locale();
     $browserLanguage = $locale->getLanguage();
     $languages = Tool::getValidLanguages();
     // Check if the browser language is a valid frontend language
     if (in_array($browserLanguage, $languages)) {
         $language = $browserLanguage;
     } else {
         // If it is not, take the first frontend language as default
         $language = reset($languages);
     }
     // Get the folder of the current language (in the current site)
     $currentSitePath = $this->document->getRealFullPath();
     $folder = Document\Page::getByPath($currentSitePath . '/' . $language);
     if ($folder) {
         $document = $this->findFirstDocumentByParentId($folder->getId());
         if ($document) {
             $this->redirect($document->getPath() . $document->getKey());
         } else {
             throw new Exception('No document found in your browser language');
         }
     } else {
         throw new Exception('No language folder found that matches your browser language');
     }
 }
开发者ID:studioemma,项目名称:multilingual,代码行数:30,代码来源:DefaultController.php

示例9: __construct

 /**
  * Constructure and setting configuration
  *
  * @param array $config
  * @throws Ht_Utils_PoCreater_Exception
  */
 public function __construct($config = array())
 {
     if (!isset($config[self::LOCAL_DIR_KEY])) {
         throw new Ht_Utils_PoCreater_Exception("Local path not setting !");
     }
     if (realpath($config[self::LOCAL_DIR_KEY])) {
         $this->_locales_dir = realpath($config[self::LOCAL_DIR_KEY]);
     } else {
         throw new Ht_Utils_PoCreater_Exception("Local path setting up is not exists!");
     }
     if (isset($config[self::LANGUAGE_KEY])) {
         if ($config[self::LANGUAGE_KEY] != "") {
             try {
                 $locale = new Zend_Locale($config[self::LANGUAGE_KEY]);
                 $this->_language = $locale->getLanguage();
             } catch (Ht_Utils_PoCreater_Exception $e) {
                 throw $e;
             }
         }
     }
     if (isset($config[self::ADAPTER_KEY]) && $config[self::ADAPTER_KEY] instanceof Zend_Db_Table_Abstract) {
         $this->_adapter = $config[self::ADAPTER_KEY];
     }
     if (isset($config[self::DATA_KEY])) {
         $this->_data = $config[self::DATA_KEY];
     }
 }
开发者ID:kangza,项目名称:hagtag,代码行数:33,代码来源:PoCreator.php

示例10: init

 public function init()
 {
     $controller = $this->getActionController();
     if (!($requestedLocale = $controller->getRequest()->getParam('language', false))) {
         $local = new Zend_Locale();
         $requestedLocale = $local->getLanguage();
     }
     if (is_array($requestedLocale)) {
         $requestedLocale = current($requestedLocale);
     }
     $requestedLocale = strtolower($requestedLocale);
     try {
         Centurion_Db::getSingleton('translation/language')->get(array('locale' => $requestedLocale));
     } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) {
         $requestedLocale = Translation_Traits_Common::getDefaultLanguage();
         $requestedLocale = $requestedLocale->locale;
     }
     Zend_Registry::get('Zend_Translate')->setLocale($requestedLocale);
     Zend_Locale::setDefault($requestedLocale);
     Zend_Registry::set('Zend_Locale', $requestedLocale);
     $options = Centurion_Db_Table_Abstract::getDefaultFrontendOptions();
     if (!isset($options['cache_id_prefix'])) {
         $options['cache_id_prefix'] = '';
     }
     $options['cache_id_prefix'] = $requestedLocale . '_' . $options['cache_id_prefix'];
     Centurion_Db_Table_Abstract::setDefaultFrontendOptions($options);
     //TODO: fix this when in test unit environment
     if (!APPLICATION_ENV === 'testing') {
         $this->getActionController()->getFrontController()->getParam('bootstrap')->getResource('cachemanager')->addIdPrefix($requestedLocale . '_');
     }
     if (Centurion_Config_Manager::get('translation.global_param')) {
         $this->getFrontController()->getRouter()->setGlobalParam('language', $requestedLocale);
     }
 }
开发者ID:rom1git,项目名称:Centurion,代码行数:34,代码来源:ManageLanguageParam.php

示例11: 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

示例12: iniTranslation

 /**
  * Init Translation system using gettext
  *
  * @param object $locale instance of Zend_Locale
  *
  * @return void
  */
 public function iniTranslation($locale, array $availableDomains = array())
 {
     if (!$locale instanceof Zend_Locale) {
         $locale = new Zend_Locale($locale);
     }
     $localeDirPath = $this->getConfig('localeDirPath');
     // init available gettext domains
     foreach ($availableDomains as $domain) {
         bindtextdomain($domain, $localeDirPath);
         bind_textdomain_codeset($domain, 'UTF-8');
     }
     // set first domain has default domain
     $defaultDomain = array_shift($availableDomains);
     textdomain($defaultDomain);
     $localeWithEncoding = $locale . '.utf8';
     // mandatory for gettext
     if (putenv('LANGUAGE') != $locale->getLanguage()) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Could not set the ENV variable LANGUAGE = %s', $locale));
     }
     if (setlocale(LC_MESSAGES, $localeWithEncoding) !== $localeWithEncoding) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Unable to set locale "%s" to value "%s", please check installed locales on system', 'LC_MESSAGES', $localeWithEncoding));
     }
     if (setlocale(LC_TIME, $localeWithEncoding) !== $localeWithEncoding) {
         throw new BaseZF_Service_GetText_Exception(sprintf('Unable to set locale "%s" to value "%s", please check installed locales on system', 'LC_TIME', $localeWithEncoding));
     }
     return $this;
 }
开发者ID:hthetiot,项目名称:basezf,代码行数:34,代码来源:GetText.php

示例13: getLanguage

 /**
  * Convenience function to get the current language
  *
  * @return string
  */
 public function getLanguage()
 {
     if (null === $this->resource) {
         $locale = new Zend_Locale();
         return $locale->getLanguage();
     }
     return $this->resource->getLanguage();
 }
开发者ID:wthielen,项目名称:zf1e,代码行数:13,代码来源:Multilanguage.php

示例14: 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

示例15: resolveLocale

 private function resolveLocale(\Zend_Locale $locale)
 {
     $proposed = array($locale->toString(), $locale->getLanguage(), self::DEFAULT_LANG);
     foreach ($proposed as $lang) {
         if (isset(self::$trans[$lang])) {
             return $lang;
         }
     }
 }
开发者ID:pago,项目名称:pantr,代码行数:9,代码来源:PeriodFormat.php


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