Skip to content

Instantly share code, notes, and snippets.

@dhayab
Forked from jacekd/gist:4562959
Last active December 18, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhayab/5715152 to your computer and use it in GitHub Desktop.
Save dhayab/5715152 to your computer and use it in GitHub Desktop.
Get language prefixing in URLs from Laravel 3 back into Laravel 4.
<?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