php - Laravel URL Language Prefix -
php - Laravel URL Language Prefix -
i trying set 2 languages site. have read around (http://forumsarchive.laravel.io/viewtopic.php?id=7458, http://laravel.io/forum/02-20-2014-how-to-make-switching-language-button) , can't seem prefix part of working.
the default language if set or selected:
/news
if chinese selected:
/zh/news
my filters.php:
app::before(function($request) { // default browser language $language = substr($request->server->get('http_accept_language'), 0, 2); // language set route if (null !== $request->segment(1)) { $routelanguage = $request->segment(1); if (in_array($routelanguage, config::get('app.languages'))) { $language = $routelanguage; } } //return $language; // set language config::set('app.locale', $language); app::setlocale($language); });
the language selector:
class languagecontroller extends basecontroller { public function select($lang) { session::put('lang', $lang); homecoming redirect::route('home'); } }
and routes.php:
route::get('/', array('uses' => 'homecontroller@home', 'as' => 'home')); route::get('language/{lang}', array( 'as' => 'language.select', 'uses' => 'languagecontroller@select' ) );
my 2 language links setting variable correctly, don't know how finish off way want (i want language slug in url seo reasons).
how can accomplish this?
php laravel laravel-4 laravel-routing
Comments
Post a Comment