diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2018-10-15 08:31:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 08:31:42 +0000 |
commit | 5bb01c034424b56a0a0ae4bc34ae5bb9a514deba (patch) | |
tree | bb18d67c8ec03bf8abd24dc6ef2138c3f81f6fa5 /src/Wallabag | |
parent | 43b6f3a8a8173c47475632ca2869f190b552b5d6 (diff) | |
parent | 4d4147b228ac90f329fd2d40dd4fb60cb980328a (diff) | |
download | wallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.tar.gz wallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.tar.zst wallabag-5bb01c034424b56a0a0ae4bc34ae5bb9a514deba.zip |
Merge pull request #3216 from wallabag/change-locale-register
Added possibility to change locale from login/register pages
Diffstat (limited to 'src/Wallabag')
6 files changed, 38 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 242f557f..be6feb7c 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; | |||
8 | use Symfony\Component\HttpFoundation\Request; | 8 | use Symfony\Component\HttpFoundation\Request; |
9 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | 9 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
10 | use Symfony\Component\Routing\Annotation\Route; | 10 | use Symfony\Component\Routing\Annotation\Route; |
11 | use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint; | ||
11 | use Wallabag\CoreBundle\Entity\Config; | 12 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\CoreBundle\Entity\TaggingRule; | 13 | use Wallabag\CoreBundle\Entity\TaggingRule; |
13 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 14 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
@@ -330,6 +331,27 @@ class ConfigController extends Controller | |||
330 | } | 331 | } |
331 | 332 | ||
332 | /** | 333 | /** |
334 | * Change the locale for the current user. | ||
335 | * | ||
336 | * @param Request $request | ||
337 | * @param string $language | ||
338 | * | ||
339 | * @Route("/locale/{language}", name="changeLocale") | ||
340 | * | ||
341 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
342 | */ | ||
343 | public function setLocaleAction(Request $request, $language = null) | ||
344 | { | ||
345 | $errors = $this->get('validator')->validate($language, (new LocaleConstraint())); | ||
346 | |||
347 | if (0 === \count($errors)) { | ||
348 | $request->getSession()->set('_locale', $language); | ||
349 | } | ||
350 | |||
351 | return $this->redirect($request->headers->get('referer', $this->generateUrl('homepage'))); | ||
352 | } | ||
353 | |||
354 | /** | ||
333 | * Remove all tags for given tags and a given user and cleanup orphan tags. | 355 | * Remove all tags for given tags and a given user and cleanup orphan tags. |
334 | * | 356 | * |
335 | * @param array $tags | 357 | * @param array $tags |
diff --git a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php index 367cdfb0..dc1db5c7 100644 --- a/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php +++ b/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php | |||
@@ -6,8 +6,10 @@ use Symfony\Component\HttpFoundation\Session\Session; | |||
6 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | 6 | use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Stores the locale of the user in the session after the | 9 | * Stores the locale of the user in the session after the login. |
10 | * login. This can be used by the LocaleListener afterwards. | 10 | * If no locale are defined (if user doesn't change it from the login screen), override it with the user's config one. |
11 | * | ||
12 | * This can be used by the LocaleListener afterwards. | ||
11 | * | 13 | * |
12 | * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html | 14 | * @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html |
13 | */ | 15 | */ |
@@ -30,7 +32,7 @@ class UserLocaleListener | |||
30 | { | 32 | { |
31 | $user = $event->getAuthenticationToken()->getUser(); | 33 | $user = $event->getAuthenticationToken()->getUser(); |
32 | 34 | ||
33 | if (null !== $user->getConfig()->getLanguage()) { | 35 | if (null !== $user->getConfig()->getLanguage() && null === $this->session->get('_locale')) { |
34 | $this->session->set('_locale', $user->getConfig()->getLanguage()); | 36 | $this->session->set('_locale', $user->getConfig()->getLanguage()); |
35 | } | 37 | } |
36 | } | 38 | } |
diff --git a/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php index e4d55c19..5cabfd35 100644 --- a/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php +++ b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php | |||
@@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; | |||
6 | use FOS\UserBundle\Event\UserEvent; | 6 | use FOS\UserBundle\Event\UserEvent; |
7 | use FOS\UserBundle\FOSUserEvents; | 7 | use FOS\UserBundle\FOSUserEvents; |
8 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | 8 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
9 | use Symfony\Component\HttpFoundation\Session\Session; | ||
9 | use Wallabag\CoreBundle\Entity\Config; | 10 | use Wallabag\CoreBundle\Entity\Config; |
10 | 11 | ||
11 | /** | 12 | /** |
@@ -22,8 +23,9 @@ class CreateConfigListener implements EventSubscriberInterface | |||
22 | private $readingSpeed; | 23 | private $readingSpeed; |
23 | private $actionMarkAsRead; | 24 | private $actionMarkAsRead; |
24 | private $listMode; | 25 | private $listMode; |
26 | private $session; | ||
25 | 27 | ||
26 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode) | 28 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed, $actionMarkAsRead, $listMode, Session $session) |
27 | { | 29 | { |
28 | $this->em = $em; | 30 | $this->em = $em; |
29 | $this->theme = $theme; | 31 | $this->theme = $theme; |
@@ -33,6 +35,7 @@ class CreateConfigListener implements EventSubscriberInterface | |||
33 | $this->readingSpeed = $readingSpeed; | 35 | $this->readingSpeed = $readingSpeed; |
34 | $this->actionMarkAsRead = $actionMarkAsRead; | 36 | $this->actionMarkAsRead = $actionMarkAsRead; |
35 | $this->listMode = $listMode; | 37 | $this->listMode = $listMode; |
38 | $this->session = $session; | ||
36 | } | 39 | } |
37 | 40 | ||
38 | public static function getSubscribedEvents() | 41 | public static function getSubscribedEvents() |
@@ -52,7 +55,7 @@ class CreateConfigListener implements EventSubscriberInterface | |||
52 | $config->setTheme($this->theme); | 55 | $config->setTheme($this->theme); |
53 | $config->setItemsPerPage($this->itemsOnPage); | 56 | $config->setItemsPerPage($this->itemsOnPage); |
54 | $config->setRssLimit($this->rssLimit); | 57 | $config->setRssLimit($this->rssLimit); |
55 | $config->setLanguage($this->language); | 58 | $config->setLanguage($this->session->get('_locale', $this->language)); |
56 | $config->setReadingSpeed($this->readingSpeed); | 59 | $config->setReadingSpeed($this->readingSpeed); |
57 | $config->setActionMarkAsRead($this->actionMarkAsRead); | 60 | $config->setActionMarkAsRead($this->actionMarkAsRead); |
58 | $config->setListMode($this->listMode); | 61 | $config->setListMode($this->listMode); |
diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml index d3925de3..72cda3f8 100644 --- a/src/Wallabag/UserBundle/Resources/config/services.yml +++ b/src/Wallabag/UserBundle/Resources/config/services.yml | |||
@@ -33,6 +33,7 @@ services: | |||
33 | - "%wallabag_core.reading_speed%" | 33 | - "%wallabag_core.reading_speed%" |
34 | - "%wallabag_core.action_mark_as_read%" | 34 | - "%wallabag_core.action_mark_as_read%" |
35 | - "%wallabag_core.list_mode%" | 35 | - "%wallabag_core.list_mode%" |
36 | - "@session" | ||
36 | tags: | 37 | tags: |
37 | - { name: kernel.event_subscriber } | 38 | - { name: kernel.event_subscriber } |
38 | 39 | ||
diff --git a/src/Wallabag/UserBundle/Resources/views/Registration/register_content.html.twig b/src/Wallabag/UserBundle/Resources/views/Registration/register_content.html.twig index d0a85fc7..85cd4f0d 100644 --- a/src/Wallabag/UserBundle/Resources/views/Registration/register_content.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/Registration/register_content.html.twig | |||
@@ -3,7 +3,6 @@ | |||
3 | {{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }} | 3 | {{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }} |
4 | <div class="card-content"> | 4 | <div class="card-content"> |
5 | <div class="row"> | 5 | <div class="row"> |
6 | |||
7 | {{ form_widget(form._token) }} | 6 | {{ form_widget(form._token) }} |
8 | 7 | ||
9 | {% for flashMessage in app.session.flashbag.get('notice') %} | 8 | {% for flashMessage in app.session.flashbag.get('notice') %} |
diff --git a/src/Wallabag/UserBundle/Resources/views/layout.html.twig b/src/Wallabag/UserBundle/Resources/views/layout.html.twig index 99bf7dfd..b53f8746 100644 --- a/src/Wallabag/UserBundle/Resources/views/layout.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/layout.html.twig | |||
@@ -15,6 +15,11 @@ | |||
15 | {% block fos_user_content %} | 15 | {% block fos_user_content %} |
16 | {% endblock fos_user_content %} | 16 | {% endblock fos_user_content %} |
17 | </div> | 17 | </div> |
18 | <div class="center"> | ||
19 | <a href="{{ path('changeLocale', {'language': 'de'}) }}">Deutsch</a> – | ||
20 | <a href="{{ path('changeLocale', {'language': 'en'}) }}">English</a> – | ||
21 | <a href="{{ path('changeLocale', {'language': 'fr'}) }}">Français</a> | ||
22 | </div> | ||
18 | </div> | 23 | </div> |
19 | </main> | 24 | </main> |
20 | {% endblock %} | 25 | {% endblock %} |