2

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
4

1 回答 1

2

您不必复制控制器。我是这样做的:

$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);

语言文件如下所示: 您可以翻译控制器或操作。但我不知道您是否也可以翻译查询参数。

// en_url.php
return array(
  'products' => 'products',
);

// nl_url.php
return array(
  'products' => 'producten',
);

在此处阅读更多相关信息。

于 2013-05-17T14:24:16.420 回答