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.
Route::translate() now mandates named routes, aligning with Laravel’s best practices for route resolution and localization. This ensures consistency in locale switching (e.g., Route::localizedUrl()) and prevents runtime failures by failing fast at registration.Route::localize() without explicit names remain unnamed, mirroring Laravel’s default behavior. This avoids unintended name collisions (e.g., with_locale. prefix) and clarifies that such routes are URL-accessible but not locale-switchable.Route::localizedUrl() helper now has a guaranteed contract (all translated routes are named), improving reliability for client-side navigation (e.g., Ziggy/Inertia).->name() for all routes inside Route::translate(), which may necessitate updates to existing route definitions. This is a breaking change but enforces better practices.Route::localize() without names are now explicitly unnamed, reducing ambiguity in route resolution. This aligns with Laravel’s default behavior and avoids silent name collisions.spatie/laravel-typescript-transformer support (due to generator limitations) narrows frontend compatibility but clarifies that Ziggy remains the recommended solution for client-side locale-aware routing.Route::localize() usage without ->name() continues to work but with adjusted behavior (unnamed routes stay unnamed). This may require testing for apps relying on implicit naming.Route::translate() will fail at boot, requiring proactive updates. This reduces runtime errors but increases migration effort.Route::localize() without names are now truly unnamed (not auto-named), which may break apps expecting them to be resolvable by name. Test route('with_locale.')-style lookups.spatie/laravel-typescript-transformer removed, Ziggy becomes the sole recommended JS adapter. Apps using the transformer will need to migrate to Ziggy or Wayfinder for static route generation.RedirectLocale triggers).route:cache remains intact, but cached routes must now adhere to the naming rules. Test cached route regeneration post-migration.Route::translate() without explicit names? How many need updates?with_locale.) for route resolution?route('with_locale.')-style lookups for unnamed routes?Route::has() or Route::named() checks that may now fail?spatie/laravel-typescript-transformer used for static route generation? If so, what’s the migration path to Ziggy/Wayfinder?Route::localizedUrl()?Route::localize() (e.g., fallback routes)?spatie/laravel-typescript-transformer support removal (if any)? Are there alternatives like Wayfinder?LocalizerBladeRouteGeneratorV2.spatie/laravel-typescript-transformer. Wayfinder uses route names (not controller methods), making it compatible with Route::localize().SetLocale/RedirectLocale pipeline remains unchanged.route:cache. Cached routes must now adhere to naming rules.->name() to all routes inside Route::translate():
Route::translate(function () {
Route::get('/about', [AboutController::class, 'index'])->name('about'); // Now required
Route::get('/contact', [ContactController::class, 'index'])->name('contact');
});
Route::localize(), unnamed routes will no longer auto-generate names. Update references to route('with_locale.') if used.spatie/laravel-typescript-transformer with Wayfinder for static route generation:
composer require wayfinderjs/wayfinder
Configure Wayfinder to use route names (not controller methods) in wayfinder.php:
'route_resolver' => \Wayfinder\RouteResolver::class,
'route_name_resolver' => \Wayfinder\RouteNameResolver::class, // Use names, not controllers
Route::localizedUrl().Route::localize() to ensure they remain URL-accessible but not locale-switchable.SetLocale and RedirectLocale are correctly ordered in app/Http/Kernel.php.php artisan route:cache) after updates.Route::translate(); optional (but discouraged) for Route::localize().LocalizerBladeRouteGeneratorV2 binding.spatie/laravel-typescript-transformer).@route and @routes work with named routes. Unnamed routes in Route::localize() are not resolvable by name.Route::translate() routes for naming updates.Route::localize() for unnamed routes and update references.spatie/laravel-typescript-transformer with Wayfinder before updating route helpers.route:cache) post-migration.localizer.detectors and localizer.locale_directions.UnnamedTranslatedRouteException provides clear error messages for missing route names.Localizer::currentLocale(), Localizer::baseName()) remain useful for debugging.RedirectLocale) can be enabled for troubleshooting redirects.Route::translate() naming requirements and Wayfinder integration.spatie/laravel-typescript-transformer → Wayfinder.Route::localize().spatie/laravel-typescript-transformer support isHow can I help you explore Laravel packages today?