I'm trying to make multi languages site with symfony 2, the question now is how to make $request->setLocale()
applicable on all pages or methods.For the moment I needed in every method to call $request->setLocale($newlanguage);
public function methodAAction()
{
...
$request->setLocale($new_language);
return $this->render('x');
}
public function methodBAction()
{
...
$request->setLocale($new_language);
return $this->render('y');
}
Is there any way to make it Global , I mean to call it only one time for all pages
You can do this with a listener which sets the locale for every request. See my answer on another question for some good code. Only the setLocaleForUnauthenticatedUser
is necessary for your problem.