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

devionti's avatar

Localization Issues

I have a dual lingo website and I have a file in lang en for English and another folder for another language The English version works. Because in the view there is no English version its replaced with the arabic version in the ar folder. Basically from the header once you click the menu option of the other language then it should switch language. I just don't understand why it refuses to switch. Even if I change default locale to ar it still only reads en folder.

home.blade.php

      {{__('home.thank.you')}}

lang/en/home.php

"thank.you" => "Thank You",

lang/ar/home.php

"thank.you" => "شكرا",

web.php

Route::get('/',['as' => 'site.home', 'uses' => 'BlogController@index'] ,function () {
    if(Session::get('locale') == null){
        Session::put('locale', 'en');
    }
    return view('pages.home');
});

BlogController.php

    public function index()
    {
        if(Session::get('locale') == null)
        {
            Session::put('locale', 'en');
        }

header.blade.php

                            <div class="dropdown">
                                    <button class="fa fa-language"></button>
                                    <div class="dropdown-content">
                                            <a class="social-ln" href="locale/en" data-request="onSwitchLocale"
                                            data-request-data="locale: 'en'">English</a>
                                            <a class="social-ln" href="locale/ar" data-request="onSwitchLocale"
                                                    data-request-data="locale: 'ar'">عربى</a>
                                    </div>
                                  </div>
0 likes
3 replies
devionti's avatar

I have two versions of the same project. One in laravel 6 and the other in laravel 7. In web.php and controller everything is the same. I compared both. I just don't know what is missing.

damarawy's avatar

Hi devionti, Why don't you use app()->getLocale() & app()->setLocale('ar') instead of using sessions?

PS: Locale is set by default to 'en', you can add a middleware to handle setting the locale

Please or to participate in this conversation.