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


PHP Zend_Translate::isAvailable方法代码示例

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


在下文中一共展示了Zend_Translate::isAvailable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: translate

 /**
  * Retturn translation string
  * example $l->translate('Field %1 is incorrect', 'FieldName');
  *
  * @param string $msg Message to transalte.
  */
 public function translate($msg)
 {
     $translated = $msg;
     if ($this->translate->isTranslated($msg, true, $this->locale)) {
         $translated = $this->translate->translate($msg);
     } else {
         foreach ($this->translationsPaths as $name => $value) {
             if (!$this->translate->isAvailable($name)) {
                 try {
                     $this->translate->addTranslation($this->translationsPaths[$name], $name);
                     $this->translate->setLocale($this->getLocale());
                 } catch (Zend_Translate_Exception $e) {
                     continue;
                 }
             }
             if ($this->translate->isTranslated($msg, $name)) {
                 $translated = $this->translate->translate($msg, $name);
                 break;
             }
         }
     }
     if (func_num_args() > 1) {
         $params = func_get_args();
         $params[0] = $translated;
         $translated = @call_user_func_array("sprintf", $params);
         //add shield for incorrect translations(warning about incorrect number of arguments)
     }
     return $translated;
 }
开发者ID:pansot2,项目名称:PadCMS-backend,代码行数:35,代码来源:Localizer.php

示例3: setIniFilenameScanTranslator

 public function setIniFilenameScanTranslator($path, $defaultLanguage, $language = null)
 {
     require_once 'Zend/Translate.php';
     $translate = new Zend_Translate(Zend_Translate::AN_INI, $path, $defaultLanguage, array('scan' => Zend_Translate::LOCALE_FILENAME));
     if ($translate->isAvailable($language)) {
         $translate->setLocale($language);
     }
     $this->setTranslator($translate->getAdapter());
 }
开发者ID:sirprize,项目名称:xzend,代码行数:9,代码来源:Translate.php

示例4: _initTranslate

 public function _initTranslate()
 {
     $locale = new Zend_Locale(Zend_Locale::BROWSER);
     $translate = new Zend_Translate(array('adapter' => 'csv', 'content' => APPLICATION_PATH . '/configs/languages/lang.en', 'locale' => 'en'));
     $translate->addTranslation(array('content' => APPLICATION_PATH . '/configs/languages/lang.hi', 'locale' => 'hi'));
     if ($translate->isAvailable($locale->getLanguage())) {
         $translate->setLocale($locale);
     } else {
         $translate->setLocale('en');
     }
     Zend_Registry::set('Translate', $translate);
 }
开发者ID:nishant3001,项目名称:canopy,代码行数:12,代码来源:Bootstrap.php

示例5: _initLocale

 public function _initLocale()
 {
     $config = $this->getOptions();
     try {
         $locale = new Zend_Locale(Zend_Locale::BROWSER);
     } catch (Zend_Locale_Exception $e) {
         $locale = new Zend_Locale($config['resources']['locale']['default']);
     }
     Zend_Registry::set('Zend_Locale', $locale);
     $translator = new Zend_Translate(array('adapter' => 'Csv', 'content' => APPLICATION_PATH . '/../data/lang/', 'scan' => Zend_Translate::LOCALE_DIRECTORY, 'delimiter' => ',', 'disableNotices' => true));
     if (!$translator->isAvailable($locale->getLanguage())) {
         $translator->setLocale($config['resources']['locale']['default']);
     }
     Zend_Registry::set('Zend_Translate', $translator);
     Zend_Form::setDefaultTranslator($translator);
 }
开发者ID:nnevala,项目名称:zf-boilerplate,代码行数:16,代码来源:Bootstrap.php

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

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

示例8: testIsAvailable

 public function testIsAvailable()
 {
     $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1'), 'en');
     $lang->addTranslation(array('msg1' => 'Message 1 (ru)'), 'ru');
     $this->assertTrue($lang->isAvailable('en'));
     $this->assertTrue($lang->isAvailable('ru'));
     $this->assertFalse($lang->isAvailable('fr'));
 }
