Since a while I am trying to solve an issue in my forms to translate the form labels. I am using .po files to translate my strings and I have exactly done what the solution should be in this answer
My translator works fine, if I test the label 'Naam' for example directly in my view as below, I get the correct translation output returned.
echo $this->translate('Naam'); // outputs 'Nom'
../module/Application/Module.php
$translator = $serviceManager->get('translator');
$translator ->setLocale($language->getLocale())
->setFallbackLocale('nl_NL');
AbstractValidator::setDefaultTranslator($translator);
../module/Application/config/module.config.php
'service_manager' => array(
'aliases' => array(
'translator' => 'MvcTranslator',
),
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'nl_NL',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
ContactForm.php
$this->add(array(
'name' => 'name',
'type' => 'Zend\Form\Element\Text',
'options' => array(
'label' => 'Naam',
),
'attributes' => array(
'type' => 'name',
'autofocus' => '',
'autocomplete' => 'off',
'class' => 'form-control',
),
));
The view
<?php echo $this->form()->openTag($form); ?>
<?php echo $this->formlabel($form->get('name')); ?> // should be 'Nom' but keeps returning 'Naam'
<?php echo $this->form()->closeTag($form); ?>