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

arpero's avatar

Language switch not working when installed on shared hosting server

Hi everyone,

I have made a website in Laravel, a multilingual website, so far English and French. To change the language there is a route declared Route::get('home/lang/{any}','HomeController@getLang');

Then in the HomeController public function getLang (Request $request , $lang) {$request->session()->put('lang', $lang); return Redirect::back(); }

In the index function of the same controller it is:

public function index (Request $request) { \App::setLocale(\Session::get('lang')); }

With this code Laravel is able to translate the strings. It works like a charm in my local PC, but when I install in a shared hosting server (in my case, Hostgator), it doesn't work. When I click on the webpage to switch to another language, it's just refreshing the page and the same original language shows. Why does this happen? What do I have to do for this to work in a shared hosting? Is that a kind of protection Laravel has?

For more details, session seems to be working OK, I print before executing the Lang::get in the views \Log::info("Get Locale in Home page: ".\App::getLocale()); and it prints correctly to the language that I have just switched to, b but then the {!! Lang::get('xxx') !!} doesn't work, nor the {{ trans('xxx') }} Languages files are well placed and everything works locally, but not in the shared hosting server. So it is the Lang::get that doesn't get the appropiate language.

Any help will be welcomed, Ariel

0 likes
5 replies
arpero's avatar

Thanks Guybrush for the quick answer. Finally I figured it out!!! I had to convert to lowercase the session variable used for the language, so \App::setLocale(strtolower(\Session::get('lang'))); dit it!! It should be the Linux case-sensitive nature.

3 likes
arpero's avatar

By the way, nice nick from the hero of Monkey Island!! :-)

1 like
Pelargir's avatar

@arpero My friend. I really, really thank you. When I saw your answer, I held my breath and immediately applied it. My heart was about to jump out of my chest before I refreshed the page. It really worked and my problem was solved. The fact that it was such a simple solution made me crazy. I've been looking for a solution for about a week, I don't know how many times I deleted and installed it. Thank you so much. The best code is with you. ♥

Please or to participate in this conversation.