开发者ID:sasezaki,项目名称:mirror-zf1-tests,代码行数:8,代码来源:TranslateTest.php

示例9: getmypid

$writer->setFormatter(new Zend_Log_Formatter_Simple('%timestamp% %priorityName% %request% %remote%: %message%' . "\n"));
$filter = new Zend_Log_Filter_Priority((int) $configuration->log->level);
$writer->addFilter($filter);
$logger = new Zend_Log($writer);
$logger->setEventItem('pid', getmypid());
$logger->setEventItem('request', $_SERVER['REQUEST_URI']);
$logger->setEventItem('remote', $_SERVER['REMOTE_ADDR']);
// TRANSLATIONS
$locale = new Zend_Locale();
Zend_Registry::set('Zend_Locale', $locale);
// default language when requested language is not available
$defaultlanguage = 'en';
define('DEFAULT_LANGUAGE', 'en');
$translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/', null, array('scan' => Zend_Translate::LOCALE_FILENAME));
$translate->setOptions(array('log' => $logger, 'logUntranslated' => true));
if (!$translate->isAvailable($locale->getLanguage())) {
    // not available languages are rerouted to another language
    $translate->setLocale(DEFAULT_LANGUAGE);
}
// REGISTRY - setup the application registry
// An application registry allows the application to store application
// necessary objects into a safe and consistent (non global) place for future
// retrieval.  This allows the application to ensure that regardless of what
// happends in the global scope, the registry will contain the objects it
// needs.
$registry = Zend_Registry::getInstance();
$registry->configuration = $configuration;
$registry->arsConfig = $arsConfig;
$registry->logger = $logger;
$registry->translate = $translate;
Zend_Registry::set('Zend_Translate', $translate);
开发者ID:VUW-SIM-FIS,项目名称:emiemi,代码行数:31,代码来源:bootstrap.php

示例10: _initTranslate

 /**
  * Initialize the translate component.
  *
  * Scans the application and project dirs for available translations
  *
  * Use $this->translate to access afterwards
  * Also sets $this->translateAdapter to access afterwards
  *
  * @return \Zend_Translate
  */
 protected function _initTranslate()
 {
     $this->bootstrap('locale');
     $language = $this->locale->getLanguage();
     /*
      * Scan for files with -<languagecode> and disable notices when the requested
      * language is not found
      */
     $options = array('adapter' => 'gettext', 'content' => GEMS_LIBRARY_DIR . '/languages/', 'disableNotices' => true, 'scan' => \Zend_Translate::LOCALE_FILENAME);
     $translate = new \Zend_Translate($options);
     // If we don't find the needed language, use a fake translator to disable notices
     if (!$translate->isAvailable($language)) {
         $translate = \MUtil_Translate_Adapter_Potemkin::create();
     }
     //Now if we have a project specific language file, add it
     $projectLanguageDir = APPLICATION_PATH . '/languages/';
     if (file_exists($projectLanguageDir)) {
         $options['content'] = $projectLanguageDir;
         $options['disableNotices'] = true;
         $projectTranslations = new \Zend_Translate($options);
         //But only when it has the requested language
         if ($projectTranslations->isAvailable($language)) {
             $translate->addTranslation(array('content' => $projectTranslations));
         }
         unset($projectTranslations);
         //Save some memory
     }
     $translate->setLocale($language);
     \Zend_Registry::set('Zend_Translate', $translate);
     // Fix for _init resourcea being case insensitive
     $container = $this->getContainer();
     $adapter = $translate->getAdapter();
     $container->translateAdapter = $adapter;
     $this->translateAdapter = $adapter;
     return $translate;
 }
开发者ID:GemsTracker,项目名称:gemstracker-library,代码行数:46,代码来源:GemsEscort.php


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