Peter Moberg
Peter Moberg

Reputation: 3098

How to add localization in the URL using the Zend Router

I have a Zend Framework site that setups all routes in a file, routes.ini. The routes look like this:

routes.popular.route = popular/:type/:page/:sortOrder
routes.popular.defaults.controller = popular
routes.popular.defaults.action = index
routes.popular.defaults.type = images
routes.popular.defaults.sortOrder = alltime
routes.popular.defaults.page = 1
routes.popular.reqs.type = \w+
routes.popular.reqs.page = \d+
routes.popular.reqs.sortOrder = \w+

In bootstrap.php they are read and added to the frontController:

$config = new Zend_Config_Ini(APPLICATION_PATH . ‘/config/routes.ini’);
$router = $frontController->getRouter();
$router->addConfig($config,‘routes’);

I would like to add localization to the URL, for example www.mysite.com/en/popular, www.mysite.com/sv/popular. What is the preferred way of doing this?

Upvotes: 3

Views: 1079

Answers (1)

St.Woland
St.Woland

Reputation: 5417

It's a good idea to have the default route localized, so I would suggest the following configuration:

routes.default.route = :lang/:controller/:action
routes.default.defaults.lang = en
routes.default.defaults.controller = default
routes.default.defaults.action = index

routes.popular.route = :lang/popular/:type/:page/:sortOrder
routes.popular.defaults.lang = en
routes.popular.defaults.controller = popular
routes.popular.defaults.action = index
routes.popular.defaults.type = images
routes.popular.defaults.sortOrder = alltime
routes.popular.defaults.page = 1
routes.popular.reqs.type = \w+
routes.popular.reqs.page = \d+
routes.popular.reqs.sortOrder = \w+

Upvotes: 2

Related Questions