]> Raphaƫl G. Git Repositories - blogbundle/blobdiff - Controller/AbstractController.php
Update translations for new context layout
[blogbundle] / Controller / AbstractController.php
index 2efdd34244d3bf009e653bfdec0c1eebfca03937..fca2be926746fc610f97fe6d657fcdd72474f7db 100644 (file)
@@ -337,7 +337,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                        'logo' => $this->config['logo'],
                        'next' => null,
                        'prev' => null,
                        'logo' => $this->config['logo'],
                        'next' => null,
                        'prev' => null,
-                       'root' => $this->router->generate($this->config['root']),
+                       'root' => $this->config['root'],
                        'title' => [
                                'page' => null,
                                'section' => null,
                        'title' => [
                                'page' => null,
                                'section' => null,
@@ -393,6 +393,27 @@ abstract class AbstractController extends BaseAbstractController implements Serv
                                                //Set locale locales context
                                                $parameters['alternates'][$shortCurrent] = $parameters['alternates'][str_replace('_', '-', $locale)];
                                        }
                                                //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)
+                                       ];
                                }
                        }
                }
                                }
                        }
                }