diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2017-06-12 17:23:35 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2017-12-12 20:33:48 +0100 |
commit | dd50f50597720af7d39708a847b7e8604fd9d341 (patch) | |
tree | 179f84687994d80959bbbac54edffa27e9ba2410 | |
parent | d80e9931f5faa071c44453e03c4ac45025106a3f (diff) | |
download | wallabag-dd50f50597720af7d39708a847b7e8604fd9d341.tar.gz wallabag-dd50f50597720af7d39708a847b7e8604fd9d341.tar.zst wallabag-dd50f50597720af7d39708a847b7e8604fd9d341.zip |
Added possibility to change locale from login/register pages
6 files changed, 29 insertions, 3 deletions
diff --git a/app/config/security.yml b/app/config/security.yml index 796dc361..594fca60 100644 --- a/app/config/security.yml +++ b/app/config/security.yml | |||
@@ -61,6 +61,7 @@ security: | |||
61 | - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } | 61 | - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } |
62 | - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } | 62 | - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } |
63 | - { path: /(unread|starred|archive|all).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } | 63 | - { path: /(unread|starred|archive|all).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } |
64 | - { path: ^/locale, role: IS_AUTHENTICATED_ANONYMOUSLY } | ||
64 | - { path: /tags/(.*).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } | 65 | - { path: /tags/(.*).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY } |
65 | - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY } | 66 | - { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY } |
66 | - { path: ^/settings, roles: ROLE_SUPER_ADMIN } | 67 | - { path: ^/settings, roles: ROLE_SUPER_ADMIN } |
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index a89bb780..7fc8fb69 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -424,4 +424,23 @@ class ConfigController extends Controller | |||
424 | 424 | ||
425 | return $config; | 425 | return $config; |
426 | } | 426 | } |
427 | |||
428 | /** | ||
429 | * Change the locale for the current user. | ||
430 | * | ||
431 | * @param Request $request | ||
432 | * @param string $language | ||
433 | * | ||
434 | * @Route("/locale/{language}", name="changeLocale") | ||
435 | * | ||
436 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
437 | */ | ||
438 | public function setLocaleAction(Request $request, $language = null) | ||
439 | { | ||
440 | if ($language != null) { | ||
441 | $this->get('session')->set('_locale', $language); | ||
442 | } | ||
443 | |||
444 | return $this->redirect($request->headers->get('referer')); | ||
445 | } | ||
427 | } | 446 | } |
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 eada1829..d2f8df85 100644 --- a/src/Wallabag/UserBundle/Resources/views/layout.html.twig +++ b/src/Wallabag/UserBundle/Resources/views/layout.html.twig | |||
@@ -10,6 +10,9 @@ | |||
10 | {% block content %} | 10 | {% block content %} |
11 | <main class="valign-wrapper"> | 11 | <main class="valign-wrapper"> |
12 | <div class="valign row"> | 12 | <div class="valign row"> |
13 | <a href="{{ path('changeLocale', {'language': 'de'}) }}">DE</a> | ||
14 | <a href="{{ path('changeLocale', {'language': 'en'}) }}">EN</a> | ||
15 | <a href="{{ path('changeLocale', {'language': 'fr'}) }}">FR</a> | ||
13 | <div class="card sw"> | 16 | <div class="card sw"> |
14 | <div class="center"><img src="{{ asset('wallassets/themes/_global/img/logo-other_themes.png') }}" alt="wallabag logo" /></div> | 17 | <div class="center"><img src="{{ asset('wallassets/themes/_global/img/logo-other_themes.png') }}" alt="wallabag logo" /></div> |
15 | {% block fos_user_content %} | 18 | {% block fos_user_content %} |