]> Raphaël G. Git Repositories - blogbundle/commitdiff
Readd short locale alternate link when missing
authorRaphaël Gertz <git@rapsys.eu>
Tue, 14 Oct 2025 11:10:27 +0000 (13:10 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Tue, 14 Oct 2025 11:10:27 +0000 (13:10 +0200)
Controller/AbstractController.php

index 2efdd34244d3bf009e653bfdec0c1eebfca03937..57a0ffc4c071ed17f03683493420cc3abd5b212b 100644 (file)
@@ -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)
+                                       ];
                                }
                        }
                }