Thank you very much.
Next step: translate the routes :)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
The following will make domain.com/{locale} available to your website.
What you need to use multiple locales is three things.
Open up config/app.php and add the following below 'locale' => 'xx'.
'locales' => ['en' => 'English', 'sv' => 'Swedish'],
Modify this array with your desired locales.
To prefix our routes, we change the map method in app/Providers/RouteServiceProvider.php. Change the map method to the following:
public function map(Router $router, Request $request)
{
$locale = $request->segment(1);
$this->app->setLocale($locale);
$router->group(['namespace' => $this->namespace, 'prefix' => $locale], function($router) {
require app_path('Http/routes.php');
});
}
Then add this to the top of the file:
use Illuminate\Routing\Router;
use Illuminate\Http\Request;
Now create a file named Language.php in app/Http/Middleware with this content:
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Redirector;
use Illuminate\Http\Request;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Routing\Middleware;
class Language implements Middleware {
public function __construct(Application $app, Redirector $redirector, Request $request) {
$this->app = $app;
$this->redirector = $redirector;
$this->request = $request;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Make sure current locale exists.
$locale = $request->segment(1);
if ( ! array_key_exists($locale, $this->app->config->get('app.locales'))) {
$segments = $request->segments();
$segments[0] = $this->app->config->get('app.fallback_locale');
return $this->redirector->to(implode('/', $segments));
}
$this->app->setLocale($locale);
return $next($request);
}
}
Now make that middleware run on all requests by adding it to the $middleware property in app/Http/Kernel.php. It is recommended to add it to the top of the array.
protected $middleware = [
'App\Http\Middleware\Language',
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
];
You are now set to go.
I have an example repository available at https://github.com/Marwelln/laravel-multiple-locales – clone it to test it out or if you are unsure how it works.
Please or to participate in this conversation.