【发布时间】:2013-09-05 17:22:50
【问题描述】:
我正在使用 ZF2,并且正在使用翻译器。 在我的应用程序的配置中,我已将翻译器添加到 service_manager 工厂,因此 ZF2 助手将使用它。
这是我的翻译器配置的样子:
'translator' => array(
'locale' => 'nl_NL',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
在我的应用程序的 module.php 文件中,我的 onBootstrap 方法中有以下代码:
/**
* Magic to determine the right locale to be used.
*
* Check cookie
* Check GET parameter
* Check HOST (application can be used from several domain names)
*/
$translator = $serviceManager->get('translator');
// We have to change the current locale if $locale is not null.
if (!is_null($locale)) {
$translator->setLocale($locale);
// The translate helper of the view has some problems with what we're doing.
// So we'll manually add the translator with the correct locale to the view helper.
$serviceManager->get('viewhelpermanager')->get('translate')->setTranslator($translator);
}
如您所见,由于 onBootstrap 方法中的语言环境修改,我已经遇到了一些问题。
现在有两件事可以帮助我: - 帮助我找到一种方法将正确的翻译器重新注入到表单助手中; - 帮助我找到 ZF2 喜欢或应该这样做的方法(我的搜索没有找到解决方案)。
希望大家能帮帮我!
【问题讨论】:
标签: php zend-framework2 zend-form zend-form-element zend-translate