I am working on ZF2 skeleton-App and added the "Album" module. My forms labels are not translated. What needs to be done to get the form labels to be multi-lingual?
My code for form/AlbumForm.php
:
class AlbumForm extends Form
{
public function __construct($name = null)
{
parent::__construct('album');
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'artist',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Artist',
),
));
$this->add(array(
'name' => 'title',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Title',
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
My code for view/edit.phtml
:
$form = $this->form;
$form->setAttribute( 'action', $this->url( 'album', array(
'action' => 'edit',
'id' => $this->id
) ) );
$form->prepare();
echo $this->form()->openTag( $form );
echo $this->formHidden( $form->get( 'id' ) );
echo $this->formRow( $form->get( 'title' ) );
echo $this->formRow( $form->get( 'artist' ) );
echo $this->formSubmit( $form->get( 'submit' ) );
echo $this->form()->closeTag();
EDITED
The var_dump()
of $translator($translator = $this->formLabel()->getTranslator();
) gives the following output:
object(Zend\I18n\Translator\Translator)#159 (8) {
["messages":protected]=>
array(0) {
}
["files":protected]=>
array(0) {
}
["patterns":protected]=>
array(1) {
["default"]=>
array(1) {
[0]=>
array(3) {
["type"]=>
string(7) "gettext"
["baseDir"]=>
string(83) "C:\Users\something\Projects\ZF2\code_new\module\Application\config/../language"
["pattern"]=>
string(5) "%s.mo"
}
}
}
["remote":protected]=>
array(0) {
}
["locale":protected]=>
string(5) "es_ES"
["fallbackLocale":protected]=>
NULL
["cache":protected]=>
NULL
["pluginManager":protected]=>
NULL
}
As you can see the locale is "es_ES". My es_ES.po
contains translations for the labels (Artist and Title) and shows them correctly in listing page headings.
Thanks in advance for help.