Translated segments for standard route
Wednesday, April 1, 2009
I have finally done the translated route, which is now part of the standard route in the Zend Framework, and merged it to trunk. There is not much to tell about it, but the example from the manual should give you an idea how it works. Basically it'll help you to localize your routes based on the current language:This feature will be available with the soonish released 1.8 version of the framework. Against my past thoughts, Zend_Ical and ZendX_Whois will also be available with this release.<?php// Prepate the translator$translator = new Zend_Translate('array', array(), 'en');$translator->addTranslation(array('archive' => 'archiv','year' => 'jahr','month' => 'monat'),'de');// Set the current locale for the translator$translator->setLocale('en');// Set it as default translator for routesZend_Controller_Router_Route::setDefaultTranslator($translator);// Create the route$route = new Zend_Controller_Router_Route('@archive/:@mode/:value',array('mode' => 'year''value' => 2005,'controller' => 'archive','action' => 'show'),array('mode' => '(month|year)''value' => '\d+'));$router->addRoute('archive', $route);// Assemble the URL in default locale: archive/month/5$route->assemble(array('mode' => 'month', 'value' => '5'));// Assemble the URL in german: archiv/monat/5$route->assemble(array('mode' => 'month', 'value' => '5', '@locale' => 'de'));
Update: The information about Zend_Ical and ZendX_Whois being in 1.8 was surely an April's fool joke.
Comments to this article
Leave a comment
Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and for notifications.


It's a joke!
Do you know the aproximate relese date for the 1.8 version? I need translatable routes and depending on the date I will wait or "borrow them" from trunk :P
Thanks!
Around April, but don't nail me on it. It is safe to start using the trunk until 1.8 comes out.