title: How to translate form labels in Zend Framework 2?
body: <p>I'm not getting <a href="http://framework.zend.com/manual/2.1/en/modules/zend.form.view.helpers.html#formlabel" rel="noreferrer">it</a>!.. Can please someone explain, how to translate form labels? A simple example would be great.</p>
  
  <p>Thank you in advance!</p>
  
  <hr>
  
  <p><strong>class Search\Form\CourseSearchForm</strong></p>
  
  <pre><code>...
  
  class CourseSearchForm extends Form {
  
      ...
  
      public function __construct(array $cities) {
          parent::__construct('courseSearch');
          ...
          $this-&gt;add(array(
              'name' =&gt; 'city',
              'type'  =&gt; 'Zend\Form\Element\Select',
              'options' =&gt; array(
                  'label' =&gt; 'Stadt',
                  'value_options' =&gt; $this-&gt;cities,
                  'id'  =&gt; 'searchFormCity',
              ),
          ));
          ...
      }
  }
  </code></pre>
  
  <p><strong>view script /module/Search/view/search/search/search-form.phtml</strong></p>
  
  <pre><code>&lt;?php echo $this-&gt;form()-&gt;openTag($form); ?&gt;
  &lt;dl&gt;
      ...
      &lt;dt&gt;&lt;label&gt;&lt;?php echo $form-&gt;get('city')-&gt;getLabel(); ?&gt;&lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;&lt;?php echo $this-&gt;formRow($form-&gt;get('city'), null, false, false); ?&gt;&lt;/dd&gt;
      ...
  &lt;/dl&gt;
  &lt;?php echo $this-&gt;form()-&gt;closeTag(); ?&gt;
  &lt;!-- The formRow(...) is my MyNamespace\Form\View\Helper (extends Zend\Form\View\Helper\FormRow); the fourth argument of it disables the label. --&gt;
  </code></pre>
  
  <hr>
  
  <p>The <strong><code>module/Application/config/module.config.php</code></strong> is configured:</p>
  
  <pre><code>return array(
      'router' =&gt; ...
      'service_manager' =&gt; array(
          'factories' =&gt; array(
              'translator' =&gt; 'Zend\I18n\Translator\TranslatorServiceFactory',
          ),
      ),
      'translator' =&gt; array(
          'locale' =&gt; 'de_DE',
          'translation_file_patterns' =&gt; array(
              array(
                  'type'     =&gt; 'gettext',
                  'base_dir' =&gt; __DIR__ . '/../language',
                  'pattern'  =&gt; '%s.mo',
              ),
          ),
      ),
      'controllers' =&gt; ...
      'view_manager' =&gt; ...
  );
  </code></pre>
  
  <p>I also edited my view and use the <code>FormLabel</code> view helper:</p>
  
  <pre><code>&lt;dt&gt;&lt;label&gt;&lt;?php echo $this-&gt;formLabel($form-&gt;get('city')); ?&gt;&lt;/label&gt;&lt;/dt&gt;
  </code></pre>
  
  <p>Furthermore I debugged the <code>FormLabel</code> at the place, where the tranlator is used (lines <a href="https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormLabel.php#L116" rel="noreferrer">116-120</a>) -- seems to be OK.</p>
  
  <p>But it's still not working.</p>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>The (test) items for labels, I added to the <code>de_DE.po</code> file manually, are tranlated. The ZF2 side problem was actually, that I was using <code>$form-&gt;get('city')-&gt;getLabel()</code> instead of <code>$this-&gt;formlabel($form-&gt;get('city'))</code> in th view script.</p>
  
  <p>The problem is now, that the labels are not added to the <code>de_DE.po</code> file. But it's not a ZF2 issue anymore, so I've accept Ruben's answer and open a new Poedit question.</p>