|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Form errors translate// in controller
/** * Возвращает Zend_Translate * * @return Zend_Translate */ protected function getTranslator() { Zend_Loader::loadClass('Zend_Translate'); $translate=new Zend_Translate('array', 'path/to/php', Zend_Registry::get('config')->locale); return $translate; } $translate = $this->getTranslator()); $form->setTranslator($translate); echo $translate->_('isEmpty'); // print 'Пустое значение'!!!!!!!!!!!!!!!!!!!!!!!!!!! // translate array <?php return $data = array ( 'isEmpty' => 'Пустое значение', 'Value is empty, but a non-empty value is required' => 'Пустое значение', ); ?> I'm trying to translate form errors, but translate did'n work. I wrote in file Zend\Form\Decorator\Errors.php: public function render($content) { $element = $this-getElement(); $view = $element-getView(); if (null === $view) { return $content; } $errors = $element-getMessages(); if (empty($errors)) { return $content; } $separator = $this-getSeparator(); $placement = $this-getPlacement(); // begin my code foreach ($errors as $key =$value) { if (null !== ($translator = $element-getTranslator())) { $errors[$key] = $translator-translate($value); } } // end my code $errors = $view-formErrors($errors, $this-getOptions()); switch ($placement) { case self::APPEND: return $content . $separator . $errors; case self::PREPEND: return $errors . $separator . $content; } } and errors was translateted. Is it bug? The translator sets on form did'n work in Validator classes. Why ? |
|
|
Re: Forn errors translateHy Eugena,
three things to mention... First: Your code does not work. You should always work with the object operator "->" instead of "-". Second: Text should be translated where it's printed to prevent that it's twice translated Third: As you have a problem with Form it's better to ask in the MVC or General List because this looks for me as you have problems with Zend_Form and not with Zend_Translate. :-) I think Form and Validate generate different responses and are therefor not translated. Greetings Thomas Weidner, I18N Team Leader, Zend Framework http://www.thomasweidner.com ----- Original Message ----- From: "Eugena" <eugena@...> To: <fw-i18n@...> Sent: Saturday, April 26, 2008 5:53 AM Subject: [fw-i18n] Forn errors translate // in conroller /** * Возвращает Zend_Translate * * @return Zend_Translate */ protected function getTranslator() { Zend_Loader::loadClass('Zend_Translate'); $translate=new Zend_Translate('array', 'path/to/php', Zend_Registry::get('config')->locale); return $translate; } $translate = $this->getTranslator()); $form->setTranslator($translate); echo $translate->_('isEmpty'); // print 'Пустое значение'!!!!!!!!!!!!!!!!!!!!!!!!!!! // translate array <?php return $data = array ( 'isEmpty' => 'Пустое значение', 'Value is empty, but a non-empty value is required' => 'Пустое значение', ); ?> I'm trying to translate form errors, but translate did'n work. I wrote in file Zend\Form\Decorator\Errors.php: public function render($content) { $element = $this-getElement(); $view = $element-getView(); if (null === $view) { return $content; } $errors = $element-getMessages(); if (empty($errors)) { return $content; } $separator = $this-getSeparator(); $placement = $this-getPlacement(); // begin my code foreach ($errors as $key =$value) { if (null !== ($translator = $element-getTranslator())) { $errors[$key] = $translator-translate($value); } } // end my code $errors = $view-formErrors($errors, $this-getOptions()); switch ($placement) { case self::APPEND: return $content . $separator . $errors; case self::PREPEND: return $errors . $separator . $content; } } and errors was translateted. Is it bug? The translator sets on form did'n work in Validator classes. Why ? -- View this message in context: http://www.nabble.com/Forn-errors-translate-tp16909178p16909178.html Sent from the Zend I18N/Locale mailing list archive at Nabble.com. |
|
|
Re: Form errors translateHello Thomas,
> > three things to mention... > > First: Your code does not work. You should always work with the object > operator "->" instead of "-". ????? it's the representation of this site!!!!!!!!!!!!! Code is working! > Second: Text should be translated where it's printed to prevent that it's > twice translated > Third: As you have a problem with Form it's better to ask in the MVC or > General List because this looks for me as you have problems with Zend_Form > and not with Zend_Translate. :-) > > I think Form and Validate generate different responses and are therefor > not > translated. > > Greetings > Thomas Weidner, I18N Team Leader, Zend Framework > http://www.thomasweidner.com thanks, but you hav't answered for my question. Yes! Form and Validate generate different responses. My problem is unsoluble? May I to write code, that make Validators to "see" Form translator as it wrote in documentation? Sorry, my english is very bad... Best regards, Eugena |
|
|
Re: Form errors translateEugena,
>> three things to mention... >> >> First: Your code does not work. You should always work with the object >> operator "->" instead of "-". > ????? it's the representation of this site!!!!!!!!!!!!! > Code is working! When I execute the code you sent public function render($content) { $element = $this-getElement(); $view = $element-getView(); if (null === $view) { return $content; } it does not work because of a broken object operator... $this->getElement() instead of $this-getElement... >> Second: Text should be translated where it's printed to prevent that it's >> twice translated >> Third: As you have a problem with Form it's better to ask in the MVC or >> General List because this looks for me as you have problems with >> Zend_Form >> and not with Zend_Translate. :-) >> >> I think Form and Validate generate different responses and are therefor >> not >> translated. >> > thanks, but you hav't answered for my question. > Yes! Form and Validate generate different responses. Of course I had... When you have two different strings they are also two different translations. So when Zend_Form gives a different response (string) it will cause other translations than Zend_Validate. Zend_Translate will only translate messageids which is knows... all other inputs will be returned as is, without modification. > My problem is unsoluble? > May I to write code, that make Validators to "see" Form translator as it > wrote in documentation? You may write what you want :-) Fact is, that Validator and Form are independent objects. And a validator does not translate anything. But as I already said... If you have problems on Zend_Form ask on the mvc mailing list. And if you have problems on Zend_Validate you should ask on the core mailing list. Both components are not part of the I18N core so my help is very restricted. :-) Greetings Thomas Weidner, I18N Team Leader, Zend Framework http://www.thomasweidner.com |
| Free Forum Powered by Nabble | Forum Help |