Skip to content

Instantly share code, notes, and snippets.

@iamshanto
Created April 11, 2015 04:11
Show Gist options
  • Select an option

  • Save iamshanto/c3371f7cd2a6e83e777d to your computer and use it in GitHub Desktop.

Select an option

Save iamshanto/c3371f7cd2a6e83e777d to your computer and use it in GitHub Desktop.
<?php
namespace Emicro\Bundle\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class LanguageSwitcherController extends Controller
{
public function switchAction(Request $request)
{
$currentLocale = $this->get('translator')->getLocale();
$prevLocale = ($currentLocale == 'en') ? 'fr' : 'en';
if ($refer = $request->headers->get('referer')) {
$url = str_replace("/{$prevLocale}/", "/{$currentLocale}/", $refer);
} else {
$url = $this->generateUrl('unit');
}
return $this->redirect($url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment