laravel-localized-routes maintained by richarddobron
Description
Laravel Package for managing localized routes in Laravel applications.
Authors
Richard Dobroň - Matteo Palazzo
Last update
2026/02/01 01:50
(dev-main)
License
Downloads
9 168
Tags
📖 Requirements
- Laravel 7.0 or higher
- Composer is required for installation
📦 Installing
Install the library using Composer:
$ composer require richarddobron/laravel-localized-routes
⚡️ Quick Start
1. Publish the configuration
$ php artisan vendor:publish --provider="richarddobron\LocalizedRoutes\LocalizedRouteServiceProvider" --tag="config"
This will create config/localized-routes.php.
2. Configure supported locales
<?php
return [
'prefix' => true,
'locales' => [
'de',
'it',
// ...
],
'route_key' => 'locale',
'route_locale' => 'en',
'redirect_code' => 302,
];
3. Add routes. Example below shows how translations work.
Routes that get translated
Create a translation file like routes/lang/de/routes.php:
<?php
return [
'example' => 'beispiel',
];
Then in routes/web.php:
Route::localeGroup([], function () {
Route::get('/example', function () {
return 'Hello, World!';
});
});
This makes these URLs:
/example(default)/de/beispiel/it/example
Routes with parameters
You can give different paths per language:
Route::get('/book/{sku}', function (string $sku) {
return 'Book details ' . $sku;
})->name('book')->locale([
'de' => 'buch/{sku}',
'it',
]);
This makes these URLs:
/book/{sku}(default)/de/buch/{sku}/it/book/{sku}
⚙️ Configuration Options
You can customize the library with the following configuration options.
| Option | Description | Default |
|---|---|---|
prefix |
Automatically prepends locale codes (/de, /it, etc.) to routes. |
true |
locales |
List of supported locales. | [] |
route_key |
The route parameter key used for locale identification. | locale |
route_locale |
Locale used for default routes. | en |
redirect_code |
HTTP status code used for redirecting to the correct localized route. | 302 |
🧪 Testing
$ composer tests
🤝 Contributing
Please see CONTRIBUTING for details.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.