Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

mcamara/laravel-localization

Premium
7 min read

We've covered the core string Localization, but there are more aspects that we can translate. For example, routes:

Take a look at the URL bar

In the images, you should see that the routes are translated as well. This is done by the mcamara/laravel-localization package.

This package helps you manage your routes in multiple languages. It also provides a great set of middlewares and helpers to help you with translations - such as detecting the user's language and redirecting them to the correct route, translating routes, etc...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

V
Velkacem ✓ Link copied!

It's a great Package!

E
elijah ✓ Link copied!

Thanks a lot for clarification! I was strugling trying to make this package worked for some time, this article really helped.

AM
Alain Martini ✓ Link copied!

using the mcamara/laravellocalisation package I ran into a problem with livewire: calls to livewire/update on a language other than the default language were being sent in 404.

I analysed the code there livewire and saw that what failed was Livewire\Mechanisms\PersistentMiddleware\PersistentMiddleware::getRouteFromRequest($request) linking routes with

$route = app('router')->getRoutes()->match($request);

failing this request returns 404.

To solve i ended prepending to /livewire/update the current locale so livewire can find its endpoint


// App\Providers\RouteServiceProvider.php

use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Livewire\Livewire;

//...
public function boot()
{
    Livewire::setUpdateRoute(function ($handle) {
        return Route::post('/livewire/update', $handle)
            ->middleware('web')
            ->prefix(LaravelLocalization::setLocale());
    });

    // ...
}

SJ
Sergio Jardim ✓ Link copied!

This is very helpful! Fixed the error for me on my search component. Many thanks! But in Laravel 11, you need to add this method to the boot method of the App/Providers/AppServiceProvider.php file instead, as there is no App\Providers\RouteServiceProvider.php file anymore.

AM
Alain Martini ✓ Link copied!

Thank you for the info, i have to migrate from 10 to 11 and your suggestion is really useful :)