niels-numbers/laravel-localizer

Detects the user’s preferred language and redirects to the matching localized URL.
16,284 32
Install
composer require niels-numbers/laravel-localizer
Latest Version:v1.4.0
PHP:^8.2
License:MIT
Last Updated:Sep 9, 2026
Links: GitHub  ·  Packagist
Maintainer: niels-numbers

Laravel Localizer

Tests PHP Laravel License

Laravel can already prefix routes with /{locale}. What it does not do: detect a visitor's language, redirect them there, remember the choice, and keep route('about') returning the right URL. This package adds exactly that.

Documentation: localizer.adam-nielsen.de

Successor to mcamara/laravel-localization. Coming from there? See the migration guide.

What you get

Wrap your routes once:

Route::localize(function () {
    Route::get('/about', AboutController::class)->name('about');
});

The page is now reachable in every configured language:

URL Language
/about en (default, prefix hidden)
/de/about de
/fr/about fr

The default language has no prefix because hide_default_locale is on by default. Turn it off and every URL carries a prefix: /about then redirects to /en/about.

route('about') keeps working as before and returns the URL for the current language: in Blade, controllers, jobs, mails and, with the JavaScript route helpers, in your Vue or React frontend.

Want /de/ueber and /fr/a-propos instead of /de/about? See Translated URL Paths.

What happens on a visit

  1. First visit: someone opens /about. The package reads their browser language (or your own detectors) and redirects them, for example to /de/about. English visitors stay on /about.
  2. From then on the URL decides: /de/about shows German and remembers it in session and cookie. A link to plain /about sends that visitor back to /de/about.
  3. One canonical URL per page: the default language has no prefix, so /en/about redirects to /about.

A language switcher is one helper call per language: Route::localizedSwitcherUrl('fr'). See Language Switcher.

Install

composer require niels-numbers/laravel-localizer

Then set your locales, register two middlewares and wrap your routes. The setup guide walks through the three steps.

Coming from mcamara/laravel-localization?

Same job, different wiring. Every localized route is a plain, static Laravel route, so php artisan route:cache works, translated routes switch reliably and Livewire works out of the box. The migration guide covers the differences step by step.

Not sure you need this package at all? See when to use it and how it compares to mcamara/laravel-localization, codezero-be/laravel-localized-routes and spatie/laravel-translatable.

License & credits

MIT licensed. Created by Adam Nielsen, building on prior work by @mcamara (original laravel-localization), @codezero-be (deprecated laravel-localized-routes, whose static-route ideas inspired this rewrite) and @jordyvanderhaegen (current maintainer of the original, whose issue #921 motivated this package).

Related Packages

tool-mountain/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

1,900 0
codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

679,522 545
opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

141,452 29
codezero/laravel-uri-translator

Translate a URI or individual slugs.

379,469 6
codezero/laravel-localizer

Automatically detect and set an app locale that matches your visitor's preferenc...

413,585 50