我正在开发一个多语言应用程序。在引导程序中有路由设置:
protected function _initRoutes() {
$this->bootstrap('frontController');
$router = $this->frontController->getRouter();
// PAGES ROUTE
$page = new Zend_Controller_Router_Route(
':language/:ident',
array(
'module' => 'core',
'controller' => 'pagine',
'action' => 'view'
),
array(
'ident' => '[a-zA-Z-_0-9]{3,}',
'language' => '[a-z]{2}'
)
);
$registrazione = new Zend_Controller_Router_Route(
':language/@utenti/@registrati',
array(
'module' => 'core',
'controller' => 'utenti',
'action' => 'registrazione'
),
array(
'language' => '[a-z]{2}'
)
);
$router->addRoute('page', $page);
$router->addRoute('registrazione', $registrazione);
.....
}
我无法将默认翻译器设置为 Zend_Controller_Router_Route(用于翻译的段),因为我不知道请求对象中的语言参数。我在“routeShutdown”期间获得多语言插件中的语言参数:
class Activa_Controller_Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract {
public function routeShutdown(Zend_Controller_Request_Abstract $request) {
$language = $request->getParam("language");
$locale = new Zend_Locale($language);
$translate = new Zend_Translate('array', APPLICATION_PATH.'/config/lang/'.$language.'.php', $locale);
Zend_Registry::set('Zend_Locale', $locale);
Zend_Registry::set('Zend_Translate', $translate);
Zend_Controller_Router_Route::setDefaultTranslator($translate);
////////////////////////
// BUT NOW IS TOO LATE
////////////////////////
}
当我输入地址“ http://servername/it/utenti/registrati ”时,我收到异常消息“找不到翻译器”。
我该如何解决?安东尼奥(意大利)