Created
January 18, 2013 07:40
-
-
Save jacekd/4562959 to your computer and use it in GitHub Desktop.
Multilingual URLs in 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'); | |
foreach(Config::get('app.languages') as $language){ | |
if(preg_match('/^\/'.$language.'(\/|\z|\?.*|#(.*))/', $uri)){ | |
Config::set('app.locale', $language); | |
$newUri = '/'.substr($uri, 3); | |
$request->server->set('REQUEST_URI', $newUri); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe
App::before
can be replaced by this codeIn my case, I wanted to keep the language in URL.