Zend 2翻译全球

时间:2015-06-07 12:27:27

标签: php zend-framework2

以下代码在控制器中运行良好,如何全局?

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',
    ),
    ),
),    

2 个答案:

答案 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',
    ),
    ),
),