0

我正在开发 ZF2 骨架应用程序并添加了“专辑”模块。我的表单标签未翻译。需要做什么才能使表单标签成为多语言?

我的代码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();

已编辑


var_dump()$translator( )的$translator = $this->formLabel()->getTranslator();输出如下:


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
}

如您所见,语言环境是“es_ES”。我的es_ES.po包含标签(艺术家和标题)的翻译,并在列表页面标题中正确显示它们。

提前感谢您的帮助。

4

0 回答 0