niels-numbers/laravel-localizer
| 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 |
Laravel Localizer
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
- 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. - From then on the URL decides:
/de/aboutshows German and remembers it in session and cookie. A link to plain/aboutsends that visitor back to/de/about. - One canonical URL per page: the default language has no prefix,
so
/en/aboutredirects 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
A convenient way to set up, manage and use localized routes in a Laravel app.
A convenient way to set up, manage and use localized routes in a Laravel app.
A convenient way to set up, manage and use localized routes in a Laravel app.