本文整理汇总了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()));
}
示例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);
}
示例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);
}
}
}
示例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];
//.........这里部分代码省略.........
示例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;
}