ZF2表单标签未翻译

时间:2013-01-30 15:31:17

标签: zend-framework2 multilingual zend-form2

我正在研究ZF2 skeleton-App并添加了“Album”模块。我的表单标签未翻译。要使表单标签多语言需要做些什么?

我的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',
            ),
        ));
    }
}

我的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


$ translator var_dump()的{​​{1}}给出以下输出:


$translator = $this->formLabel()->getTranslator();

正如您所看到的那样,语言环境是“es_ES”。我的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 } 包含标签的翻译(艺术家和标题),并在列表页面标题中正确显示。

提前感谢您的帮助。

0 个答案:

没有答案