本文整理汇总了PHP中Zend_Translate类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate类的具体用法?PHP Zend_Translate怎么用?PHP Zend_Translate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Translate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: _initSetTranslations
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';
}
}
示例3: getMessages
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;
}
示例4: _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;
}
示例5: 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) {
}
}
}
示例6: getValues
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;
}
示例7: fileToDbAction
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);
}
示例8: setMessage
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);
}
示例9: _
/**
* 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);
}
}
示例10: translate
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('"', '"', $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;
}
示例11: _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;
}
示例12: _initTranslation
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);
}
示例13: _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);
}
示例14: _getGettextFileData
/**
* 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;
}
示例15: 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);
}