richarddobron/laravel-localized-routes

Laravel Package for managing localized routes in Laravel applications.

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/richarddobron/laravel-localized-routes

2.0.1 2026-01-05 12:26 UTC

This package is auto-updated.

Last update: 2026-01-05 12:28:11 UTC


README

Laravel Localized Routes

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;
})->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.