In order to initialize I18n in forms, you will need either a
Zend_Translate object or a
Zend_Translate_Adapter object, as detailed in the
Zend_Translate documentation. Once you have a
translation object, you have several options:
-
Easiest: add it to the registry. All I18n aware components of Zend Framework will autodiscover a translate object that is in the registry under the 'Zend_Translate' key and use it to perform translation and/or localization:
<?php
// use the 'Zend_Translate' key; $translate is a Zend_Translate object:
Zend_Registry::set('Zend_Translate', $translate);This will be picked up by
Zend_Form,Zend_Validate, andZend_View_Helper_Translate. -
If all you are worried about is translating validation error messages, you can register the translation object with
Zend_Validate_Abstract:<?php
// Tell all validation classes to use a specific translate adapter:
Zend_Validate_Abstract::setDefaultTranslator($translate); -
Alternatively, you can attach to the
Zend_Formobject as a global translator. This has the side effect of also translating validation error messages:<?php
// Tell all form classes to use a specific translate adapter, as well
// as use this adapter to translate validation error messages:
Zend_Form::setDefaultTranslator($translate); -
Finally, you can attach a translator to a specific form instance or to specific elements using their
setTranslator()methods:<?php
// Tell *this* form instance to use a specific translate adapter; it
// will also be used to translate validation error messages for all
// elements:
$form->setTranslator($translate);
// Tell *this* element to use a specific translate adapter; it will
// also be used to translate validation error messages for this
// particular element:
$element->setTranslator($translate);




