I looked more thoroughly onto the code today, because I was experiencing the same problem as you, and it appears that the language comes from Session::getLocale()
. But Symfony2 never calls Session::setLocale()
, and sets the locale
member of the Session
object. A google search for "symfony2 session setlocale" leads to this § of the documentation
So I ended up putting this line on top of the controller I was working on, and it worked :
$this->getRequest()->getSession()->setLocale(
$this->getRequest()->getPreferredLanguage());
Now I guess this is not acceptable, because you're not going to add this on top of each and every controller. Plus, this should not be done for every request, it should only be done for the first one, when the user has no session yet. If anyone knows how to do this feel free to edit this answer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…