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

hsntngr's avatar

Laravel localization-translation doesn't work, shows only default language

I'm trying to build multilingual website with laravel but there is a problem with translation. It shows only default language. Even if I set the app locale language, laravel continue to shows default language

when I said app.test/ar/admin or `app.test/en/admin, routes and others works as well, I can reach the view, just trans message not work..

admin blade

<div class="row">
   <h1>{{trans('admin.welcome')}}</h1>
</div>

I tried with __('admin.welcome') but still same result..

app service provider;

public function boot(Request $request)
    {
        if (!session()->has("locale")) {
            session()->put("locale", $request->getPreferredLanguage(config("translatable.locales")));
        }
        app()->setLocale(session()->get("locale"));
    }

route service provider

 Route::group([
            'middleware' => 'web',
            'namespace' => $this->namespace,
            'prefix' => session()->get("locale"),
        ], function ($router) {...});

language middleware

public function handle(Request $request, Closure $next)
    {
        if (!in_array($request->segment(1), config('translatable.locales'))) {
            $segments = $request->segments();
            $segments = array_prepend($segments, app()->getLocale());
            return redirect()->to(implode('/', $segments));
        }

        return $next($request);
    }

so how can I fix this ? Any help would be appreciated.

0 likes
1 reply
aurawindsurfing's avatar

Hi,

Install debugbar and check what locale you actually have when you are trying to display a different one.

I also had to do similar thing recently and ended up using this combination:

"arcanedev/localization": "^3.0",
"cviebrock/eloquent-sluggable": "^4.5",
"mariuzzo/laravel-js-localization": "^1.4",

Hope it helps!

Please or to participate in this conversation.