-
-
Save dhayab/5715152 to your computer and use it in GitHub Desktop.
Get language prefixing in URLs from Laravel 3 back into Laravel 4.
This file contains 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 | |
/* | |
* Multilingual URLs in Laravel 4 | |
*/ | |
//config/app.php | |
return array( | |
... | |
'languages' => array('en', 'gr'), | |
... | |
); | |
// filters.php | |
App::before(function($request) | |
{ | |
$uri = $request->server->get('REQUEST_URI'); | |
if ( in_array(Request::segment(1), Config::get('app.languages')) ) { | |
Session::put('locale', Request::segment(1)); | |
return Redirect::to(substr(Request::path(), 3)); | |
} | |
if ( Session::has('locale') ) { | |
App::setLocale(Session::get('locale')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment