當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Form::setTranslator方法代碼示例

本文整理匯總了PHP中Zend_Form::setTranslator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Form::setTranslator方法的具體用法?PHP Zend_Form::setTranslator怎麽用?PHP Zend_Form::setTranslator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Form的用法示例。


在下文中一共展示了Zend_Form::setTranslator方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testElementTranslatorNotOveriddenbyFormTranslatorDuringRendering

 /**
  * @group ZF-12375
  */
 public function testElementTranslatorNotOveriddenbyFormTranslatorDuringRendering()
 {
     // Set translator for form
     $this->form->setTranslator(new Zend_Translate('array', array('labelText' => 'Foo')));
     // Add element with his own translator
     $this->form->addElement('text', 'foo', array('label' => 'labelText', 'translator' => new Zend_Translate('array', array('labelText' => 'Bar')), 'decorators' => array('Label')));
     $this->form->setDecorators(array('FormElements'));
     // Test
     $this->assertSame(PHP_EOL . '<label for="foo" class="optional">Bar</label>' . PHP_EOL, $this->form->render(new Zend_View()));
 }
開發者ID:baofeng-beijing,項目名稱:zf1.11.x,代碼行數:13,代碼來源:FormTest.php

示例2: testLocalTranslatorPreferredOverDefaultGlobalTranslator

 public function testLocalTranslatorPreferredOverDefaultGlobalTranslator()
 {
     $this->assertNull($this->form->getTranslator());
     $translatorDefault = new Zend_Translate('array', array('foo' => 'bar'));
     Zend_Form::setDefaultTranslator($translatorDefault);
     $received = $this->form->getTranslator();
     $this->assertSame($translatorDefault->getAdapter(), $received);
     $translator = new Zend_Translate('array', array('foo' => 'bar'));
     $this->form->setTranslator($translator);
     $received = $this->form->getTranslator();
     $this->assertNotSame($translatorDefault->getAdapter(), $received);
     $this->assertSame($translator->getAdapter(), $received);
 }
開發者ID:vicfryzel,項目名稱:zf,代碼行數:13,代碼來源:FormTest.php

示例3: initTranslation

 protected function initTranslation(\Zend_Form $form, $id, $locale = null)
 {
     if ($locale === null) {
         $locale = \Zend_Locale::findLocale();
     }
     $trans = $this->translateForm($id, $locale);
     if ($locale != null && $locale != "") {
         if (null === $form->getTranslator()) {
             $form->setTranslator($trans);
         } else {
             $form->getTranslator()->addTranslation($trans);
         }
     }
 }
開發者ID:mkliche,項目名稱:Zendformbuilder,代碼行數:14,代碼來源:Frontend.php

