Error Translator with latest update

85 Views Asked by At

I have update zf2 on the latest version and i receive this error: http://jsfiddle.net/8Ft6d/

Some mandatory parameter was added for translation?

This is my translator config:

'translator' => array(
    'locale' => 'it_IT',
    'translation_file_patterns' => array(
        array(
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ),
    ),
),
'service_manager' => array(
    'aliases' => array(
        'translator' => 'MvcTranslator',
    ),
),

and this is what i call inside the Module.php::onBootstrap()

$translator = $serviceManager->get('translator’);

Thanks

2

There are 2 best solutions below

0
Ocramius On

What is happening here is that most probably, the DiAbstractServiceFactory is kicking in before an abstract factory that is responsible of fetching the MvcTransator instance.

You will likely have to switch the order in which abstract factories are being used, or remove your 'di' config from your modules or autoload config, since its presence will automatically cause addition of the DiAbstractServiceFactory to the ServiceManager.

0
Benjamin Nolan On

I've had the same issue myself this morning after upgrading from 2.2.6 to 2.3.0.

There's a bug in ZF2.3.0 which causes the Di module to fail when trying to create an instance of the MvcTranslator (see: https://github.com/zendframework/zf2/pull/5959, where @Ocramius and noopable came up with the solution).

Until the fix is rolled out to the framework, you'll need to change the following code in Zend\ServiceManager\Di\DiAbstractServiceFactory from:

public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
    return $this->instanceManager->hasSharedInstance($requestedName)
        || $this->instanceManager->hasAlias($requestedName)
        || $this->instanceManager->hasConfig($requestedName)
        || $this->instanceManager->hasTypePreferences($requestedName)
        || $this->definitions->hasClass($requestedName);
}

to:

public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
    if ($this->instanceManager->hasSharedInstance($requestedName)
        || $this->instanceManager->hasAlias($requestedName)
        || $this->instanceManager->hasConfig($requestedName)
        || $this->instanceManager->hasTypePreferences($requestedName)
    ) {
        return true;
    }

    if (! $this->definitions->hasClass($requestedName) || interface_exists($requestedName)) {
        return false;
    }

    return true;
}