How set localization for Zend_Dojo_Form elements?
Lets say I have a simple form:
class Form_Simple extends Zend_Dojo_Form
{
public function init() {
$this->addElements(array(
new Zend_Dojo_Form_Element_ValidationTextBox('name', a开发者_运维问答rray(
'required' => true,
'label' => 'Name:'
))
}
}
"name" element is required so error message will be "this field is required". How change this message?
You can localize the form labels just like in any other part of your application.
In your bootstrap file you have to setup the Zend_Locale and Zend_Translate object. It will be avialable in your entire application.
E.g in your boostrap:
//init locale
$translate = new Zend_Translate('gettext',
APPLICATION_PATH.'/languages',null,
array('scan' => Zend_Translate::LOCALE_FILENAME));
$locale = new Zend_Locale();
$locale->setLocale(Zend_Locale::BROWSER);
$requestedLanguage = key($locale->getBrowser());
if(in_array($requestedLanguage, $translate->getList())){
$language = $requestedLanguage;
}else{
$language = 'en';
}
$translate->setLocale($language);
$view->translate = $translate;
Since the setup is really detailed and maybe complex I recommend you to watch this tutorial http://www.youtube.com/watch?v=FwPgqla-cRk
精彩评论