From 3d10d3501676aad377f91aa03155b176a1fdf270 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Tue, 14 Oct 2025 13:10:27 +0200 Subject: [PATCH] Readd short locale alternate link when missing --- Controller/AbstractController.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 2efdd34..57a0ffc 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -393,6 +393,27 @@ abstract class AbstractController extends BaseAbstractController implements Serv //Set locale locales context $parameters['alternates'][$shortCurrent] = $parameters['alternates'][str_replace('_', '-', $locale)]; } + //Add shorter locale + } elseif (empty($parameters['alternates'][$shortCurrent = substr($locale, 0, 2)])) { + //Set titles + $titles = []; + + //Set route params locale + $routeParams['_locale'] = $locale; + + //Iterate on other locales + foreach(array_diff($this->config['locales'], [$locale]) as $other) { + //Set other locale title + $titles[$other] = $this->translator->trans($this->config['languages'][$locale], [], null, $other); + } + + //Set locale locales context + $parameters['alternates'][$shortCurrent] = [ + 'absolute' => $this->router->generate($this->route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL), + 'relative' => $this->router->generate($this->route, $routeParams), + 'title' => implode('/', $titles), + 'translated' => $this->translator->trans($this->config['languages'][$locale], [], null, $locale) + ]; } } } -- 2.41.3