Reputation: 2600
I would like to have internationalized urls for a better user experience (All in intranets, so no SEO to worry about).
So basically i would like URLS like this (in this example, english, dutch and french):
/en/products
/en/product/123/blue-box
/nl/producten
/nl/product/123/blauwe-doos
/fr/produits
/fr/produit/123/boite-bleue
The /nl/
part is no problem at all and described all over SO and the internet. But my problem is with routing to the controllers and actions.
Currently i have extended from the default router and used Zend_Translate to translate everything to english and have controllers and actions based on the english names.
However i keep having the feeling that there should be a better way to do this. Does anyone know if there are standard components in zend framework for this or had perhaps already created something like this before.
specs:
PHP 5.4.4
Zend Framework 1.11.10
Upvotes: 2
Views: 190
Reputation: 12655
You don't have to copy your controllers. I've done it this way:
$translate = new Zend_Translate(
array(
'adapter' => 'array',
'content' => 'PATH_TO_LANGUAGES/en_url.php',
'locale' => 'en'
)
);
$translate->addTranslation(array(
'content' => 'PATH_TO_LANGUAGES/nl_url.php',
'locale' => 'nl'
));
$translate->setLocale('en');
Zend_Controller_Router_Route::setDefaultTranslator($translate);
The language files look like this: You can translate controllers or actions. But I don't know if you can translate query params, too.
// en_url.php
return array(
'products' => 'products',
);
// nl_url.php
return array(
'products' => 'producten',
);
Read more about it here.
Upvotes: 2