+
+ //Get current locale
+ #$currentLocale = $router->getContext()->getParameters()['_locale'];
+ $currentLocale = $requestStack->getCurrentRequest()->getLocale();
+
+ //Set translator locale
+ //XXX: allow LocaleSubscriber on the fly locale change for first page
+ $this->translator->setLocale($currentLocale);
+
+ //Iterate on locales excluding current one
+ foreach($this->config['locales'] as $locale) {
+ //Set titles
+ $titles = [];
+
+ //Iterate on other locales
+ foreach(array_diff($this->config['locales'], [$locale]) as $other) {
+ $titles[$other] = $translator->trans($this->config['languages'][$locale], [], null, $other);
+ }
+
+ //Get context path
+ $path = $router->getContext()->getPathInfo();
+
+ //Retrieve route matching path
+ $route = $router->match($path);
+
+ //Get route name
+ $name = $route['_route'];
+
+ //Unset route name
+ unset($route['_route']);
+
+ //With current locale
+ if ($locale == $currentLocale) {
+ //Set locale locales context
+ $this->context['canonical'] = $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL);
+ } else {
+ //Set locale locales context
+ $this->context['alternates'][] = [
+ 'lang' => $locale,
+ 'absolute' => $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL),
+ 'relative' => $router->generate($name, ['_locale' => $locale]+$route),
+ 'title' => implode('/', $titles),
+ 'translated' => $translator->trans($this->config['languages'][$locale], [], null, $locale)
+ ];
+ }
+ }