我正在尝试注册一个自定义数据库翻译加载器。
为此,我受到了启发: Feeding Zend Translator
我在(module.config.php)中有以下工厂代码:
'service_manager' => array(
'factories' => array(
'translator' => function($sm){
$translator = new \V1\Service\DatabaseTranslationService();
return $translator->createService($sm);
},
),
),
DatabaseTranslationService 看起来像这样:
$config = $serviceLocator->get('Config');
$trConfig = isset($config['translator']) ? $config['translator'] : array();
$translator = new \Zend\I18n\Translator\Translator();
$translator->getPluginManager()->setInvokableClass('database', '\Foo\I18n\Translator\Loader\DatabaseTranslator', true);
$translator->addTranslationFile('database', 'en_EN');
return $translator;
但似乎没有使用“setInvokableClass”:我收到此错误:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for database
有人知道如何正确注册翻译吗