Browse Source

Mise en place des lien permettant de changer le laguage.

bastien 13 years ago
parent
commit
1053c22ad3

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

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

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

10
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
10
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
11
 use Muzich\CoreBundle\ElementFactory\ElementManager;
11
 use Muzich\CoreBundle\ElementFactory\ElementManager;
12
 use Muzich\CoreBundle\Entity\Element;
12
 use Muzich\CoreBundle\Entity\Element;
13
+use Symfony\Component\HttpFoundation\RedirectResponse;
13
 
14
 
14
 class CoreController extends Controller
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
    * @param string $type
50
    * @param string $type

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

11
 element_add:
11
 element_add:
12
   pattern:  /element/add
12
   pattern:  /element/add
13
   defaults: { _controller: MuzichCoreBundle:Core:elementAdd }
13
   defaults: { _controller: MuzichCoreBundle:Core:elementAdd }
14
-  

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

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

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

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

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

1
 ## Routing du Bundle
1
 ## Routing du Bundle
2
 
2
 
3
 home:
3
 home:
4
-  pattern:  /
5
-  defaults: { _controller: MuzichHomeBundle:Home:index }
4
+  pattern:  /{_locale}
5
+  defaults: { _controller: MuzichHomeBundle:Home:index, _locale: fr }
6
   
6
   
7
 show_user:
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
 show_group:
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
 
2
 
3
 namespace Muzich\IndexBundle\Controller;
3
 namespace Muzich\IndexBundle\Controller;
4
 
4
 
5
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
 use Muzich\CoreBundle\lib\Controller;
5
 use Muzich\CoreBundle\lib\Controller;
7
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
8
 use Symfony\Component\Security\Core\SecurityContext;
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
 class IndexController extends Controller
11
 class IndexController extends Controller
16
 {
12
 {
22
   public function indexAction()
18
   public function indexAction()
23
   {
19
   {
24
     $vars = $this->proceedLogin();
20
     $vars = $this->proceedLogin();
25
-    
26
     $form = $this->container->get('fos_user.registration.form');
21
     $form = $this->container->get('fos_user.registration.form');
27
     
22
     
28
     return array_merge($vars, array(
23
     return array_merge($vars, array(
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
 ## Routing du Bundle Index
1
 ## Routing du Bundle Index
2
 
2
 
3
 index:
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
 fos_user_security:
7
 fos_user_security:
8
     resource: "@FOSUserBundle/Resources/config/routing/security.xml"
8
     resource: "@FOSUserBundle/Resources/config/routing/security.xml"

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

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