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;
 }
Example #2
0
 protected function _initSetTranslations()
 {
     $translate = new Zend_Translate(array('adapter' => 'gettext', 'content' => APPLICATION_PATH . '/../library/Rdine/Translate/Language', 'locale' => null, 'scan' => Zend_Translate::LOCALE_FILENAME));
     $namespace = new Zend_Session_Namespace();
     $language = 'en';
     if ($namespace->lang) {
         if ($namespace->lang == 'en_US') {
             $language = 'en';
             $namespace->lang = 'en_US';
         }
         if ($namespace->lang == 'es_SP') {
             $language = 'es_SP';
         }
     } else {
         $language = 'en';
         $namespace->lang = 'en_US';
     }
     $translate->setLocale($language);
     $view = $this->getResource('view');
     $view->translate = $translate;
     if ($namespace->lang) {
         $view->lang = $namespace->lang;
     } else {
         $view->lang = 'en_US';
         $namespace->lang = 'en_US';
     }
 }
 public function getMessages(\Zend_Translate $t)
 {
     if ($this->checkedRespondentTracks) {
         $messages[] = sprintf($t->_('Checked %d tracks.'), $this->checkedRespondentTracks);
     }
     if ($this->checkedTokens || !$this->checkedRespondentTracks) {
         $messages[] = sprintf($t->_('Checked %d tokens.'), $this->checkedTokens);
     }
     if ($this->hasChanged()) {
         if ($this->surveyCompletionChanges) {
             $messages[] = sprintf($t->_('Answers changed by survey completion event for %d tokens.'), $this->surveyCompletionChanges);
         }
         if ($this->resultDataChanges) {
             $messages[] = sprintf($t->_('Results and timing changed for %d tokens.'), $this->resultDataChanges);
         }
         if ($this->roundCompletionChanges) {
             $messages[] = sprintf($t->_('%d token round completion events caused changed to %d tokens.'), $this->roundCompletionCauses, $this->roundCompletionChanges);
         }
         if ($this->tokenDateChanges) {
             $messages[] = sprintf($t->_('%2$d token date changes in %1$d tracks.'), $this->tokenDateCauses, $this->tokenDateChanges);
         }
         if ($this->roundChangeUpdates) {
             $messages[] = sprintf($t->_('Round changes propagated to %d tokens.'), $this->roundChangeUpdates);
         }
         if ($this->deletedTokens) {
             $messages[] = sprintf($t->_('%d tokens deleted by round changes.'), $this->deletedTokens);
         }
         if ($this->createdTokens) {
             $messages[] = sprintf($t->_('%d tokens created to by round changes.'), $this->createdTokens);
         }
     } else {
         $messages[] = $t->_('No tokens were changed.');
     }
     return $messages;
 }
 /**
  * @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;
 }
Example #5
0
 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) {
         }
     }
 }
Example #6
0
 public static function getValues(Zend_Translate $lang)
 {
     $countries = Zend_Locale::getTranslationList('Territory', $lang->getLocale(), 2);
     $continents = Zend_Locale::getTranslationList('Territory', $lang->getLocale(), 1);
     array_unshift($countries, current($continents));
     return $countries;
 }
 function fileToDbAction()
 {
     $translator = new Zend_Translate('ini', APPLICATION_PATH . '/languages/tran_en.ini', 'en');
     $data = $translator->getAdapter()->getDataList();
     foreach ($data['en'] as $key => $value) {
         echo " {$key} => {$value}";
         $ln = new Sys_Model_Translation();
         $ln->setKey($key);
         $ln->setEn($value);
         $ln->save();
     }
     /*
     					$translator = new Zend_Translate('ini', APPLICATION_PATH . '/languages/tran_th.ini', 'en');
         				$data = ($translator->getAdapter()->getDataList());
     foreach ($data['en'] as $key => $value){
     	echo " $key => $value";
     	$ln = new Sys_Model_Translation();
     	$ln->setKey($key);
     	$ln->setLanguage('EN');
     	$ln->setValue($value);
     	$ln->save();
     }
     */
     $this->_helper->redirector('index');
     $this->render('blank', null, true);
 }
Example #8
0
 public static function setMessage(Zend_Translate $message)
 {
     if (!$message->getAdapter() instanceof Core_Translate_Message) {
         throw new InvalidArgumentException('O adapter dever ser Core_Translate_Message');
     }
     static::set(static::MESSAGE, $message);
 }
Example #9
0
 /**
  * Add a translated message to headtitle
  * @param string $msg
  * @return App_Controller_Action
  */
 protected function _addHeadTitle($msg)
 {
     $separator = " - ";
     $msg = self::$_translate->_($msg);
     $this->view->headTitle($separator . $msg);
     return $this;
 }
Example #10
0
/**
 * Hook for SECTION: i18n (translation)
 */
