aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2015-10-01 16:28:38 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-10-15 21:42:29 +0200
commitc89d35e851d26b78f89bd7ece5e3eaa109c8cac0 (patch)
tree554523b6b376d258fbf82b8ef8ec16236f774b5f /src/Wallabag
parent3d3ed955f11006a408c6596eb9151a0afb28e721 (diff)
downloadwallabag-c89d35e851d26b78f89bd7ece5e3eaa109c8cac0.tar.gz
wallabag-c89d35e851d26b78f89bd7ece5e3eaa109c8cac0.tar.zst
wallabag-c89d35e851d26b78f89bd7ece5e3eaa109c8cac0.zip
Language selection on config screen
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php2
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/Configuration.php25
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php4
-rw-r--r--src/Wallabag/CoreBundle/EventListener/LocaleListener.php41
-rw-r--r--src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php35
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ConfigType.php12
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml1
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml2
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php9
9 files changed, 119 insertions, 12 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index ecfecc66..ca4acc6a 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -42,7 +42,7 @@ class ConfigController extends Controller
42 42
43 $this->get('session')->getFlashBag()->add( 43 $this->get('session')->getFlashBag()->add(
44 'notice', 44 'notice',
45 'Config saved' 45 'Config saved. Some parameters will be considered after disconnection.'
46 ); 46 );
47 47
48 return $this->redirect($this->generateUrl('config')); 48 return $this->redirect($this->generateUrl('config'));
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
new file mode 100644
index 00000000..32acd1f1
--- /dev/null
+++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
@@ -0,0 +1,25 @@
1<?php
2
3namespace Wallabag\CoreBundle\DependencyInjection;
4
5use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8class Configuration implements ConfigurationInterface
9{
10 public function getConfigTreeBuilder()
11 {
12 $treeBuilder = new TreeBuilder();
13 $rootNode = $treeBuilder->root('wallabag_core');
14
15 $rootNode
16 ->children()
17 ->arrayNode('languages')
18 ->prototype('scalar')->end()
19 ->end()
20 ->end()
21 ;
22
23 return $treeBuilder;
24 }
25}
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
index 7493351b..330cc957 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
@@ -11,6 +11,10 @@ class WallabagCoreExtension extends Extension
11{ 11{
12 public function load(array $configs, ContainerBuilder $container) 12 public function load(array $configs, ContainerBuilder $container)
13 { 13 {
14 $configuration = new Configuration();
15 $config = $this->processConfiguration($configuration, $configs);
16 $container->setParameter('wallabag_core.languages', $config['languages']);
17
14 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 18 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
15 $loader->load('services.yml'); 19 $loader->load('services.yml');
16 } 20 }
diff --git a/src/Wallabag/CoreBundle/EventListener/LocaleListener.php b/src/Wallabag/CoreBundle/EventListener/LocaleListener.php
new file mode 100644
index 00000000..71795316
--- /dev/null
+++ b/src/Wallabag/CoreBundle/EventListener/LocaleListener.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\CoreBundle\EventListener;
4
5use Symfony\Component\HttpKernel\Event\GetResponseEvent;
6use Symfony\Component\HttpKernel\KernelEvents;
7use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9class LocaleListener implements EventSubscriberInterface
10{
11 private $defaultLocale;
12
13 public function __construct($defaultLocale = 'en')
14 {
15 $this->defaultLocale = $defaultLocale;
16 }
17
18 public function onKernelRequest(GetResponseEvent $event)
19 {
20 $request = $event->getRequest();
21 if (!$request->hasPreviousSession()) {
22 return;
23 }
24
25 // try to see if the locale has been set as a _locale routing parameter
26 if ($locale = $request->attributes->get('_locale')) {
27 $request->getSession()->set('_locale', $locale);
28 } else {
29 // if no explicit locale has been set on this request, use one from the session
30 $request->setLocale($request->getSession()->get('_locale', $this->defaultLocale));
31 }
32 }
33
34 public static function getSubscribedEvents()
35 {
36 return array(
37 // must be registered before the default Locale listener
38 KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
39 );
40 }
41}
diff --git a/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php b/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php
new file mode 100644
index 00000000..97bfabc8
--- /dev/null
+++ b/src/Wallabag/CoreBundle/EventListener/UserLocaleListener.php
@@ -0,0 +1,35 @@
1<?php
2
3namespace Wallabag\CoreBundle\EventListener;
4
5use Symfony\Component\HttpFoundation\Session\Session;
6use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
7
8/**
9 * Stores the locale of the user in the session after the
10 * login. This can be used by the LocaleListener afterwards.
11 */
12class UserLocaleListener
13{
14 /**
15 * @var Session
16 */
17 private $session;
18
19 public function __construct(Session $session)
20 {
21 $this->session = $session;
22 }
23
24 /**
25 * @param InteractiveLoginEvent $event
26 */
27 public function onInteractiveLogin(InteractiveLoginEvent $event)
28 {
29 $user = $event->getAuthenticationToken()->getUser();
30
31 if (null !== $user->getConfig()->getLanguage()) {
32 $this->session->set('_locale', $user->getConfig()->getLanguage());
33 }
34 }
35}
diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
index 49b05b80..1f0ad89d 100644
--- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
@@ -9,16 +9,20 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
9class ConfigType extends AbstractType 9class ConfigType extends AbstractType
10{ 10{
11 private $themes = array(); 11 private $themes = array();
12 private $languages = array();
12 13
13 /** 14 /**
14 * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes) 15 * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
16 * @param array $languages Languages come from configuration, array just code language as key and label as value
15 */ 17 */
16 public function __construct($themes) 18 public function __construct($themes, $languages)
17 { 19 {
18 $this->themes = array_combine( 20 $this->themes = array_combine(
19 $themes, 21 $themes,
20 array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes) 22 array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes)
21 ); 23 );
24
25 $this->languages = $languages;
22 } 26 }
23 27
24 public function buildForm(FormBuilderInterface $builder, array $options) 28 public function buildForm(FormBuilderInterface $builder, array $options)
@@ -29,7 +33,9 @@ class ConfigType extends AbstractType
29 'choices_as_values' => true, 33 'choices_as_values' => true,
30 )) 34 ))
31 ->add('items_per_page') 35 ->add('items_per_page')
32 ->add('language') 36 ->add('language', 'choice', array(
37 'choices' => $this->languages,
38 ))
33 ->add('save', 'submit') 39 ->add('save', 'submit')
34 ; 40 ;
35 } 41 }
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index c38787de..e29fcd1f 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -10,6 +10,7 @@ services:
10 class: Wallabag\CoreBundle\Form\Type\ConfigType 10 class: Wallabag\CoreBundle\Form\Type\ConfigType
11 arguments: 11 arguments:
12 - %liip_theme.themes% 12 - %liip_theme.themes%
13 - %wallabag_core.languages%
13 tags: 14 tags:
14 - { name: form.type, alias: config } 15 - { name: form.type, alias: config }
15 16
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index aced4d83..7b10dea1 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -108,7 +108,7 @@ download the application: "téléchargez l'application"
108 108
109# Flash messages 109# Flash messages
110Information updated: "Vos informations personnelles ont bien été mises à jour" 110Information updated: "Vos informations personnelles ont bien été mises à jour"
111Config saved: "Les paramètres de wallabag ont bien été mis à jour" 111"Config saved. Some parameters will be considered after disconnection.": "Les paramètres ont bien été mis à jour. Certains seront pris en compte après déconnexion."
112RSS information updated: "La configuration des flux RSS a bien été mise à jour" 112RSS information updated: "La configuration des flux RSS a bien été mise à jour"
113Password updated: "Votre mot de passe a bien été mis à jour" 113Password updated: "Votre mot de passe a bien été mis à jour"
114Entry starred: "Article ajouté dans les favoris" 114Entry starred: "Article ajouté dans les favoris"
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index 3da5e8b7..7085151a 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -46,7 +46,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
46 $data = array( 46 $data = array(
47 'config[theme]' => 0, 47 'config[theme]' => 0,
48 'config[items_per_page]' => '30', 48 'config[items_per_page]' => '30',
49 'config[language]' => 'fr_FR', 49 'config[language]' => 'en',
50 ); 50 );
51 51
52 $client->submit($form, $data); 52 $client->submit($form, $data);
@@ -65,12 +65,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
65 array(array( 65 array(array(
66 'config[theme]' => 0, 66 'config[theme]' => 0,
67 'config[items_per_page]' => '', 67 'config[items_per_page]' => '',
68 'config[language]' => 'fr_FR', 68 'config[language]' => 'en',
69 )),
70 array(array(
71 'config[theme]' => 0,
72 'config[items_per_page]' => '12',
73 'config[language]' => '',
74 )), 69 )),
75 ); 70 );
76 } 71 }