I tried routing to switch language but there's no change. Could you help me, pls?
Route::get('lang/{lang}', function($lang)
{
App::setLocale($lang);
return Redirect::to('/');
});
Join Stack Overflow to learn, share knowledge, and build your career.
I tried routing to switch language but there's no change. Could you help me, pls?
Route::get('lang/{lang}', function($lang)
{
App::setLocale($lang);
return Redirect::to('/');
});
App::setLocale()
is not persistent - that is to say that it will not remember between requests what you have stored. Instead you could use the session to remember the chosen locale, and read from the session the locale on each request. We can also read the default locale (from config) in case there isn't one set in the session.
// app/routes.php
Route::get('lang/{lang}', function($lang)
{
Session::put('my.locale', $lang);
return Redirect::to('/');
});
// app/start/global.php
App::setLocale(Session::get('my.locale', Config::get('app.locale')));
Cookie::forever
and Cookie::get
but it doesn't work. With sessions it works, as you showed. I have tried printing the cookie but it's empty. Printing the session works though. The code is similar in both cases, I have only changed it to use cookies instead of sessions.
– MikkoP
Jan 25 '14 at 16:35
I solved the problem by putting
App::setLocale(Session::get('lang', 'en'));
in app/start/global.php