Zend_Controller_Router_Route: Could not find a translator
- by Antonio
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)