Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Multilingual Routes Laravel Package

chinleung/laravel-multilingual-routes

Register multilingual Laravel routes automatically from a single definition. Generates locale-prefixed URLs (optionally including default locale) and can auto-detect/set locale via middleware. Configure supported locales and keep route naming consistent across languages.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer: composer require chinleung/laravel-multilingual-routes.
  2. Add the DetectRequestLocale middleware to the top of your web middleware group in bootstrap/app.php to automatically detect and switch the app locale per request.
  3. Define your supported locales via app.locales config or use chinleung/laravel-locales.
  4. Run php artisan vendor:publish --provider="ChinLeung\MultilingualRoutes\MultilingualRoutesServiceProvider" --tag="config" to publish config if you need to prefix the default locale.
  5. Start with simple routes: Route::multilingual('/', 'HomeController')->name('home');, then create translation files at resources/lang/{locale}/routes.php (e.g., 'home' => 'accueil' for French).

Implementation Patterns

  • Bulk Route Registration: Use Route::multilingualResource('photos', 'PhotoController') to auto-generate full RESTful routes across locales—avoid repetitive boilerplate.
  • Dynamic Naming: Rename routes per locale with ->names(['en' => 'dashboard', 'fr' => 'tableau-bord']) for natural localization, not just translation.
  • Route Inference & Flexibility:
    • Use ->except(['fr']) or ->only(['en', 'es']) to selectively expose routes by locale.
    • Use ->view('welcome') to map multilingual URIs to Blade views without controllers.
    • For complex views, chain ->data([...]) or ->middleware([...]).
  • Link Generation: Replace route() with localized_route('home', [], 'fr') for explicit locale URLs, and current_route() to switch context (e.g., language switcher dropdowns).
  • Route Validation: Use Request::localizedRouteIs('home') in Blade or middleware to check route context agnostic of locale prefix.

Gotchas and Tips

  • Parameterized Routes Require Explicit Translations: For multilingualResource, always include translated patterns like 'test/{test}' => 'teste/{test}'—missing entries cause broken parameterized URIs.
  • Default Locale Prefixing: If publishing the config, set prefix_default_locale to true to avoid inconsistent route naming (e.g., /en/about vs /about).
  • Middleware Placement Matters: DetectRequestLocale must run first in the web middleware group—placing it after auth/session causes locale detection to be too late.
  • Signed URLs: Use URL::signedLocalizedRoute() instead of route()—Laravel’s native signed routes won’t work with multilingual names.
  • Debugging URIs: Run php artisan route:list to verify all generated localized routes—ensure the URI column matches expectations.
  • Extension Points: Extend via MultilingualRouteServiceProvider customization or override Route::multilingual() resolution by listening to Route::afterResolving() in a custom macro.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport