Zend Framework 2: how to inject configured Zend\Translator\Adapter\Gettext into Zend\View\Helper\Translator

StackOverflow https://stackoverflow.com/questions/9497301

  •  14-11-2019
  •  | 
  •  

문제

I have a problem with that component. My configuration in Application/config/module.config.php in di->instance section:

'alias' => array (
    'translateAdapter' => 'Zend\Translator\Adapter\Gettext',
    'viewHelper' => 'Zend\View\Helper\Translator'
),

'translateAdapter' => array (
    'parameters' => array (
        'locale' => 'de',
        'content' => '/home/alex/web/www/sob.lan/www/data/langs',
        'scan' => 'filename',
        'disableNotices' => true
    )
),

'viewHelper' => array(
    'parameters' => array(
        'translator' => 'translateAdapter'
    )
),

After, calling $this->translator()->translate() in view helper function I receive unconfigured gettext adapter.

What is the problem?

도움이 되었습니까?

해결책

The configuration parameters passed to the adapter are called $options in the constructor.

So you should get the desired result as follows:

'translateAdapter' => array (
    'parameters' => array (
        'options' => array(
            'locale' => 'de',
            'content' => '/home/alex/web/www/sob.lan/www/data/langs',
            'scan' => 'filename',
            'disableNotices' => true
        )
    )
),
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top