]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added possibility to change locale from login/register pages
authorNicolas Lœuillet <nicolas@loeuillet.org>
Mon, 12 Jun 2017 15:23:35 +0000 (17:23 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Tue, 12 Dec 2017 19:33:48 +0000 (20:33 +0100)
app/config/security.yml
src/Wallabag/CoreBundle/Controller/ConfigController.php
src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
src/Wallabag/UserBundle/Resources/config/services.yml
src/Wallabag/UserBundle/Resources/views/Registration/register_content.html.twig
src/Wallabag/UserBundle/Resources/views/layout.html.twig

index 796dc361e1ea202e67cd3f610f283f81502d1020..594fca60dc11d8e2b0f907fc65983514e0c26ac5 100644 (file)
@@ -61,6 +61,7 @@ security:
         - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: /(unread|starred|archive|all).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
+        - { path: ^/locale, role: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: /tags/(.*).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
         - { path: ^/settings, roles: ROLE_SUPER_ADMIN }
index a89bb7805b6bc98c9129620eaaa8ff4016c65efb..7fc8fb699c14f6d05331dd6543d1bf9f7b380d32 100644 (file)
@@ -424,4 +424,23 @@ class ConfigController extends Controller
 
         return $config;
     }
+
+    /**
+     * Change the locale for the current user.
+     *
+     * @param Request $request
+     * @param string  $language
+     *
+     * @Route("/locale/{language}", name="changeLocale")
+     *
+     * @return \Symfony\Component\HttpFoundation\RedirectResponse
+     */
+    public function setLocaleAction(Request $request, $language = null)
+    {
+        if ($language != null) {
+            $this->get('session')->set('_locale', $language);
+        }
+
+        return $this->redirect($request->headers->get('referer'));
+    }
 }
index e4d55c19746ff78f0df97bc052c464426f57b87d..5cabfd35ae21516d2294047ff13e5e4b5b54e425 100644 (file)
@@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager;
 use FOS\UserBundle\Event\UserEvent;
 use FOS\UserBundle\FOSUserEvents;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\HttpFoundation\Session\Session;
 use Wallabag\CoreBundle\Entity\Config;
 
 /**
@@ -22,8 +23,9 @@ class CreateConfigListener implements EventSubscriberInterface
     private $readingSpeed;
     private $actionMarkAsRead;
     private $listMode;
+    private $session;
 
-    public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode)
+    public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode, Session $session)
     {
         $this->em = $em;
         $this->theme = $theme;
@@ -33,6 +35,7 @@ class CreateConfigListener implements EventSubscriberInterface
         $this->readingSpeed = $readingSpeed;
         $this->actionMarkAsRead = $actionMarkAsRead;
         $this->listMode = $listMode;
+        $this->session = $session;
     }
 
     public static function getSubscribedEvents()
@@ -52,7 +55,7 @@ class CreateConfigListener implements EventSubscriberInterface
         $config->setTheme($this->theme);
         $config->setItemsPerPage($this->itemsOnPage);
         $config->setRssLimit($this->rssLimit);
-        $config->setLanguage($this->language);
+        $config->setLanguage($this->session->get('_locale', $this->language));
         $config->setReadingSpeed($this->readingSpeed);
         $config->setActionMarkAsRead($this->actionMarkAsRead);
         $config->setListMode($this->listMode);
index d3925de3b1f8991ea9bd9029a73418088bd2be4c..72cda3f8a32899797c51b7d5c3402a64df5cb4f2 100644 (file)
@@ -33,6 +33,7 @@ services:
             - "%wallabag_core.reading_speed%"
             - "%wallabag_core.action_mark_as_read%"
             - "%wallabag_core.list_mode%"
+            - "@session"
         tags:
             - { name: kernel.event_subscriber }
 
index d0a85fc745edd807a62f0034da2af04235c0a252..85cd4f0d3dddc217290e4b999c9e25d2b6304cad 100644 (file)
@@ -3,7 +3,6 @@
 {{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}
     <div class="card-content">
         <div class="row">
-
             {{ form_widget(form._token) }}
 
             {% for flashMessage in app.session.flashbag.get('notice') %}
index eada1829a403734f682714224626fa8b7fdd28ad..d2f8df85149799c40b26b6d2bfb1110a682b4949 100644 (file)
@@ -10,6 +10,9 @@
 {% block content %}
 <main class="valign-wrapper">
     <div class="valign row">
+        <a href="{{ path('changeLocale', {'language': 'de'}) }}">DE</a>
+        <a href="{{ path('changeLocale', {'language': 'en'}) }}">EN</a>
+        <a href="{{ path('changeLocale', {'language': 'fr'}) }}">FR</a>
         <div class="card sw">
             <div class="center"><img src="{{ asset('wallassets/themes/_global/img/logo-other_themes.png') }}" alt="wallabag logo" /></div>
             {% block fos_user_content %}