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」です。Myes_ES.poにはラベル (アーティストとタイトル) の翻訳が含まれており、一覧ページの見出しに正しく表示されます。

助けてくれてありがとう。

4

0 に答える 0