How to redirect to same page when change the user culture
On symfony 1.2.8 i m stuck to redirect to same page when change the user culture. that mean if user change the culture from the some action its should go back to the same action instead of going to the index
page i found a similer question on SF but its also going to the index page
Language switcher开发者_StackOverflow, redirect to current page with symfony
EDIT problem is my request coming from out of the symfony actually from another index file so i cant use $this->redirect($request->getReferer());
The easiest way is to redirect to referer.
//actions
$this->redirect($request->getReferer());
You can also append current page url as a parameter to user culture change url.
I took this tutorial (jobeet about i18n) and modified the executeChangeLanguage
function like this:
public function executeChangeLanguage(sfWebRequest $request)
{
$form = new sfFormLanguage(
$this->getUser(),
array('languages' => array('en', 'fr'))
);
$form->process($request);
// added
$url = $request->getReferer();
$newUrl = $url;
if ($request->getParameter('language') == 'fr') {
$newUrl = str_replace('.com/en', '.com/fr', $url);
}
if ($request->getParameter('language') == 'en') {
$newUrl = str_replace('.com/fr', '.com/en', $url);
}
return $this->redirect($newUrl);
// old return
// return $this->redirect('localized_homepage');
}
This is dirty hack, but it worked for me.
精彩评论