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


PHP Zend_Locale::getBrowser方法代码示例

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


在下文中一共展示了Zend_Locale::getBrowser方法的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: get_smart_locale

 /**
  * Try very hard to get a locale for this user. Helps for i18n etc.
  * @return string
  */
 public static function get_smart_locale($language = null)
 {
     require_once FRAMEWORK_PATH . '/thirdparty/Zend/Locale.php';
     $locale = Zend_Locale::getBrowser();
     if (!$locale) {
         if ($language) {
             return i18n::get_locale_from_lang($language);
         } else {
             return i18n::get_locale();
         }
     }
     $locale = array_keys($locale);
     $firstPref = array_shift($locale);
     if (strpos($firstPref, '_') === false) {
         return i18n::get_locale_from_lang($language);
     }
     return $firstPref;
 }
开发者ID:betterbrief,项目名称:silverstripe-opauth,代码行数:22,代码来源:OpauthResponseHelper.php

示例3: getBestAvailableLanguageFromBrowser

 /**
  * Get best available language setting from browser
  * if browser = es_AR and no es_AR.mo but es.mo, load es.mo
  * @return string language name
  */
 public function getBestAvailableLanguageFromBrowser()
 {
     $acceptedLangsByBrowser = $this->_zLocale->getBrowser();
     array_multisort($acceptedLangsByBrowser, SORT_DESC, SORT_NUMERIC);
     $currentLanguage = I18n::DEFAULT_LANGUAGE;
     if ($acceptedLangsByBrowser != null) {
         foreach ($acceptedLangsByBrowser as $acceptedLang => $quality) {
             $isAvailable = $this->_loadLanguage($acceptedLang);
             if ($isAvailable === FALSE) {
                 $parts = explode('_', $acceptedLang);
                 $isAvailable = $this->_loadLanguage($parts[0]);
             }
             if ($isAvailable) {
                 $currentLanguage = $acceptedLang;
                 break;
             }
         }
     }
     return $currentLanguage;
 }
开发者ID:que273,项目名称:siremis,代码行数:25,代码来源:I18n.php

示例4: _addTranslationData

 protected function _addTranslationData($data, $locale, array $options = array())
 {
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
     }
     if ($options['clear'] || !isset($this->_translate[$locale])) {
         $this->_translate[$locale] = array();
     }
     $ext = strtolower(ltrim(strrchr($data, '.'), '.'));
     if (!isset($this->_extToParser[$ext])) {
         return false;
     }
     $class = $this->_extToParser[$ext];
     $temp = call_user_func(array($class, 'parse'), $data, $locale, $options);
     if (empty($temp)) {
         $temp = array();
     }
     $keys = array_keys($temp);
     foreach ($keys as $key) {
         if (!isset($this->_translate[$key])) {
             $this->_translate[$key] = array();
         }
         $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language])) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     return $this;
 }
开发者ID:febryantosulistyo,项目名称:ClassicSocial,代码行数:40,代码来源:Null.php

示例5: _addTranslationData

 /**
  * Internal function for adding translation data
  *
  * This may be a new language or additional data for an existing language
  * If the options 'clear' is true, then the translation data for the specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|Zend_Config $content Translation data to add
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($options = array())
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } else {
         if (func_num_args() > 1) {
             $args = func_get_args();
             $options['content'] = array_shift($args);
             if (!empty($args)) {
                 $options['locale'] = array_shift($args);
             }
             if (!empty($args)) {
                 $options += array_shift($args);
             }
         }
     }
     if ($options['content'] instanceof Zend_Translate || $options['content'] instanceof Zend_Translate_Adapter) {
         $options['usetranslateadapter'] = true;
         if (!empty($options['locale']) && $options['locale'] !== 'auto') {
             $options['content'] = $options['content']->getMessages($options['locale']);
         } else {
             $content = $options['content'];
             $locales = $content->getList();
             foreach ($locales as $locale) {
                 $options['locale'] = $locale;
                 $options['content'] = $content->getMessages($locale);
                 $this->_addTranslationData($options);
             }
             return $this;
         }
     }
     try {
         $options['locale'] = Zend_Locale::findLocale($options['locale']);
     } catch (Zend_Locale_Exception $e) {
         #require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e);
     }
     if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
         $this->_translate[$options['locale']] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
         $temp = self::$_cache->load($id);
         if ($temp) {
             $read = false;
         }
     }
     if ($options['reload']) {
         $read = true;
     }
     if ($read) {
         if (!empty($options['usetranslateadapter'])) {
             $temp = array($options['locale'] => $options['content']);
         } else {
             $temp = $this->_loadTranslationData($options['content'], $options['locale'], $options);
         }
     }
     if (empty($temp)) {
         $temp = array();
     }
     $keys = array_keys($temp);
     foreach ($keys as $key) {
         if (!isset($this->_translate[$key])) {
             $this->_translate[$key] = array();
         }
         if (array_key_exists($key, $temp) && is_array($temp[$key])) {
             $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
         }
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($options['locale']);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language])) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
         if (self::$_cacheTags) {
             self::$_cache->save($temp, $id, array($this->_options['tag']));
         } else {
             self::$_cache->save($temp, $id);
         }
//.........这里部分代码省略.........
开发者ID:ankitsapient,项目名称:testgithubankit,代码行数:101,代码来源:Adapter.php

示例6: _addTranslationData

 /**
  * Internal function for adding translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|string       $data    Translation data
  * @param  string|Zend_Locale $locale  Locale/Language to add data for, identical with locale identifier,
  *                                     @see Zend_Locale for more information
  * @param  array              $options (optional) Option for this Adapter
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides a fluid interface
  */
 private function _addTranslationData($data, $locale, array $options = array())
 {
     if (!($locale = Zend_Locale::isLocale($locale))) {
         /**
          * @see Zend_Translate_Exception
          */
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
     }
     if (!array_key_exists($locale, $this->_translate)) {
         $this->_translate[$locale] = array();
     }
     $this->_loadTranslationData($data, $locale, $options);
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getBrowser() + $find->getEnvironment();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (array_key_exists($language, $this->_translate)) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . $this->toString();
         $temp = $this->_translate;
         $temp['_options_'] = $this->_options;
         self::$_cache->save(serialize($temp), $id);
     }
     return $this;
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:47,代码来源:Adapter.php

