PHPackages                             alexwaha/laravel-multilang-routes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. alexwaha/laravel-multilang-routes

ActiveLibrary[Localization &amp; i18n](/categories/localization)

alexwaha/laravel-multilang-routes
=================================

Multilanguage Localization for Laravel routes.

1.1.1(1y ago)719MITPHPPHP &gt;=8.1

Since Apr 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AlexWaha/laravel-multilang-routes)[ Packagist](https://packagist.org/packages/alexwaha/laravel-multilang-routes)[ Docs](https://alexwaha.com)[ RSS](/packages/alexwaha-laravel-multilang-routes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (13)Used By (0)

Laravel Multilang Routes
========================

[](#laravel-multilang-routes)

[![Latest Version](https://camo.githubusercontent.com/30afb439da3cca9c15617b005e02c4fdd6d3d796d9d5a2e2c1c5f0ad5d8e0153/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6578776168612f6c61726176656c2d6d756c74696c616e672d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexwaha/laravel-multilang-routes)[![Laravel Versions](https://camo.githubusercontent.com/19bba1a114c6a81ee0f3f16cf5fd88c3d4ae32d37b65e128abdfe7755c5541a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d3130253230253743253230313125323025374325323031322d626c75653f7374796c653d666c61742d737175617265)](https://laravel.com/)[![PHP Version](https://camo.githubusercontent.com/b543b06c10a4acae57f00e7e89a1188d9f86dc1349389fe58762b4e4842cf9d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322532422d626c75653f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Downloads](https://camo.githubusercontent.com/9d9b7db390307cf043c58d48a90d5b9669f2865676b6bca059b793da006ef36c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6578776168612f6c61726176656c2d6d756c74696c616e672d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexwaha/laravel-multilang-routes)[![License](https://camo.githubusercontent.com/9e5657fcd95a98be0eb617d2c4cb3d812c9b7ac59d5e062dd7366f84a00e5f5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c6578776168612f6c61726176656c2d6d756c74696c616e672d726f757465732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Simple and lightweight package to localize your Laravel routes.

Features
--------

[](#features)

- Localized versions of your routes without complex configurations
- Seamless support for route groups, slugs, and middleware
- Automatically switches URLs based on the active locale
- Redirects `/fallback_locale/...` to `/...` with 301 if needed
- Works with Laravel 10, 11, and 12

📚 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require alexwaha/laravel-multilang-routes
```

Publish the configuration file:

```
php artisan vendor:publish --tag=multilang-routes-config
```

This will create `config/multilang-routes.php`.

🚀 Usage
-------

[](#-usage)

Define your routes using the `localizedRoutes` macro.

```
use Illuminate\Support\Facades\Route;

Route::localizedRoutes(function () {
    Route::get('/', function () {
        return view('welcome');
    });
});
```

Or routes with middlewares, for ex.: `web`

```
use Illuminate\Support\Facades\Route;

Route::localizedRoutes(function () {
    Route::get('/', [HomeController::class, 'index'])->name('home');
}, ['web']);
```

Or named routes with prefix

```
Route::localizedRoutes(function () {
    Route::name('blog.')->prefix('/blog')->group(function () {
        Route::get('', [BlogController::class, 'index'])->name('index');
        Route::get('/{post}', [BlogController::class, 'show'])->name('show');
    });
}, ['web']);
```

This automatically generates localized routes like:

- `/en/blog`
- `/es/blog`
- `/de/blog`

> The slug in the URL is required for the `setLocale` middleware, which changes the application language based on the `locale` slug.

🧩 Checking if Route is Localized
--------------------------------

[](#-checking-if-route-is-localized)

You can easily check if your route name is already localized:

```
@if (Route::isLocalized($name))
    // The route name is already localized (e.g., "en.blog.index")
@endif
```

### Blade usage

[](#blade-usage)

Generate a localized URL in Blade templates using `Route::localize()` method:

```
About
```

Or generate URLs with parameters:

```
View Post
```

🛡️ Middleware
-------------

[](#️-middleware)

### 🧩 `localize.setLocale`

[](#-localizesetlocale)

Middleware to automatically detect and set the application locale based on the first segment of the URL.

Registered alias as `localize.setLocale`

> Note: If the segment does not match any configured language slug, the application will fall back to the default locale.

➊ Apply Middleware Globally to a middleware group

in **Laravel 10.x** `app\Http\Kernel.php`

```
protected $middlewareGroups = [
        'web' => [
            \Alexwaha\Localize\Middleware\SetLocale::class,
```

in **Laravel ^11.x** `bootstrap\app.php`

```
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->group('web', [
            \Alexwaha\Localize\Middleware\SetLocale::class,,
        ]);
    })
```

```
Route::localizedRoutes(function () {
    Route::get('/', function () {
        return view('welcome');
    });
}, ['web']);
```

➋ Apply Middleware Directly in `localizedRoutes`You can pass middleware as the second argument to the localizedRoutes macro:

```
Route::localizedRoutes(function () {
    Route::get('/', function () {
        return view('welcome');
    });
}, ['web', 'localize.setLocale']);
```

This is a simpler and more compact approach, especially useful for smaller projects.

### 🧩 `PaginatedMiddleware`

[](#-paginatedmiddleware)

Middleware that transforms paginated URLs by cleaning query parameters.

Registered alias as `localize.paginated`.

When a paginated route like `/page/{page?}` is used:

🛠 **Note**:

- It ensures that the first page `blog/page/1` does not have a query string or URL segment like `/page/1`.
- Instead, the first page URL is clean, such as `/blog`, improving SEO and URL readability.
- If the user accesses `blog/page/2`, `blog/page/3`, etc., the page number remains in the URL.

When building localized URLs with pagination, you can define your routes like this:

```
use Illuminate\Support\Facades\Route;

Route::localizedRoutes(function () {
    Route::name('blog.')->prefix('/blog')->group(function () {
        Route::get('', [BlogController::class, 'index'])->name('index');
        Route::get('/page/{page?}', [BlogController::class, 'index'])->name('paginated');
        Route::get('/{post}', [BlogController::class, 'show'])->name('show');
    });
}, ['web', 'localize.setLocale', 'localize.paginated']);
```

### Default Locale Redirection

[](#default-locale-redirection)

If a user visits a URL with the default fallback locale (e.g., `/en/about` when `en` is the fallback), they will be automatically redirected with a **301 Permanent Redirect** to the non-sluged version (`/about`).

This ensures clean URLs for your default language.

⚙️ Configuration
----------------

[](#️-configuration)

You can configure which languages are available and their corresponding URL slugs inside the `config/multilang-routes.php` file.

Each language entry should contain:

KeyDescriptionExamplelocaleApplication locale `(app()->setLocale)`en,es,deslugURL slug for routesen,es,de | english, spanish, german#### Example:

[](#example)

```
return [
    'language_provider' => [
        'class' => \Alexwaha\Localize\LanguageProvider::class,
        'params' => [
            'languages' => [
                [
                    'locale' => 'en',
                    'slug' => 'en',
                ],
                [
                    'locale' => 'es',
                    'slug' => 'es',
                ],
            ],
        ],
    ],
];
```

You can customize the list of supported languages and their URL prefixes or create your own Language Provider.

If you want full control over how languages are loaded (for example, from a database), you can create a custom provider by implementing the `LanguageProviderInterface` and specify your class in the configuration.

Example `config/multilang-routes.php`:

```
return [
    'language_provider' => [
        'class' => App\Providers\CustomLanguageProvider::class,
    ],
];
```

Your custom provider should implement:

```
interface LanguageProviderInterface
{
    public function getLanguages(): array;
    public function getLocaleBySegment(?string $segment = null): string;
}
```

This gives you the flexibility to load languages from the database, API, or any other source.

---

📂 Examples
----------

[](#-examples)

You can find practical examples inside the [examples](./examples) folder:

- [ExampleController.php](examples/ExampleController.php)
    Simple controller with paginated navigation.
- [DatabaseLanguageProvider.php](examples/DatabaseLanguageProvider.php)
    Custom Language Provider loading languages from database.
- [RoutesExample.php](examples/RoutesExample.php)
    Localized routes registration example.
- [pagination.blade.php](examples/pagination.blade.php)
    Blade pagination rendering.

---

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel 10.x, 11.x, or 12.x

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Credits
-------

[](#credits)

Developed by [Alex Waha](https://alexwaha.com)

---

Feel free to submit issues or contribute to this project!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance48

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

12

Last Release

395d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a021873fb9ee11ab36d842b3d63434a904e4f2cbd126939a6e3b8157111100e1?d=identicon)[alexwaha](/maintainers/alexwaha)

---

Tags

languagelanguage-switcherlaravellocalelocalizationlocalizedlocalized-routermultilanguagerouteslaravellocalizationroutesmultilinguallocalize

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/alexwaha-laravel-multilang-routes/health.svg)

```
[![Health](https://phpackages.com/badges/alexwaha-laravel-multilang-routes/health.svg)](https://phpackages.com/packages/alexwaha-laravel-multilang-routes)
```

###  Alternatives

[themsaid/laravel-langman

Manage language files with ease.

871307.5k11](/packages/themsaid-laravel-langman)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
