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

georgeboot's avatar

L5 localisation routing

I need localisation in my app. The way I prefer is that the first segment in the URL contains the current language. For example: /en/blog, /nl/blog, etc.

Laravel supports localisation and I'm using this to translate my static strings. However, I can't get a proper setup working for my routes.

I found https://github.com/mcamara/laravel-localization but that immediately a huge package (and still makes things complicated). All I want are some simple routes that do the following:

  • Add a localised version of every page. Eg: /en/blog, /nl/blog
  • redirect routes without locale to the default locale (/blog to /en/blog)

What I currently have:

// routes.php
Route::group(['middleware' => ['web']], function () {
    Route::group(['prefix' => '{locale}'], function($locale) {
        Route::get('', function () {
            return view('welcome');
        });
        Route::auth();
        Route::get('home', 'HomeController@index');
        Route::resource('blog', 'BlogController', ['only' => ['index', 'show']]);
    });
});

This however produces routes with incorrect names: {locale}.blog.index. This means generating routes with route('blog.index') doesn't work. Also, this approach forces me to add the $locale parameter to every controller method.

Can someone share some thoughts how to get this working nice and easy? Thank you!

0 likes
1 reply
igorblumberg's avatar

Hello @georgeboot , I've been using mcamara/laravel-localization package for a while and it was quite easy:

Route::group(['middleware' => ['web']], function () {
    Route::group(['prefix' => LaravelLocalization::setLocale(),'middleware'=>"localizationRedirect"], function() {
        //routes here
    });
});

I didn't need to change any thing in my controllers, and I kept using laravel's default localization for static strings.

From there you could move to translate the entire route (/home for en and /inicio for pt) but that's up to you, the package has a lot of features, but the basic is really easy.

good luck!

Please or to participate in this conversation.