I want to use a URL rewrite on my site:
/:@controller/:@action/
So I want to use translated segments on route and I want to detect requested language from these translated segments. For example, if user request a url like this:
/user/profile/
then I could understand that requested language is English. And if user request a url like this:
/kullanici/profil/
then I coult understand that requested language is Turkish. How can I do this with Zend_Controller_Router?
We solved our problem by creating a new router with extending Zend_Controller_Router_Route. We overrode "match" method of class and added some lines of code to original match code.
.....
foreach( $translateMessages as $key => $val ) {
if (($originalPathPart = array_search($pathPart, $val)) !== false) {
$pathPart = $originalPathPart;
if (!$this->_localeSet) {
$locale = Zend_Registry::get('Zend_Locale');
$locale->setLocale($key); // Set Locale by translated key language
$this->_localeSet = true; // Added to class with default value false
$this->_activeLocale = $key; // Added to class with default value ''
}else{
// A second translated key but this is not same language.
// Then rise 404 error
if ($this->_activeLocale != $key) {
//FIXME: Rise 404 error
throw new Exception("URL Not Found");
}
}
}
}
.....