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
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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
        )
    )
),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top