我能够让它工作!
首先,添加一个'router_class' => 'Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack',
your module.config.php
像这样:
return array (
'router' => array (
'router_class' => 'Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack',
'routes' => array(),
)
);
其次,您必须提供翻译器(最好在 module.php 中)以及翻译文件:
class Module
{
public function onBootstrap(MvcEvent $e)
{
// Load translator
$translator = $e->getApplication()->getServiceManager()->get('translator');
$translator->setLocale('de_DE');
// setup the translation file. you can use .mo files or whatever, check the translator api
$translator->addTranslationFile('PhpArray', __DIR__.'/language/routes/de_DE.php', 'default', 'de_DE');
$app = $e->getTarget();
// Route translator
$app->getEventManager()->attach('route', array($this, 'onPreRoute'), 100);
}
public function onPreRoute($e){
$app = $e->getTarget();
$serviceManager = $app->getServiceManager();
$serviceManager->get('router')->setTranslator($serviceManager->get('translator'));
}
}
现在,您应该能够在路线定义中使用翻译,如下所示:
return array (
'router' => array (
'routes' => array(
'login' => array (
'type' => 'Zend\Mvc\Router\Http\Segment',
'may_terminate' => true,
'options' => array (
'route' => '/{login}',
'defaults' => Array(
'controller' => '...',
)
),
),
)
);
创建翻译(在此示例中,phpArray 位于 module/language/routes/de_DE.php 中):
<?php
return array(
'login' => 'anmelden',
);
如果我没忘记什么的话,你就可以走了。我的情况是这样的,所以如果上面的说明不可行,请随时发表评论,我会解决问题。