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


PHP Zend_Translate::addTranslation方法代码示例

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


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

示例1: _initLanguages

    protected function _initLanguages()
    {
        $languageDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages';
        Zend_Registry::set('languageDir', $languageDir);

        $translate = new Zend_Translate(
            'gettext', $languageDir
        );

        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'en_GB.mo', 'en');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'fr_FR.mo', 'fr');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'it_IT.mo', 'it');
        $translate->addTranslation($languageDir . DIRECTORY_SEPARATOR . 'ru_RU.mo', 'ru');

        $locale = new Zend_Session_Namespace('locale');
        if ($locale->value === null) {

            $config_model  = new Default_Model_Configuration();
            $locale_config = $config_model->getKey('locale');

            isset($locale_config) ? $locale->value = $locale_config : $locale->value = 'en';
        }

        $translate->setLocale($locale->value);

        Zend_Registry::set('tr', $translate);
        Zend_Registry::set('Zend_Translate', $translate);
        Zend_Registry::set('Zend_Locale', $locale);
    }
开发者ID:reith2004,项目名称:frapi,代码行数:29,代码来源:Bootstrap.php

示例2: _initTranslate

 protected function _initTranslate()
 {
     $registry = Zend_Registry::getInstance();
     $this->_translate = $registry->get('Zend_Translate');
     $this->_translate->addTranslation(array('adapter' => 'array', 'content' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'locales', 'scan' => Zend_Translate::LOCALE_DIRECTORY));
     $registry->set('Zend_Translate', $this->_translate);
     return $registry;
 }
开发者ID:brunopbaffonso,项目名称:ongonline,代码行数:8,代码来源:Bootstrap.php

示例3: _loadFromFiles

 /**
  * @param array $files
  */
 protected function _loadFromFiles(array $files)
 {
     $translate = new Zend_Translate('Array', $files['en'], 'en');
     /** @var Zend_Translate_Adapter_Array $translate */
     $translate->addTranslation(array('content' => $files['nl'], 'locale' => 'nl'));
     return $translate;
 }
开发者ID:WebSpider,项目名称:OpenConext-engineblock,代码行数:10,代码来源:CacheProxy.php

示例4: preDispatch

 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     //set lang var to session
     $nsLang = new Zend_Session_Namespace("Language");
     $lang = "vi";
     if ($request->getParam("lang") != "") {
         $lang = $request->getParam("lang");
     } else {
         if ($nsLang->language != "") {
             $lang = $nsLang->language;
         }
     }
     $nsLang->language = $lang;
     //Set back to session
     $options = array('disableNotices' => true, 'logUntranslated' => false);
     $commonLang = new Zend_Translate("tmx", APP_PATH . "/languages/common.tmx", $lang, $options);
     $controller = $request->getControllerName();
     $langPath = APP_PATH . "/languages/" . $controller . ".tmx";
     if (file_exists($langPath)) {
         $commonLang->addTranslation($langPath, $lang);
     }
     $registry = Zend_Registry::getInstance();
     $registry->set("translate", $commonLang);
     return $lang;
 }
开发者ID:BGCX261,项目名称:zillatek-project-svn-to-git,代码行数:25,代码来源:Lang.php