function _($msg)
{
    /////////////////////////////
    // ==> SECTION: i18n <==
    // Need volunteers to help create translations for the catalog in data/zfdemo.mo
    // Nice tool to help manage the gettext catalog: http://www.poedit.net/
    static $translator = null;
    if ($translator === null) {
        require_once 'Zend/Translate.php';
        $registry = Zend_Registry::getInstance();
        $translator = new Zend_Translate('gettext', $registry['dataDir'] . 'zfdemo.mo', $registry['userLocale']);
    }
    if (func_num_args() === 1) {
        return $translator->_($msg);
    } else {
        $args = func_get_args();
        array_shift($args);
        return vsprintf($translator->_($msg), $args);
    }
    /////////////////////////////
    // ==> SECTION: mvc <==
    if (func_num_args() === 1) {
        return $msg;
    } else {
        $args = func_get_args();
        array_shift($args);
        return vsprintf($msg, $args);
    }
}
Example #11
0
	static function translate($locale_code, $module_name, $key, $replace = null, $do_translation = true) {

// DON'T EVER LEAVE THIS UNCOMMENTED
// ob_clean();
// can be useful for debugging since using dd() will dump out into the existing markup and be hard to see
// but this clears out all the other markup so the debug data can be seen clearly

		$translation = $key;
		if ($do_translation) {
			if (RivetyCore_Registry::get('enable_localization') == '1'
			 && !is_null($module_name) && trim($module_name) != ""
			 && !is_null($key) && trim($key) != "") {
				$locale_code = RivetyCore_Translate::cleanZendLocaleCode($locale_code);

				// TODO: account for core rivety module
				$path_to_csv = RivetyCore_Registry::get('basepath')."/modules/".$module_name."/languages/".$locale_code.".csv";

				if (file_exists($path_to_csv)) {
					try {
						$translate = new Zend_Translate("csv", $path_to_csv, $locale_code, array('delimiter' => ","));
						$translation = $translate->_($key);
						// this next bit will populate the locale file with untranslated terms
						// so it's easier for someone to go through and translate them
						if (RivetyCore_Registry::get('auto_populate_language_files') == '1') {
							if (!$translate->isTranslated($key, true, $locale_code)) {
								$key_no_quotes = str_replace('"', '&quot;', $key);
								$str = '"'.$key_no_quotes.'","'.$key_no_quotes.'"'."\n";
								file_put_contents($path_to_csv, $str, FILE_APPEND);
							}
						}
					} catch (Exception $e) {
						$translation = $key;
					}
				} else {
					// create the file
					file_put_contents($path_to_csv, $key.','.$key);
				}
			}
		}
		$output = "";
		if (is_null($replace)) {
			// no replace, no sprintf
			$output = $translation;
		} else {
			if (is_array($replace)) {
				if (count($replace) > 1) {
					// there are multiple indices, use vsprintf
					$output = vsprintf($translation, $replace);
				} else {
					// there's only one index, use the cheaper sprintf instead
					$output = sprintf($translation, $replace[0]);
				}
			} else {
				// $replace is not an array, so try using it straight
				$output = sprintf($translation, $replace);
			}
		}
		return $output;
	}
Example #12
0
 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;
 }
 protected function _initTranslation()
 {
     $translate = new Zend_Translate('Array', APPLICATION_PATH . '/configs/languages/pt_BR.php', 'pt_BR');
     $translate->setLocale('pt_BR');
     Zend_Registry::set('Zend_Translate', $translate);
     $locale = new Zend_Locale('pt_BR');
     Zend_Registry::set('Zend_Locale', $locale);
 }
Example #14
0
 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);
 }
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @param  mixed $content
  * @return boolean
  * @throws \Zend_Validate_Exception If validation of $value is impossible
  */
 public function isValid($value, $context = array())
 {
     $this->_message = null;
     $user = $this->_userSource->getUser();
     if (!($user->isActive() && $user->canResetPassword() && $user->isAllowedOrganization($context['organization']))) {
         $this->_message = $this->translate->_('User not found or no e-mail address known or user cannot be reset.');
     }
     return (bool) (!$this->_message);
 }
Example #16
0
 /**
  * get translation with Zend_Translate_Adapter_Gettext
  *
  * @see Zend_Translate_Adapter_Gettext
  * @param string $file
  * @return array
  */
 protected function _getGettextFileData($file)
 {
     $data = array();
     if (file_exists($file)) {
         $gettextTranslator = new Zend_Translate(array('adapter' => 'Zend_Translate_Adapter_Gettext', 'content' => $file));
         $data = $gettextTranslator->getMessages();
     }
     return $data;
 }
