diff --git a/Bundle/CoreBundle/Resources/script/ngApp/filters/translateFilter.js b/Bundle/CoreBundle/Resources/script/ngApp/filters/translateFilter.js index 6aae7d6aa..abc65f209 100644 --- a/Bundle/CoreBundle/Resources/script/ngApp/filters/translateFilter.js +++ b/Bundle/CoreBundle/Resources/script/ngApp/filters/translateFilter.js @@ -1,5 +1,10 @@ angular.module('ngApp').filter('translate', function() { return function(input) { - return Translator.trans(input, {}, 'victoire'); + var originalLocale = Translator.locale; + Translator.locale = adminLocale; + var trans = Translator.trans(input, {}, 'victoire'); + Translator.locale = originalLocale; + + return trans; }; }); diff --git a/Bundle/CoreBundle/Resources/views/Layout/layout.html.twig b/Bundle/CoreBundle/Resources/views/Layout/layout.html.twig index 68e9c6ecf..c434e91d2 100644 --- a/Bundle/CoreBundle/Resources/views/Layout/layout.html.twig +++ b/Bundle/CoreBundle/Resources/views/Layout/layout.html.twig @@ -76,7 +76,7 @@ {% javascripts injector='victoire-edit, victoire-leftnavbar' %} {% endjavascripts %} - + {% endif %} {% if is_granted('ROLE_VICTOIRE') %} diff --git a/Bundle/I18nBundle/Listener/KernelRequestListener.php b/Bundle/I18nBundle/Listener/KernelRequestListener.php new file mode 100644 index 000000000..267ffd2eb --- /dev/null +++ b/Bundle/I18nBundle/Listener/KernelRequestListener.php @@ -0,0 +1,27 @@ + + */ +class KernelRequestListener +{ + protected $twig; + protected $availableLocales; + + public function __construct(\Twig_Environment $twig, $availableLocales) + { + $this->twig = $twig; + $this->availableLocales = $availableLocales; + } + + public function onKernelRequest(GetResponseEvent $event) + { + $this->twig->addGlobal('victoire_i18n_available_locales', $this->availableLocales); + } +} diff --git a/Bundle/I18nBundle/Listener/LocaleListener.php b/Bundle/I18nBundle/Listener/LocaleListener.php deleted file mode 100644 index c79e835fd..000000000 --- a/Bundle/I18nBundle/Listener/LocaleListener.php +++ /dev/null @@ -1,78 +0,0 @@ -defaultLocale = $defaultLocale; - $this->localeResolver = $localeResolver; - } - - /** - * @param GetResponseEvent $event - * - * method called on kernel request used only to persist locale in session - */ - public function onKernelRequest(GetResponseEvent $event) - { - $request = $event->getRequest(); - if (!$request->hasPreviousSession()) { - return; - } - - $locale = $this->localeResolver->resolve($request); - - // on essaie de voir si la locale a été fixée dans le paramètre de routing _locale - if ($locale = $request->getLocale()) { - $request->getSession()->set('_locale', $locale); - $request->setLocale($locale); - } else { - // si aucune locale n'a été fixée explicitement dans la requête, on utilise celle de la session - $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale)); - } - } - - /** - * This method will be called on user login in order to set the victoire locale. - * - * @param InteractiveLoginEvent $event - */ - public function onLogin(InteractiveLoginEvent $event) - { - $user = $event->getAuthenticationToken()->getUser(); - - if ($user instanceof VictoireUserInterface) { - // set the victoireLocale - $event->getRequest()->getSession()->set('victoire_locale', $user->getLocale()); - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - SecurityEvents::INTERACTIVE_LOGIN => 'onLogin', - KernelEvents::REQUEST => 'onKernelRequest', - ]; - } -} diff --git a/Bundle/I18nBundle/Resources/config/services.yml b/Bundle/I18nBundle/Resources/config/services.yml index b014e7e5e..f21f5d3c8 100644 --- a/Bundle/I18nBundle/Resources/config/services.yml +++ b/Bundle/I18nBundle/Resources/config/services.yml @@ -1,5 +1,4 @@ services: - victoire_i18n.locale_resolver: class: Victoire\Bundle\I18nBundle\Resolver\LocaleResolver arguments: @@ -27,3 +26,11 @@ services: - '@victoire_i18n.locale_resolver' tags: - { name: routing.loader } + + victoire_i18n.kernelrequest.listener: + class: Victoire\Bundle\I18nBundle\Listener\KernelRequestListener + arguments: + - '@twig' + - '%victoire_i18n.available_locales%' + tags: + - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }