Search code examples
zend-translatezend-framework2

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


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?


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