示例5: __construct

 /**
  * Create a new GettextZendTranslator and configure it with passed params
  * @param string|Zend_Locale $given_locale
  * @param string $filename
  * @param boolean $default_instance If none instance yet, this instance will be used whatever this param value is
  */
 public function __construct($given_locale = null, $filename = null, $default_instance = true)
 {
     if ($filename != null) {
         $this->filename = $filename;
     }
     self::$absolutePath = Config::getInstance()->getString('appRootDir') . self::DIR_LOCALES;
     $this->debugMode = Config::getInstance()->getBoolean('i18n/gettextZendTranslator/debug', false);
     $path = self::$absolutePath . self::DEFAULT_LOCALE . '/' . $this->filename;
     parent::__construct(self::GETTEXT, $path, self::DEFAULT_LOCALE);
     // Adding other existing locales
     $locales = $this->getAvailableLocales();
     foreach ($locales as $locale) {
         if ($locale != self::DEFAULT_LOCALE) {
             parent::addTranslation(self::$absolutePath . $locale . '/' . $this->filename, $locale);
         }
     }
     if ($given_locale == null) {
         if (($given_locale = Zend_Registry::get('Zend_Locale')) == null) {
             $given_locale = self::DEFAULT_LOCALE;
         }
     }
     $this->setLocale($given_locale);
     Zend_Registry::set('Zend_Translator', $this);
     if ($default_instance || self::$instance == null) {
         self::$instance = $this;
     }
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:33,代码来源:GettextZendTranslator.php

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

示例7: _initTranslate

 protected function _initTranslate()
 {
     $translate = new Zend_Translate('gettext', APPLICATION_PATH . '/data/languages/zh.mo', 'zh');
     $translate->addTranslation(APPLICATION_PATH . '/data/languages/en.mo', 'en');
     //$translate->setLocale('zh');
     $translate->setLocale('en');
     Zend_Registry::set('translate', $translate);
 }
开发者ID:sandin,项目名称:iMemo,代码行数:8,代码来源:Bootstrap.php

示例8: routeShutdown

 /**	@brief Changement de langue.
  * 
  * Exploitation du cache de l'application pour stocker l'instance de Zend_Translate correspondant.
  * Si le cache n'est pas présent, une nouvelle instance est créée, puis stockée dans le cache de Zend_Translate.
  * 
  * @see		Controller/Plugin/Zend_Controller_Plugin_Abstract::routeShutdown()
  * @throws	exception Projet_Exception en cas d'erreur au cours de la requête.
  * @return	void.
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     parent::routeShutdown($request);
     // Récupération du paramètre de langue passée dans l'URL
     $sLocal = $this->getRequest()->getParam('language') ? $this->getRequest()->getParam('language') : self::DEFAULT_LANGUAGE;
     // Récupération du local dans une combinaison du type "fr_FR"
     $aLanguage = explode("_", $sLocal);
     $sLanguage = isset($aLanguage[0]) ? $aLanguage[0] : self::DEFAULT_LANGUAGE;
     # Récupération de "fr"
     $sCountry = isset($aLanguage[1]) ? $aLanguage[1] : self::DEFAULT_COUNTRY;
     # Récupération de "FR"
     // Fonctionnalité réalisée si le fichier de langue n'existe pas
     if (!file_exists(LANGUAGE_PATH . $sLanguage . '.ini')) {
         $sLanguage = self::DEFAULT_LANGUAGE;
     }
     // Récupération du cache de la langue en cours dans le cache de Zend_Translate
     if ((bool) APP_CACHE) {
         $oCacheTranslate = Zend_Translate::getCache();
         $oTranslate = $oCacheTranslate->load($sLanguage);
     } else {
         $oTranslate = null;
     }
     // Fonctionnalité réalisé si
     if (empty($oTranslate)) {
         // Initialisation de la langue
         try {
             // Chargement du Zend_Translate
             $oTranslate = new Zend_Translate(array('adapter' => 'ini', 'content' => LANGUAGE_PATH . $sLanguage . '.ini', 'locale' => $sLocal));
             $sFichier = LANGUAGE_PATH . $sLanguage . '.php';
             if (file_exists($sFichier)) {
                 //traduction des erreurs de formulaires
                 $oTranslate->addTranslation(array('content' => new Zend_Translate('array', $sFichier, $sLanguage)));
             }
             if ((bool) APP_CACHE) {
                 // Enregistrement de la langue dans le cache
                 $oCacheTranslate = Zend_Translate::getCache();
                 $oCacheTranslate->save($oTranslate, $sLanguage);
             }
         } catch (Exception $e) {
             if ((bool) APP_CACHE) {
                 // Suppression du cache
                 $oCacheTranslate->remove($sLanguage);
             }
             // Création d'une exception au niveau du projet
             die($e->getMessage());
             throw new Projet_Exception($e->getMessage(), __METHOD__, $e);
         }
     }
     // Enregistrement du Zend_Translate dans les fonctionnalités de l'application
     Zend_Registry::set("Zend_Locale", $sLocal);
     Zend_Registry::set("Zend_Translate", $oTranslate);
     // Potentiellement inutile vu la ligne précédente...
     Zend_Form::setDefaultTranslator($oTranslate);
     Zend_Validate_Abstract::setDefaultTranslator($oTranslate);
     // Language par défaut pour toutes les routes
     Zend_Controller_Front::getInstance()->getRouter()->setGlobalParam('language', $sLocal);
 }
开发者ID:netixx,项目名称:Stock,代码行数:66,代码来源:Translate.php

示例9: _initLanguage

 protected function _initLanguage()
 {
     try {
         $translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/en.csv', 'en');
         $translate->addTranslation(APPLICATION_PATH . '/languages/br.csv', 'br');
         Zend_Registry::set('Zend_Translate', $translate);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
开发者ID:erickosma,项目名称:e-ong,代码行数:10,代码来源:Bootstrap.php

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

示例11: addSiteInterfaceLanguage

 /** Loads the site interface locale.
  * @param string $locale = null The locale to load (for instance: 'en_US'). If empty we'll use the currently active locale
  */
 public function addSiteInterfaceLanguage($locale = null)
 {
     if (is_object($this->translate)) {
         if (!(is_string($locale) && strlen($locale))) {
             $locale = $this->translate->getLocale();
         }
         $path = DIR_LANGUAGES_SITE_INTERFACE . '/' . $locale . '.mo';
         if (is_file($path)) {
             $this->translate->addTranslation($path, $locale);
         }
     }
 }
开发者ID:Zyqsempai,项目名称:amanet,代码行数:15,代码来源:localization.php

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

示例13: setUp

 /**
  * Setup test
  *
  * @return void
  */
 public function setUp()
 {
     // Backup server array
     $this->_server = $_SERVER;
     // Clean host env
     unset($_SERVER['HTTP_HOST'], $_SERVER['HTTPS'], $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT']);
     // Set translator
     $translator = new Zend_Translate('array', array('foo' => 'en_foo', 'bar' => 'en_bar'), 'en');
     $translator->addTranslation(array('foo' => 'de_foo', 'bar' => 'de_bar'), 'de');
     $translator->setLocale('en');
     Zend_Registry::set('Zend_Translate', $translator);
 }
开发者ID:netvlies,项目名称:zf,代码行数:17,代码来源:RouteTest.php

示例14: preDispatch

 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // Die CSV-Dateien laden
     $translate = new Zend_Translate('csv', '../application/config/lang.de.csv', 'de');
     $translate->addTranslation('../application/config/lang.en.csv', 'en');
     // sprache einstellen
     $translate->setLocale('de');
     // translateobjekt in der registry speichern
     $registry = Zend_Registry::getInstance();
     $registry->set('translate', $translate);
     // für alle Formular der Klasse Zend_Form das standard translate objekt setzen
     Zend_Form::setDefaultTranslator($translate);
 }
开发者ID:blackskaarj,项目名称:webgr,代码行数:13,代码来源:Translate.php

示例15: init

 /**
  * (non-PHPdoc)
  * @see Zend_Application_Resource_Resource::init()
  * @return Zend_Translate
  */
 public function init()
 {
     $options = $this->getOptions();
     $adapter = $options['adapter'];
     $defaultTranslation = $options['default']['file'];
     $defaultLocale = $options['default']['locale'];
     $translate = new Zend_Translate($adapter, $defaultTranslation, $defaultLocale);
     foreach ($options['translation'] as $locale => $translation) {
         $translate->addTranslation($translation, $locale);
     }
     Zend_Registry::set('Zend_Translate', $translate);
     return $translate;
 }
开发者ID:Rud5G,项目名称:zfbase,代码行数:18,代码来源:Translate.php


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