niels-numbers / laravel-localizer
Detects the user’s preferred language and redirects to the matching localized URL.
Package info
github.com/niels-numbers/laravel-localizer
pkg:composer/niels-numbers/laravel-localizer
Requires
- php: ^8.2
- codezero/browser-locale: ^3.0
- illuminate/support: ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0
Requires (Dev)
- mockery/mockery: ^1.3.3
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^9.6 || ^10.1 || ^11.0 || ^12.0 || ^13.0
Suggests
- tighten/ziggy: Use Ziggy v2+ as your client-side route helper. Bind \Tighten\Ziggy\Ziggy::class to NielsNumbers\LaravelLocalizer\Routing\LocalizerZiggyV2::class to make route() locale-aware in JS.
- tightenco/ziggy: Use Ziggy v1 as your client-side route helper. Bind \Tightenco\Ziggy\BladeRouteGenerator::class to NielsNumbers\LaravelLocalizer\Routing\LocalizerBladeRouteGeneratorV1::class to make route() locale-aware in JS.
README
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
Example
Route::localize(function () { Route::get('/about', AboutController::class)->name('about'); });
Produces:
/aboutfor the default locale (e.g. English), prefix hidden/de/about,/fr/about, ... for every other configured locale
In your application code, keep using route('about'); the package
picks the right variant based on the current locale.
Install
composer require niels-numbers/laravel-localizer
Setup guide · Migrating from mcamara/laravel-localization?
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).