示例7: _initLanguage

 protected function _initLanguage()
 {
     $available_languages = Core_Model_Language::getLanguageCodes();
     $current_language = in_array($this->_request->getLanguageCode(), $available_languages) ? $this->_request->getLanguageCode() : '';
     $language_session = Core_Model_Language::getSession();
     $language = '';
     if ($language_session) {
         $language = $language_session->current_language;
     }
     if (!empty($current_language)) {
         Core_Model_Language::setCurrentLanguage($current_language);
     } else {
         if (!empty($language)) {
             //            $this->_request->setLanguageCode($language);
         } else {
             if ($accepted_languages = Zend_Locale::getBrowser()) {
                 $accepted_languages = array_keys($accepted_languages);
                 //            $accepted_languages = preg_split('/(,)|(;)|(-)|(=)/', $accepted_languages);
                 foreach ($accepted_languages as $lang) {
                     if (in_array($lang, $available_languages)) {
                         $current_language = $lang;
                         break;
                     }
                 }
                 if (!$current_language) {
                     $current_language = Core_Model_Language::getDefaultLanguage();
                 }
                 Core_Model_Language::setCurrentLanguage($current_language);
             }
         }
     }
 }
开发者ID:BeamlabsTigre,项目名称:Webapp,代码行数:32,代码来源:Bootstrap.php

示例8: addTranslation

    /**
     * Add translation data
     *
     * It may be a new language or additional data for existing language
     * If $clear parameter is true, then translation data for specified
     * language is replaced and added otherwise
     *
     * @param  array|string          $data    Translation data
     * @param  string|Zend_Locale    $locale  Locale/Language to add data for, identical with locale identifier,
     *                                        see Zend_Locale for more information
     * @param  array                 $options OPTIONAL Option for this Adapter
     * @throws Zend_Translate_Exception
     */
    public function addTranslation($data, $locale, array $options = array())
    {
        if (!$locale = Zend_Locale::isLocale($locale)) {
            throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
        }

        if (!in_array($locale, $this->_languages)) {
            $this->_languages[$locale] = $locale;
        }

        $this->_loadTranslationData($data, $locale, $options);
        if ($this->_automatic === true) {
            $find = new Zend_Locale($locale);
            $browser = $find->getBrowser() + $find->getEnvironment();
            arsort($browser);
            foreach($browser as $language => $quality) {
                if (in_array($language, $this->_languages)) {
                    $this->_locale = $language;
                    break;
                }
            }
        }
    }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:36,代码来源:Adapter.php

