diff options
11 files changed, 136 insertions, 12 deletions
diff --git a/app/config/config.yml b/app/config/config.yml index 956fdd07..a4d88b94 100644 --- a/app/config/config.yml +++ b/app/config/config.yml | |||
@@ -25,6 +25,11 @@ framework: | |||
25 | fragments: ~ | 25 | fragments: ~ |
26 | http_method_override: true | 26 | http_method_override: true |
27 | 27 | ||
28 | wallabag_core: | ||
29 | languages: | ||
30 | en: 'English' | ||
31 | fr: 'Français' | ||
32 | |||
28 | # Twig Configuration | 33 | # Twig Configuration |
29 | twig: | 34 | twig: |
30 | debug: "%kernel.debug%" | 35 | debug: "%kernel.debug%" |
diff --git a/app/config/services.yml b/app/config/services.yml index ff6a582b..80d6c1a1 100644 --- a/app/config/services.yml +++ b/app/config/services.yml | |||
@@ -18,3 +18,15 @@ services: | |||
18 | public: false | 18 | public: false |
19 | tags: | 19 | tags: |
20 | - { name: twig.extension } | 20 | - { name: twig.extension } |
21 | |||
22 | wallabag.locale_listener: | ||
23 | class: Wallabag\CoreBundle\EventListener\LocaleListener | ||
24 | arguments: ["%kernel.default_locale%"] | ||
25 | tags: | ||
26 | - { name: kernel.event_subscriber } | ||
27 | |||
28 | wallabag.user_locale_listener: | ||
29 | class: Wallabag\CoreBundle\EventListener\UserLocaleListener | ||
30 | arguments: ["@session"] | ||
31 | tags: | ||
32 | - { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin } | ||
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 | |||
3 | namespace Wallabag\CoreBundle\DependencyInjection; | ||
4 | |||
5 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
6 | use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
7 | |||
8 | class 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 | |||
3 | namespace Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
6 | use Symfony\Component\HttpKernel\KernelEvents; | ||
7 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
8 | |||
9 | class 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 | |||
3 | namespace Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use Symfony\Component\HttpFoundation\Session\Session; | ||
6 | use 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 | */ | ||
12 | class 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; | |||
9 | class ConfigType extends AbstractType | 9 | class 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 |
110 | Information updated: "Vos informations personnelles ont bien été mises à jour" | 110 | Information updated: "Vos informations personnelles ont bien été mises à jour" |
111 | Config 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." |
112 | RSS information updated: "La configuration des flux RSS a bien été mise à jour" | 112 | RSS information updated: "La configuration des flux RSS a bien été mise à jour" |
113 | Password updated: "Votre mot de passe a bien été mis à jour" | 113 | Password updated: "Votre mot de passe a bien été mis à jour" |
114 | Entry starred: "Article ajouté dans les favoris" | 114 | Entry 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 | } |