Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yigitozmen's avatar

changing language with mcamara/laravel-localization

I'm adding language support to the website. And i remove language prefix for default locale. Now i added a selectbox to select preferred language. But LaravelLocalization::setLocale('lang') not working?

For example in the route file; Route::('/test', function(){ return LaravelLocalization::setLocale('en'); });

it prints 'en' to the screen but it doesnt set in session.

So if i have a url with querystring how can i change language?

0 likes
1 reply
pariamonia's avatar

In my opinion, (how I do it in my project) you need: when you change the language in controller

 App::setLocale($lang);
 Session::put('locale', $lang);
 \LaravelLocalization::setLocale($lang);
 $url = \LaravelLocalization::getLocalizedURL(App::getLocale(), \URL::previous());
return Redirect::to($url);
1 like

Please or to participate in this conversation.