示例9: _initLanguage

 protected function _initLanguage()
 {
     $available_languages = Core_Model_Language::getLanguageCodes();
     $current_language = in_array($this->getRequest()->getLanguageCode(), $available_languages) ? $this->getRequest()->getLanguageCode() : "";
     $language_session = Core_Model_Language::getSession();
     $language = '';
     if (!$this->getRequest()->isApplication()) {
         if ($language_session->current_language) {
             $language = $language_session->current_language;
         } else {
             if (!$this->getRequest()->isInstalling()) {
                 $current_language = System_Model_Config::getValueFor("system_default_language");
             }
         }
     } else {
         $language = $language_session->current_language;
     }
     if (!empty($current_language)) {
         Core_Model_Language::setCurrentLanguage($current_language);
     } else {
         if (!empty($language)) {
         } else {
             if ($accepted_languages = Zend_Locale::getBrowser()) {
                 $accepted_languages = array_keys($accepted_languages);
                 foreach ($accepted_languages as $lang) {
                     if (in_array($lang, $available_languages)) {
                         $current_language = $lang;
                         break;
                     }
                 }
                 if (!$current_language) {
                     $current_language = Core_Model_Language::getDefaultLanguage();
                 }
                 Core_Model_Language::setCurrentLanguage($current_language);
             } else {
                 Core_Model_Language::setCurrentLanguage(Core_Model_Language::getDefaultLanguage());
             }
         }
     }
 }
开发者ID:bklein01,项目名称:siberian_cms_2,代码行数:40,代码来源:Default.php

示例10: initializeLocalization

 /**
  * 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')));
 }
开发者ID:svenjantzen,项目名称:imscp,代码行数:41,代码来源:Initializer.php

示例11: getBrowserLanguage

 /**
  * Check user browser and choose first valid locale.
  *
  * @return string|null
  */
 protected function getBrowserLanguage()
 {
     $locale = null;
     // detection of user browser language preference
     $browser = \Zend_Locale::getBrowser();
     $valid = Tool::getValidLanguages();
     foreach ($browser as $lang => $p) {
         $lang = explode('_', $lang);
         if (in_array($lang[0], $valid)) {
             $locale = $lang[0];
             break;
         }
     }
     return $locale;
 }
开发者ID:hagith,项目名称:pimcore-boilerplate,代码行数:20,代码来源:Action.php

示例12: _addTranslationData

 /**
  * Internal function for adding translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|string       $data    Translation data
  * @param  string|Zend_Locale $locale  Locale/Language to add data for, identical with locale identifier,
  *                                     @see Zend_Locale for more information
  * @param  array              $options (optional) Option for this Adapter
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($data, $locale, array $options = array())
 {
     if (!Zend_Locale::isLocale($locale, true, false)) {
         if (!Zend_Locale::isLocale($locale, false, false)) {
             /**
              * @see Zend_Translate_Exception
              */
             require_once 'Zend/Translate/Exception.php';
             throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
         }
         $locale = new Zend_Locale($locale);
     }
     $locale = (string) $locale;
     if (isset($this->_translate[$locale]) === false) {
         $this->_translate[$locale] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
         $result = self::$_cache->load($id);
         if ($result) {
             $this->_translate[$locale] = unserialize($result);
             $read = false;
         }
     }
     if ($read) {
         $this->_loadTranslationData($data, $locale, $options);
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language]) === true) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
         self::$_cache->save(serialize($this->_translate[$locale]), $id);
     }
     return $this;
 }
开发者ID:ankuradhey,项目名称:dealtrip,代码行数:60,代码来源:Adapter.php

示例13: testgetBrowser

 /**
  * test getBrowser
  * expected true
  */
 public function testgetBrowser()
 {
     putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2");
     $value = new Zend_Locale();
     $list = $value->getBrowser();
     $this->assertTrue(isset($list['de']));
 }
开发者ID:jon9872,项目名称:zend-framework,代码行数:11,代码来源:LocaleTest.php

示例14: addTranslation

 /**
  * Add translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @param  array|string          $data    Translation data
  * @param  string|Zend_Locale    $locale  Locale/Language to add data for, identical with locale identifier,
  *                                        see Zend_Locale for more information
  * @param  array                 $options OPTIONAL Option for this Adapter
  * @throws Zend_Translate_Exception
  */
 public function addTranslation($data, $locale, array $options = array())
 {
     if (!($locale = Zend_Locale::isLocale($locale))) {
         throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
     }
     if (!array_key_exists($locale, $this->_translate)) {
         $this->_translate[$locale] = array();
     }
     $this->_loadTranslationData($data, $locale, $options);
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getBrowser() + $find->getEnvironment();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (array_key_exists($language, $this->_translate)) {
                 $this->_locale = $language;
                 break;
             }
         }
     }
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . $this->toString();
         self::$_cache->save(serialize($this->_translate), $id);
     }
 }
开发者ID:ismaelmelus,项目名称:home,代码行数:38,代码来源:Adapter.php

示例15: testBrowser

 /**
  * test getBrowser
  * expected true
  */
 public function testBrowser()
 {
     $value = new Zend_Locale();
     $default = $value->getBrowser();
     $this->assertTrue(is_array($default));
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:10,代码来源:LocaleTest.php


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