我有一段时间试图解决表单中的问题以翻译表单标签。我正在使用.po文件来翻译我的字符串,我已完全按照answer
完成解决方案我的翻译工作正常,如果我在下面的视图中直接测试标签'Naam',我会得到正确的翻译输出。
echo $this->translate('Naam'); // outputs 'Nom'
../模块/应用/ Module.php
$translator = $serviceManager->get('translator');
$translator ->setLocale($language->getLocale())
->setFallbackLocale('nl_NL');
AbstractValidator::setDefaultTranslator($translator);
../模块/应用/配置/ 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',
),
));
视图
<?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); ?>