示例4: translateAction

 public function translateAction()
 {
     $this->view->page_title .= $this->view->translate('Help us to translate nolotiro.org to your language');
     $request = $this->getRequest();
     $newlangs = array('ca' => 'Català', 'gl' => 'Galego', 'eu' => 'Euskara', 'nl' => 'Nederlands', 'de' => 'Deutsch', 'fr' => 'Français', 'pt' => 'Português', 'it' => 'Italiano');
     $lform = new Zend_Form();
     $lform->setMethod('get');
     $lform->addElement('select', 'lang', array('multiOptions' => $newlangs));
     $elem_newlang = $lform->getElement('lang');
     $elem_newlang->removeDecorator('label')->removeDecorator('HtmlTag')->setAttrib('onchange', 'this.form.submit()');
     $lform->populate($request->getParams());
     $newlang = $elem_newlang->getValue();
     $this->view->langsform = $lform;
     if ($newlang != null) {
         if (isset($newlangs[$newlang])) {
             $this->view->newlangtext = $newlangs[$newlang];
         } else {
             $newlang == null;
         }
     }
     if ($newlang == null) {
         $elem_newlang->clearMultiOptions();
         $elem_newlang->addMultiOption("", "-- " . $this->view->translate("Choose language") . " --");
         $elem_newlang->addMultiOptions($newlangs);
     } else {
         $options = array('scan' => Zend_Translate::LOCALE_FILENAME);
         $translate = new Zend_Translate('csv', NOLOTIRO_PATH . '/application/languages/', 'en', $options);
         $adapter = $translate->getAdapter();
         $es = $adapter->getMessages('es');
         if (strcmp($this->lang, $newlang) != 0) {
             $userlang = $adapter->getMessages($this->lang);
             $adapter->setLocale($this->lang);
         } else {
             $adapter->setLocale("en");
         }
         $en = $adapter->getMessages('en');
         $lang = $adapter->getMessages($newlang);
         $tform = new Zend_Form();
         $tform->setMethod('post');
         $tform->setAttrib('class', 'texts');
         $tform->addElement('captcha', 'safe_captcha', array('label' => 'Please, insert the 4 characters shown:', 'required' => true, 'captcha' => array(' captcha' => 'Image', 'wordLen' => 4, 'height' => 50, 'width' => 160, 'gcfreq' => 50, 'timeout' => 300, 'font' => NOLOTIRO_PATH . '/www/images/antigonimed.ttf', 'imgdir' => NOLOTIRO_PATH . '/www/images/captcha')));
         $tform->setTranslator($adapter);
         $index = 0;
         foreach ($es as $key => $text) {
             if (strpos($key, "safe_") === 0) {
                 continue;
             }
             if (isset($userlang[$key])) {
                 $text = $userlang[$key];
             } elseif (isset($en[$key])) {
                 $text = $en[$key];
             } else {
                 $text = $key;
             }
             $maxlen = strlen($text) * 3;
             $text = preg_replace("/(\\<[^\\>]*\\>)/", " ", $text);
             $text = preg_replace("/(\\'?%[a-zA-Z\\-]*%?\\'?)/", "...", $text);
             if (isset($lang[$key])) {
                 $val = $lang[$key];
                 $maxlen = strlen($val) * 3;
                 $val = preg_replace("/(\\<[^\\>]*\\>)/", " ", $val);
                 $val = preg_replace("/(\\'?%[a-zA-Z\\-]*%?\\'?)/", "...", $val);
             } else {
                 $val = '';
             }
             if ($maxlen < 20) {
                 $maxlen = 20;
             }
             if ($maxlen < 140) {
                 $type = "text";
                 $rows = 1;
             } else {
                 $type = "textarea";
                 $rows = round($maxlen / 50);
             }
             $tform->addElement($type, "text{$index}", array('validators' => array(array('StringLength', false, array(1, $maxlen))), 'required' => false, 'label' => $text, 'value' => $val, 'cols' => 40, 'rows' => $rows));
             $input = $tform->getElement("text{$index}");
             if ($val == '') {
                 $input->getDecorator('Label')->setOption('class', 'empty');
             }
             $valid = $input->getValidator("StringLength")->setEncoding('UTF-8');
             $index++;
         }
         // add the submit button
         $tform->addElement('submit', 'submit_texts', array('label' => 'Send texts', 'class' => 'magenta awesome'));
         $this->view->textsform = $tform;
         $this->view->newlang = $newlang;
         $tform->populate($request->getParams());
         if ($tform->getElement("submit_texts")->getValue() != null) {
             $data = $tform->getValues();
             if ($tform->isValid($data)) {
                 $newdata = false;
                 $index = 0;
                 foreach ($es as $key => $text) {
                     if (strpos($key, "safe_") === 0 || strpos($key, "lang") === 0) {
                         continue;
                     }
                     $mod = false;
                     $val = $data["text{$index}"];
                     $comp = $lang[$key];
//.........這裏部分代碼省略.........
開發者ID:Arteaga2k,項目名稱:nolotiro,代碼行數:101,代碼來源:PageController.php

示例5: getForms

 /**
  * Возвращает массив объектов Zend_Form мини-форм по типам 
  *
  * @return array
  */
 public function getForms()
 {
     $forms = array();
     foreach ($this->configs as $fieldtype => $template) {
         $form = new Zend_Form($template);
         $form->setElementsBelongTo('fields[]');
         $form->addDisplayGroup(array_keys($template['elements']), 'main', array('legend' => $template['label'], 'class' => 'ui-widget-content'));
         $form->removeDecorator('Form');
         $form->removeDecorator('DtDdWrapper');
         $form->setTranslator($this->translate);
         $forms[$fieldtype] = $form;
     }
     return $forms;
 }
開發者ID:ei-grad,項目名稱:phorm,代碼行數:19,代碼來源:FormsElements.php


注:本文中的Zend_Form::setTranslator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。