Example #17
0
 /**	@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);
 }
Example #18
0
 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());
 }
Example #19
0
 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();
     }
 }
Example #20
0
 /**
  * Initialize translation-handling
  *
  * @return void
  */
 protected function _initTranslation()
 {
     $translate = new Zend_Translate('xliff', APPLICATION_PATH . DIRECTORY_SEPARATOR . 'locale', null, array('scan' => Zend_Translate::LOCALE_DIRECTORY));
     // Eine Log Instanz erstellen
     $writer = new Zend_Log_Writer_Stream(realpath(APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'log') . DIRECTORY_SEPARATOR . date('Ymd') . '-TranslateError.log');
     $log = new Zend_Log($writer);
     //
     // Diese der Übersetzungs-Instanz hinzufügen
     $translate->setOptions(array('log' => $log, 'logUntranslated' => true));
     Zend_Registry::set('Zend_Translate', $translate);
 }
Example #21
0
 /**
  * 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);
 }
Example #22
0
 /**
  * Sets a translation Adapter for translation
  *
  * @param  Zend_Translate|Zend_Translate_Adapter $translate
  * @return Zend_View_Helper_HeadTitle
  */
 public function setTranslator($translate)
 {
     if ($translate instanceof Zend_Translate_Adapter) {
         $this->_translator = $translate;
     } elseif ($translate instanceof Zend_Translate) {
         $this->_translator = $translate->getAdapter();
     } else {
         require_once 'Zend/View/Exception.php';
         throw new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
     }
     return $this;
 }
Example #23
0
 /**
  * Vytvari "or Cancel" odkaz za tlacitkem
  *
  * @return string
  */
 public function buildCancelLink()
 {
     $cancel = $this->getOption('cancel');
     if (!is_null($cancel)) {
         $request = Zend_Controller_Front::getInstance()->getRequest();
         $projekt = $request->getParam('projekt');
         if (!is_null($projekt)) {
             $projekt = '/' . $projekt;
         }
         return ' ' . $this->_translator->translate('or') . ' <a href="' . $projekt . '/' . $cancel . '" class="cancel">' . $this->_translator->translate('Cancel') . '</a>';
     }
 }
Example #24
0
 public static function getValues(Zend_Translate $lang)
 {
     $vars = Unsee_Hash::$ttlTypes;
     $values = array();
     foreach ($vars as $item) {
         $elLangString = 'settings_delete_ttl_' . $item;
         if ($lang->isTranslated($elLangString)) {
             $values[$item] = $lang->translate($elLangString);
         }
     }
     return $values;
 }
Example #25
0
 /**
  * (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;
 }
Example #26
0
 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);
 }
Example #27
0
 /**
  * Sets a translation Adapter for translation
  *
  * @param  Zend_Translate|Zend_Translate_Adapter $translate
  * @return Zend_View_Helper_HeadTitle
  */
 public function setTranslator($translate)
 {
     if ($translate instanceof Zend_Translate_Adapter) {
         $this->_translator = $translate;
     } elseif ($translate instanceof Zend_Translate) {
         $this->_translator = $translate->getAdapter();
     } else {
         $e = new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
         $e->setView($this->view);
         throw $e;
     }
     return $this;
 }
Example #28
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $locale = new Zend_Locale();
     Zend_Registry::set('Zend_Locale', $locale);
     // default language when requested language is not available
     $defaultlanguage = 'vi';
     // somewhere in your application
     $adapter = new Zend_Translate(array('adapter' => 'ini', 'content' => APPLICATION_PATH . '/languages', 'scan' => Zend_Translate::LOCALE_DIRECTORY, 'locale' => $locale->getLanguage()));
     //if (! $adapter->isAvailable($locale->getLanguage())) {
     // not available languages are rerouted to another language
     $adapter->setLocale($defaultlanguage);
     Zend_Registry::set('Zend_Translate', $adapter);
     //}
 }
 public function getJsTranslation()
 {
     if (!$this->_jstranslation) {
         try {
             $locale = Mage::app()->getLocale()->getLocaleCode();
             $translator = new Zend_Translate(array('adapter' => 'csv', 'content' => Mage::getBaseDir('locale') . '/' . $locale . '/' . 'Mirasvit_Helpdesk.csv', 'locale' => substr($locale, 0, 2), 'delimiter' => ','));
             $this->_jstranslation = json_encode($translator->getMessages());
         } catch (Exception $e) {
             // If we had unexpected exception (non-standard locale, for example), return empty
             return array();
         }
     }
     return $this->_jstranslation;
 }
Example #30
0
 /**
  * Set translator
  *
  * @param  Zend_Translate|Zend_Translate_Adapter|null $translator
  * @return Zend_View_Helper_FormElement
  */
 public function setTranslator($translator = null)
 {
     if (null === $translator) {
         $this->_translator = null;
     } elseif ($translator instanceof Zend_Translate_Adapter) {
         $this->_translator = $translator;
     } elseif ($translator instanceof Zend_Translate) {
         $this->_translator = $translator->getAdapter();
     } else {
         $e = new Zend_View_Exception('Invalid translator specified');
         $e->setView($this->view);
         throw $e;
     }
     return $this;
 }