zendframework/zf2 — pull request #5328 by coolmic (2013-10-23 15:43:19+00:00)
Title: Add EventManager in Router/Http/Part

@DASPRiD

Like always, sorry for my english.

I am trying to add translation in the url, and I want something like

http://www.website.com/fr/contact-nous
http://www.website.com/en/contact-us

Router configuration :
```php
array(
'router' => array(
'router_class' => 'Zend\Mvc\Router\Http\TranslatorAwareTreeRouteStack'
'routes' => array(
'i18n' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:lang]',
'defaults' => array(
'lang' => 'fr'
),
'constraints' => array(
'lang' => 'fr|en'
)
),
'may_terminate' => false,

'child_routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'App\Controller\Index',
'action' => 'index',
),
),
),

'contact' => array(
'type' => 'Segment',
'options' => array(
'route' => '/{contact}',
'defaults' => array(
'controller' => 'App\Controller\Contact',
'action' => 'index',
),
),
)
)
)
),
)
)
```

http://www.website.com/fr/contact-nous works , but not http://www.website.com/en/contact-us .

The issue is like egg and chicken.
I need to set the Route translator locale to the value of :lang , but the routing is still not finished, so I still don't know the lang requested.

Maybe create my own Route would work too but
I think that adding an event manager in SimpleRouteStack ( for now, I only edited Part route) will make it easier.

All I have to do is add in Module
```php
public function onBootstrap(EventInterface $e)
{
if (!($e instanceof MvcEvent)) {
return;
}

$serviceLocator = $e->getApplication()->getServiceManager();

$sharedManager = $e->getApplication()->getEventManager()->getSharedManager();
$sharedManager->attach(
'Zend\Mvc\Router\Http\Part',
'match',
function (EventInterface $event) use ($serviceLocator) {
$match = $event->getParam('match');
if ($match instanceof RouteMatch) {
if ($lang = $match->getParam('lang')) {
$serviceLocator->get('Translator')->setLocale($lang);
$serviceLocator->get('Router')->setDefaultParam('lang', $lang); // don't need specify current lang on assemblage
}
}
}
);
}
```