richarddobron/laravel-localized-routes
Composer 安装命令:
composer require richarddobron/laravel-localized-routes
包简介
Laravel Package for managing localized routes in Laravel applications.
README 文档
README
Laravel Package for managing localized routes in Laravel applications.
📖 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.
统计信息
- 总下载量: 11.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04