Symfony2 default locale in routing

前端 未结 12 2290
猫巷女王i
猫巷女王i 2020-12-01 04:41

I have a problem with routing and the internationalization of my site built with Symfony2.
If I define routes in the routing.yml file, like this:

exampl         


        
12条回答
  •  一个人的身影
    2020-12-01 04:59

    There is my Solution, it makes this process faster!

    Controller:

    /**
     * @Route("/change/locale/{current}/{locale}/", name="locale_change")
     */
    public function setLocaleAction($current, $locale)
    {
        $this->get('request')->setLocale($locale);
        $referer = str_replace($current,$locale,$this->getRequest()->headers->get('referer'));
    
        return $this->redirect($referer);
    }
    

    Twig:

  • {{ language.locale }}
提交回复
热议问题