Created
April 11, 2015 04:11
-
-
Save iamshanto/c3371f7cd2a6e83e777d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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