Browse Source

Mise en place des lien permettant de changer le laguage.

bastien 12 years ago
parent
commit
1053c22ad3

+ 5 - 2
app/config/routing.yml View File

@@ -8,6 +8,10 @@
8 8
 MuzichIndexBundle:
9 9
   resource: "@MuzichIndexBundle/Resources/config/routing.yml"
10 10
   prefix: /
11
+    
12
+change_language:
13
+    pattern:  /change-language/{language}/{redirect}
14
+    defaults: { _controller: MuzichCoreBundle:Core:changeLanguage, redirect: referer }
11 15
   
12 16
 MuzichCoreBundle:
13 17
   resource: "@MuzichCoreBundle/Resources/config/routing.yml"
@@ -16,8 +20,7 @@ MuzichCoreBundle:
16 20
 
17 21
 MuzichHomeBundle:
18 22
   resource: "@MuzichHomeBundle/Resources/config/routing.yml"
19
-  prefix: /{_locale}/
20
-  defaults: { _locale: fr }
23
+  prefix: /
21 24
 
22 25
 MuzichUserBundle:
23 26
   resource: "@MuzichUserBundle/Resources/config/routing.yml"

+ 31 - 0
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -10,10 +10,41 @@ use Muzich\CoreBundle\Entity\FollowGroup;
10 10
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
11 11
 use Muzich\CoreBundle\ElementFactory\ElementManager;
12 12
 use Muzich\CoreBundle\Entity\Element;
13
+use Symfony\Component\HttpFoundation\RedirectResponse;
13 14
 
14 15
 class CoreController extends Controller
15 16
 {
16 17
   
18
+  public function changeLanguageAction($language, $redirect)
19
+  {
20
+    if($language != null)
21
+    {
22
+      $old = $this->get('session')->getLocale();
23
+      $this->get('session')->setLocale($language);
24
+    }
25
+    
26
+    $url_referer = $this->container->get('request')->headers->get('referer');
27
+    
28
+    // On effectue un contrôl un peu sépcial:
29
+    // Si la page de demande était la page de connexion (hello)
30
+    if (
31
+      $this->generateUrl('index', array('_locale' => $old), true) == $url_referer
32
+      || $this->generateUrl('index', array('_locale' => null), true) == $url_referer
33
+    )
34
+    {
35
+      // On construit l'url
36
+      $url = $this->generateUrl('index', array('_locale' => $language));
37
+    }
38
+    else
39
+    {
40
+      // Sinon on retourne sur l'url précédent en modifiant la langue
41
+      $url = str_replace("/$old", "/$language", 
42
+        $this->container->get('request')->headers->get('referer'));
43
+    }
44
+    
45
+    return new RedirectResponse($url);
46
+  }
47
+  
17 48
   /**
18 49
    * 
19 50
    * @param string $type

+ 0 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml View File

@@ -11,4 +11,3 @@ follow:
11 11
 element_add:
12 12
   pattern:  /element/add
13 13
   defaults: { _controller: MuzichCoreBundle:Core:elementAdd }
14
-  

+ 9 - 5
src/Muzich/CoreBundle/Resources/config/security.yml View File

@@ -9,11 +9,12 @@ security:
9 9
             pattern:      ^/
10 10
             form_login:
11 11
                 provider:       fos_userbundle
12
-                login_path:     /hello
12
+                login_path:     index
13 13
                 use_forward:    false
14 14
                 check_path:     /login_check
15 15
                 failure_path:   null
16
-                default_target_path: /hello
16
+                default_target_path: home
17
+                
17 18
             logout:
18 19
                 path:   /logout
19 20
                 target: /hello
@@ -27,9 +28,11 @@ security:
27 28
         
28 29
     ## La en tant qu'exemple, exploiter ça (http://j-place.developpez.com/tutoriels/php/ameliorez-vos-applications-developpees-avec-symfony2/#LVI-A-3)
29 30
     access_control:
30
-        - { path: ^/hello, roles: IS_AUTHENTICATED_ANONYMOUSLY }
31
+        - { path: "^/hello", roles: IS_AUTHENTICATED_ANONYMOUSLY }
32
+        - { path: "^/hello/(?:fr|en)", roles: IS_AUTHENTICATED_ANONYMOUSLY }
31 33
         - { path: ^/(?:fr|en)/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
32 34
         - { path: "^/(?:fr|en)/resetting", roles: IS_AUTHENTICATED_ANONYMOUSLY }
35
+        - { path: "^/change-language/(?:fr|en)", roles: IS_AUTHENTICATED_ANONYMOUSLY }
33 36
         
34 37
         
35 38
         - { path: ^/_wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY }
@@ -38,10 +41,11 @@ security:
38 41
         - { path: ^/css/, role: IS_AUTHENTICATED_ANONYMOUSLY }
39 42
         - { path: ^/bundles/, role: IS_AUTHENTICATED_ANONYMOUSLY }
40 43
         
44
+        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
45
+        - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
46
+        
41 47
         - { path: ^/, roles: ROLE_USER }
42 48
 #        # Liste des pages accessibles à tous les utilisateurs (ne pas toucher)
43
-#        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
44
-#        - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
45 49
 #        - { path: ^/register$, role: IS_AUTHENTICATED_ANONYMOUSLY }
46 50
 #        
47 51
 #        # PAGES ACCESSIBLES AUX ADMINISTRATEURS

+ 4 - 0
src/Muzich/CoreBundle/Resources/views/Language/languages.html.twig View File

@@ -0,0 +1,4 @@
1
+<div id="choose_language">
2
+  <a href="{{ path('change_language', {'language' : 'fr'}) }}">fr</a> |
3
+  <a href="{{ path('change_language', {'language' : 'en'}) }}">en</a>
4
+</div>

+ 2 - 1
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

@@ -22,7 +22,8 @@
22 22
 </head>
23 23
 <body>
24 24
   
25
-	
25
+  {% include "MuzichCoreBundle:Language:languages.html.twig" %}
26
+  
26 27
   {% include "MuzichUserBundle:Account:topBar.html.twig" %}
27 28
   
28 29
   <div id="container">

+ 6 - 6
src/Muzich/HomeBundle/Resources/config/routing.yml View File

@@ -1,13 +1,13 @@
1 1
 ## Routing du Bundle
2 2
 
3 3
 home:
4
-  pattern:  /
5
-  defaults: { _controller: MuzichHomeBundle:Home:index }
4
+  pattern:  /{_locale}
5
+  defaults: { _controller: MuzichHomeBundle:Home:index, _locale: fr }
6 6
   
7 7
 show_user:
8
-  pattern: /user/{slug}
9
-  defaults: { _controller: MuzichHomeBundle:Show:showUser }
8
+  pattern: /{_locale}/user/{slug}
9
+  defaults: { _controller: MuzichHomeBundle:Show:showUser, _locale: fr }
10 10
   
11 11
 show_group:
12
-  pattern: /group/{slug}
13
-  defaults: { _controller: MuzichHomeBundle:Show:showGroup }
12
+  pattern: /{_locale}/group/{slug}
13
+  defaults: { _controller: MuzichHomeBundle:Show:showGroup, _locale: fr }

+ 1 - 16
src/Muzich/IndexBundle/Controller/IndexController.php View File

@@ -2,15 +2,11 @@
2 2
 
3 3
 namespace Muzich\IndexBundle\Controller;
4 4
 
5
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 5
 use Muzich\CoreBundle\lib\Controller;
7 6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8 7
 use Symfony\Component\Security\Core\SecurityContext;
9
-use Symfony\Component\Security\Core\Exception\AuthenticationException;
10 8
 
11
-use Muzich\CoreBundle\Entity\Tag;
12
-use Muzich\CoreBundle\Entity\UsersTagsFavorites;
13
-use Muzich\CoreBundle\Entity\User;
9
+use Symfony\Component\HttpFoundation\RedirectResponse;
14 10
 
15 11
 class IndexController extends Controller
16 12
 {
@@ -22,7 +18,6 @@ class IndexController extends Controller
22 18
   public function indexAction()
23 19
   {
24 20
     $vars = $this->proceedLogin();
25
-    
26 21
     $form = $this->container->get('fos_user.registration.form');
27 22
     
28 23
     return array_merge($vars, array(
@@ -65,14 +60,4 @@ class IndexController extends Controller
65 60
     );
66 61
   }
67 62
   
68
-  /**
69
-   * Gestion du formulaire d'inscription sur la page d'index.
70
-   * 
71
-   * @return type array
72
-   */
73
-  public function proceedRegister()
74
-  {
75
-    
76
-  }
77
-  
78 63
 }

+ 2 - 2
src/Muzich/IndexBundle/Resources/config/routing.yml View File

@@ -1,8 +1,8 @@
1 1
 ## Routing du Bundle Index
2 2
 
3 3
 index:
4
-    pattern:  /hello
5
-    defaults: { _controller: MuzichIndexBundle:Index:index }
4
+    pattern:  /hello/{_locale}
5
+    defaults: { _controller: MuzichIndexBundle:Index:index, _locale: fr }
6 6
 
7 7
 fos_user_security:
8 8
     resource: "@FOSUserBundle/Resources/config/routing/security.xml"

+ 13 - 1
web/bundles/muzichcore/css/main.css View File

@@ -251,4 +251,16 @@ ul.inline li
251 251
     }
252 252
 }
253 253
 
254
-/* Message flash end */
254
+/* Message flash end */
255
+
256
+#choose_language
257
+{
258
+  float: right;
259
+  margin-right: 5px;
260
+}
261
+
262
+#choose_language a
263
+{
264
+  text-decoration: none;
265
+  color: black;
266
+}