From: Raphaƫl Gertz Date: Tue, 14 Oct 2025 11:10:27 +0000 (+0200) Subject: Readd short locale alternate link when missing X-Git-Tag: 0.0.1~15 X-Git-Url: https://git.rapsys.eu/blogbundle/commitdiff_plain/3d10d3501676aad377f91aa03155b176a1fdf270?ds=inline Readd short locale alternate link when missing --- 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) + ]; } } }