本文整理汇总了PHP中Zend_Form::setDefaultTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::setDefaultTranslator方法的具体用法?PHP Zend_Form::setDefaultTranslator怎么用?PHP Zend_Form::setDefaultTranslator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form
的用法示例。
在下文中一共展示了Zend_Form::setDefaultTranslator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initFormErrorMessages
public function _initFormErrorMessages()
{
Zend_Form::setDefaultTranslator(
new Zend_Translate(
'array', APPLICATION_PATH. '/translations/forms.php', 'pl'
)
);
}
示例2: preDispatch
/**
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
switch ($request->getModuleName()) {
case 'default':
Zend_Form::setDefaultTranslator(Zend_Registry::get('Zend_Translate'));
break;
}
}
示例3: routeShutdown
/**
* Sets the application locale and translation based on the locale param, if
* one is not provided it defaults to english
*
* @param Zend_Controller_Request_Abstract $request
* @return Void
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$config = Zend_Registry::get('config');
$frontController = Zend_Controller_Front::getInstance();
$params = $request->getParams();
$registry = Zend_Registry::getInstance();
// Steps setting the locale.
// 1. Default language is set in config
// 2. TLD in host header
// 3. Locale params specified in request
$locale = $registry->get('Zend_Locale');
// Check host header TLD.
$tld = preg_replace('/^.*\\./', '', $request->getHeader('Host'));
// Provide a list of tld's and their corresponding default languages
$tldLocales = $frontController->getParam('tldLocales');
if (is_array($tldLocales) && array_key_exists($tld, $tldLocales)) {
// The TLD in the request matches one of our specified TLD -> Locales
$locale->setLocale(strtolower($tldLocales[$tld]));
} elseif (isset($params['locale'])) {
// There is a locale specified in the request params.
$locale->setLocale(strtolower($params['locale']));
}
// Now that our locale is set, let's check which language has been selected
// and try to load a translation file for it.
$language = $locale->getLanguage();
$translate = Garp_I18n::getTranslateByLocale($locale);
Zend_Registry::set('Zend_Translate', $translate);
Zend_Form::setDefaultTranslator($translate);
if (!$config->resources->router->locale->enabled) {
return;
}
$path = '/' . ltrim($request->getPathInfo(), '/\\');
// If the language is in the path, then we will want to set the baseUrl
// to the specified language.
$langIsInUrl = preg_match('/^\\/' . $language . '\\/?/', $path);
$uiDefaultLangIsInUrl = false;
$uiDefaultLanguage = false;
if (isset($config->resources->locale->uiDefault)) {
$uiDefaultLanguage = $config->resources->locale->uiDefault;
$uiDefaultLangIsInUrl = preg_match('/^\\/' . $uiDefaultLanguage . '\\/?/', $path);
}
if ($langIsInUrl || $uiDefaultLangIsInUrl) {
if ($uiDefaultLangIsInUrl) {
$frontController->setBaseUrl($frontController->getBaseUrl() . '/' . $uiDefaultLanguage);
} else {
$frontController->setBaseUrl($frontController->getBaseUrl() . '/' . $language);
}
} elseif (!empty($config->resources->router->locale->enabled) && $config->resources->router->locale->enabled) {
$redirectUrl = '/' . $language . $path;
if ($frontController->getRouter()->getCurrentRouteName() === 'admin' && !empty($config->resources->locale->adminDefault)) {
$adminDefaultLanguage = $config->resources->locale->adminDefault;
$redirectUrl = '/' . $adminDefaultLanguage . $path;
} elseif ($uiDefaultLanguage) {
$redirectUrl = '/' . $uiDefaultLanguage . $path;
}
$this->getResponse()->setRedirect($redirectUrl, 301);
}
}
示例4: _setupTranslation
protected function _setupTranslation()
{
if (self::getDefaultTranslator()) {
return;
}
$path = dirname(dirname(dirname(__FILE__))) . '/translate/forms.php';
$translate = new Zend_Translate('array', $path, 'en');
Zend_Form::setDefaultTranslator($translate);
}
示例5: 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);
}
示例6: init
public function init()
{
//initialization function
$this->locale = Zend_Registry::get('Zend_Locale');
$this->view->translate = Zend_Registry::get('Zend_Translate');
Zend_Form::setDefaultTranslator($this->view->translate);
$this->lobjform = new App_Form_Search();
//local object for Search Form
$this->lobjschemesetupmodel = new Reports_Model_DbTable_Mhssetup();
$this->gobjsessionsis = Zend_Registry::get('sis');
}
示例7: _initLocale
protected function _initLocale()
{
Zend_Loader::loadClass('Zend_Locale');
Zend_Locale::setDefault('fr');
$session = new Zend_Session_Namespace();
$session->locale = !empty($session->locale) ? $session->locale : DEFAULT_LOCALE;
$translator = new Zend_Translate(array('adapter' => 'array', 'content' => APPLICATION_PATH . '/languages/' . $session->locale . '.php', 'locale' => $session->locale));
Zend_Validate_Abstract::setDefaultTranslator($translator);
Zend_Form::setDefaultTranslator($translator);
Zend_Validate::setDefaultTranslator($translator);
Zend_Registry::set("Zend_Translate", $translator);
}
示例8: _initTranslator
protected function _initTranslator()
{
$session = Zend_Registry::get('session');
Zend_Locale::setDefault('en');
$locale = isset($session->locale) ? $session->locale : new Zend_Locale(Zend_Locale::ZFDEFAULT);
Zend_Registry::set('Zend_Locale', $locale);
$session->locale = $locale;
$translator = new Zend_Translate(array('adapter' => 'array', 'content' => INSTALL_PATH . DIRECTORY_SEPARATOR . 'system/languages/', 'scan' => Zend_Translate::LOCALE_FILENAME, 'locale' => $locale->getLanguage(), 'ignore' => array('.'), 'route' => array('fr' => 'en', 'it' => 'en', 'de' => 'en')));
Zend_Form::setDefaultTranslator($translator);
Zend_Registry::set('Zend_Translate', $translator);
Zend_Registry::set('session', $session);
}
示例9: 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);
}
示例10: _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);
}
示例11: 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');
}
}
}
示例12: _initTranslate
/**
* Referência:
* http://www.codeforest.net/multilanguage-support-in-zend-framework
*/
protected function _initTranslate()
{
$locale = new Zend_Locale();
if (!Zend_Locale::isLocale($locale, TRUE, FALSE)) {
if (!Zend_Locale::isLocale($locale, FALSE, FALSE)) {
throw new Zend_Locale_Exception("The locale '{$locale}' is no known locale");
}
$locale = new Zend_Locale($locale);
}
//$locale = "pt_BR";
$translatorArray = new Zend_Translate(array('adapter' => 'array', 'content' => APPLICATION_PATH . '/../resources/languages', 'locale' => $locale, 'scan' => Zend_Translate::LOCALE_DIRECTORY));
$translate = new Zend_Translate('gettext', APPLICATION_PATH . "/langs/", $locale, array('scan' => Zend_Translate::LOCALE_DIRECTORY));
$translate->addTranslation($translatorArray);
$registry = Zend_Registry::getInstance();
$registry->set('Zend_Translate', $translate);
Zend_Validate_Abstract::setDefaultTranslator($translate);
Zend_Form::setDefaultTranslator($translate);
}
示例13: _initLocale
/**
* This is where we set up the locale and set the translation adapters
* @deprecate this could be set in the site.ini using resoruces
* @return void
*/
protected function _initLocale()
{
//this is the locale
try {
$locale = new Zend_Locale(Zend_Locale::BROWSER);
} catch (Zend_Locale_Exception $e) {
$locale = new Zend_Locale('en_US');
}
Zend_Locale::setDefault($locale);
// here we define the translator
$translatePath = APPLICATION_PATH . '/languages/translate.xml';
$options = array('log' => Zend_Registry::get('logger'), 'disableNotices' => false, 'logMessage' => "Untranslated message within '%locale%': %message% : %word%");
$translate = new Zend_Translate('tmx', $translatePath, $locale, $options);
// hwere we add the translator to the registry
Zend_Registry::set('translate', $translate);
// here we set all forms attached to the translator
// this will translate everything on the form
Zend_Form::setDefaultTranslator($translate);
}
示例14: __construct
public function __construct($app)
{
parent::__construct($app);
date_default_timezone_set('America/Lima');
$this->bootstrap('multidb');
/* ejecuta un recurso */
$db = $this->getPluginResource('multidb')->getDb('db');
/* obtiene los datos del recurso */
Zend_Db_Table::setDefaultAdapter($db);
/* registra el adaptador */
Zend_Registry::set('db', $db);
/*registra la clase adaptadora*/
Zend_Form::setDefaultTranslator(new Zend_Translate('array', APPLICATION_PATH . '/configs/lang/es.php', 'es'));
$this->getResourceLoader()->addResourceType('entity', 'entitys/', 'Entity');
$this->getResourceLoader()->addResourceType('service', 'services/', 'Service');
$response = new Zend_Controller_Response_Http();
$response->setHeader('Content-Type', 'text/html; charset=utf-8')->setHeader('Accept-Encoding', 'gzip, deflate')->setHeader('Expires', 'max-age=' . 20, true)->setHeader('Cache-Control', 'private', 'must-revalidate')->setHeader('Pragma', 'no-cache', true);
$response->sendResponse();
}
示例15: routeShutdown
/**
* Sets the application locale and translation based on the lang param.
*
* If a lang param is not provided, it will default to english.
*
* @param Zend_Controller_Request_Abstract $request
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$registry = Zend_Registry::getInstance();
$locale = $registry->get('Zend_Locale');
$translate = $registry->get('Zend_Translate');
$params = $this->getRequest()->getParams();
$localeParam = isset($params['lang']) ? $param['lang'] : false;
if (false === $localeParam) {
$localeParam = $locale->getLanguage();
}
if (!$translate->isAvailable($localeParam)) {
$localeParam = 'en';
$this->getRequest()->setParam('lang', 'en');
}
$locale->setLocale($localeParam);
$translate->setLocale($locale);
Zend_Form::setDefaultTranslator($translate);
setcookie('lang', $locale->getLanguage(), null, '/');
}