Added possibility to change locale from login/register pages

This commit is contained in:
Nicolas Lœuillet 2017-06-12 17:23:35 +02:00 committed by Jeremy Benoist
parent 43b6f3a8a8
commit be417ef236
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
6 changed files with 31 additions and 3 deletions

View file

@ -64,6 +64,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 }

View file

@ -329,6 +329,25 @@ class ConfigController extends Controller
return $this->redirect($request->headers->get('referer'));
}
/**
* 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 (null !== $language) {
$this->get('session')->set('_locale', $language);
}
return $this->redirect($request->headers->get('referer'));
}
/**
* Remove all tags for given tags and a given user and cleanup orphan tags.
*

View 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);

View 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 }

View 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') %}

View file

@ -15,6 +15,11 @@
{% block fos_user_content %}
{% endblock fos_user_content %}
</div>
<div class="center">
<a href="{{ path('changeLocale', {'language': 'de'}) }}">Deutsch</a>
<a href="{{ path('changeLocale', {'language': 'en'}) }}">English</a>
<a href="{{ path('changeLocale', {'language': 'fr'}) }}">Français</a>
</div>
</div>
</main>
{% endblock %}