chinleung/laravel-multilingual-routes
Register multilingual Laravel routes from a single definition. Automatically generates locale-prefixed URLs based on configured locales, with optional default-locale prefixing. Includes middleware to detect request locale and switch the app locale accordingly.
Pros:
Route::multilingual(), Route::multilingualResource()), reducing cognitive load for developers familiar with the framework.resources/lang/{locale}/routes.php. This decouples route definitions from locale-specific paths.resource() method to handle multilingual routes, including nested resources, constraints, and soft deletes (Laravel 12+ features).DetectRequestLocale middleware to dynamically set the app locale based on request (e.g., subdomain, path prefix, or header), enabling consistent locale handling across the stack.Cons:
routes.php per locale, which could become cumbersome for large applications with many dynamic routes.Route::get('/fr/...')) with declarative Route::multilingual() syntax.localized_route(), current_route()), which may require updates to existing route generation logic (e.g., in emails, redirects, or APIs).DetectRequestLocale as the first middleware in the web group, which could conflict with existing middleware ordering (e.g., authentication or CORS).chinleung/laravel-locales for locale configuration (optional but recommended). If the project already uses a different locale management system (e.g., Spatie’s laravel-translatable), integration may require additional abstraction.DetectRequestLocale middleware’s default behavior (e.g., subdomain-based detection) may not align with the project’s i18n strategy (e.g., path prefixes like /en/, query params, or cookie-based locales).routes.php). May impact performance during route regeneration (e.g., after migrations).{id}) in translated URIs (e.g., fr/photos/{photo}) must be explicitly defined in routes.php. Omissions could lead to 404s./ vs. /en/ for English)?routes.php translation files? Is there a process for keeping them synchronized with route definitions?/fr/photos vs. /photos?locale=fr)? How does this package’s approach compare to existing solutions?Route::get('/fr/...')) that need to be migrated? What’s the strategy for incremental adoption?routes.php files?Route::apiResource()) also support multilingual paths? The package appears web-focused.laravel-translation) but may require customization to avoid duplication (e.g., locale detection).localized_route() for API calls)./en/about, /fr/about).App::setLocale() calls, middleware).// Before
Route::get('/about', [AboutController::class, 'index'])->name('about');
Route::get('/fr/a-propos', [AboutController::class, 'index'])->name('fr.about');
// After
Route::multilingual('about', AboutController::class)->names([
'en' => 'about',
'fr' => 'a-propos',
]);
Route::multilingual().Route::multilingualResource()).route() → localized_route()).Route::apiResource()) may not work out-of-the-box for multilingual paths. Requires custom middleware or package extension.spatie/laravel-permission) may need updates to handle multilingual route names.spatie/laravel-translation or similar, coordinate locale detection logic to avoid duplication.route('posts.index') vs. localized_route('posts.index')).How can I help you explore Laravel packages today?