Zend_Controller_Router_Route:找不到翻译器
我正在开发一个多语言应用程序。在引导程序中,有路由设置:
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”我收到异常消息“找不到翻译”。
我该如何修复它? 安东尼奥(意大利)
I am developing a multilanguage application. In the bootstrap there is the routes setup:
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);
.....
}
I cannot set the default translator to Zend_Controller_Router_Route (for translated segments) because i don't know the language parameter in the request object.
I get the language parameter in Multilanguage Plugin during the "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
////////////////////////
}
When i type the address "http://servername/it/utenti/registrati" i get the exception with the message "Could not find a translator".
How can i fix it?
Antonio (Italy)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个 routeStartup() 插件,在其中扫描请求 URI 的区域设置/语言,例如使用简单的正则表达式。然后在路由器中创建并设置默认转换器。
Create a routeStartup() plugin, in which you scan the request URI for the locale/language, for example with a simple Regex. Then create and set the default translator in the Router.