I donβt get it ! .. May someone like to explain how to translate the forms? A simple example will be great.
Thank you in advance!
class Search \ Form \ CourseSearchForm
... class CourseSearchForm extends Form { ... public function __construct(array $cities) { parent::__construct('courseSearch'); ... $this->add(array( 'name' => 'city', 'type' => 'Zend\Form\Element\Select', 'options' => array( 'label' => 'Stadt', 'value_options' => $this->cities, 'id' => 'searchFormCity', ), )); ... } }
view script / module / Search / view / search / search / search-form.phtml
<?php echo $this->form()->openTag($form); ?> <dl> ... <dt><label><?php echo $form->get('city')->getLabel(); ?></label></dt> <dd><?php echo $this->formRow($form->get('city'), null, false, false); ?></dd> ... </dl> <?php echo $this->form()->closeTag(); ?>
Configurable module/Application/config/module.config.php :
return array( 'router' => ... 'service_manager' => array( 'factories' => array( 'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory', ), ), 'translator' => array( 'locale' => 'de_DE', 'translation_file_patterns' => array( array( 'type' => 'gettext', 'base_dir' => __DIR__ . '/../language', 'pattern' => '%s.mo', ), ), ), 'controllers' => ... 'view_manager' => ... );
I also edited my view and used the FormLabel view FormLabel :
<dt><label><?php echo $this->formLabel($form->get('city')); ?></label></dt>
In addition, I debugged FormLabel in the place where the transactor is used (lines 116-120 ) - everything seems to be in order.
But it still does not work.
EDIT
Elements (test) for labels, which I added to the de_DE.po file manually, are translated. The essence of the problem with ZF2 was that I used $form->get('city')->getLabel() instead of $this->formlabel($form->get('city')) from a script perspective.
The problem is that tags are not added to the de_DE.po file. But this is no longer ZF2's problem, so I accept Ruben's answer and open a new question about Poedit.