niels-numbers/laravel-localizer
Locale-aware routing for Laravel with static, route:cache-ready localized routes. Auto-detects language, redirects to prefixed URLs, and resolves route() to the correct locale. Successor to mcamara/laravel-localization.
Successor to
mcamara/laravel-localization. Static routes,route:cacheready.
Locale-aware routing for Laravel: auto-detect, auto-redirect, and resolve route() per language.
Documentation: localizer.adam-nielsen.de
Route::localize(function () {
Route::get('/about', AboutController::class)->name('about');
});
Produces:
/about - this endpoint carries the package's core magic: auto-detection, redirect, or default locale (see below)/de/about, /fr/about, ... for every other configured localeEvery route is registered twice as a static route:
GET|HEAD about ............... without_locale.about › AboutController
GET|HEAD {locale}/about .......... with_locale.about › AboutController
In your application code, keep using route('about'); the package
picks the right variant based on the current locale.
How /about resolves at request time:
Accept-Language header
(or your own detector chain) and redirects to the matching
localized URL.hide_default_locale is on -
in which case they are redirected or stay on /about.Note: a switcher link to plain
/aboutcarries no locale signal -RedirectLocalewould send the user back to their session locale instead of switching. See Language Switcher for more.
composer require niels-numbers/laravel-localizer
Setup guide · Migrating from mcamara/laravel-localization?
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).
How can I help you explore Laravel packages today?