以下代码在控制器中运行良好,如何全局?
XXXController.php
$lang = 'nl';
$loc = $this->getServiceLocator();
$translator = $this->get('translator');
$translator->addTranslationFile("phparray",'./module/admin/language/lang.array.'.$lang.'.php');
$loc->get('ViewHelperManager')->get('translate')->setTranslator($translator);
View.phtml
echo $this->translate('homepage');
the awnser:
module.config.php
'translator' => array(
'locale' => 'it_IT',
'translation_files' => array(
array(
'type' => 'phpArray',
'filename' => './module/admin/language/lang.array.nl.php',
),
),
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language/mydomain',
'pattern' => '%s.mo',
),
),
),
答案 0 :(得分:1)
在模块配置中设置翻译器,如Zend Skeleton Application
答案 1 :(得分:0)
the awnser!
'translator' => array(
'locale' => 'it_IT',
'translation_files' => array(
array(
'type' => 'phpArray',
'filename' => './module/admin/language/lang.array.nl.php',
),
),
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language/mydomain',
'pattern' => '%s.mo',
),
),
),