PHPackages                             tool-mountain/laravel-localized-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. tool-mountain/laravel-localized-routes

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

tool-mountain/laravel-localized-routes
======================================

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

1.1.1(9mo ago)0987↓16.7%MITPHPPHP ^8.1CI passing

Since Mar 31Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/tool-mountain/laravel-localized-routes)[ Packagist](https://packagist.org/packages/tool-mountain/laravel-localized-routes)[ RSS](/packages/tool-mountain-laravel-localized-routes/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (5)Used By (0)

Laravel Localized Routes
========================

[](#laravel-localized-routes)

[![GitHub release](https://camo.githubusercontent.com/354cbfb10d4b685c4cedbf08ce01f6dc60ec4447ab0108eb7c2c5b3ffe4690e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f746f6f6c2d6d6f756e7461696e2f6c61726176656c2d6c6f63616c697a65642d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://github.com/tool-mountain/laravel-localized-routes/releases)[![Laravel](https://camo.githubusercontent.com/50a632fed10f91ccd009337654743ad6ba9321cdcd796352dca02b3c296fc702/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31322d7265643f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com)[![License](https://camo.githubusercontent.com/1e6d25ccb39120e3bdef8c23de2250427c199698b667ba2585e57b750891fbb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6f6c2d6d6f756e7461696e2f6c61726176656c2d6c6f63616c697a65642d726f757465732e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/7872e4fa60aa03f10142da05b0d03c8086d77eaeaaea9707de63b65fce95309b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f6f6c2d6d6f756e7461696e2f6c61726176656c2d6c6f63616c697a65642d726f757465732f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465266c6162656c3d7465737473)](https://github.com/tool-mountain/laravel-localized-routes/actions)[![Codecov](https://camo.githubusercontent.com/3b6011bd5162b84fe03e6124e68d02eaca0d9f54a81cb0530b791baf0e83517b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f6f6c2d6d6f756e7461696e2f6c61726176656c2d6c6f63616c697a65642d726f757465733f7374796c653d666c61742d7371756172652d737175617265)](https://codecov.io/gh/tool-mountain/laravel-localized-routes)[![Total Downloads](https://camo.githubusercontent.com/ba26b682a95abb4b3db4b4d3453c3fcba7caf877ff24c104d4ff2f2bc26cc693/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f6f6c2d6d6f756e7461696e2f6c61726176656c2d6c6f63616c697a65642d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tool-mountain/laravel-localized-routes)

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

📖 Table of Contents
-------------------

[](#-table-of-contents)

- [Requirements](#-requirements)
- [Upgrade](#-upgrade)
- [Install](#-install)
- [Configure](#-configure)
    - [Publish Configuration File](#-publish-configuration-file)
    - [Configure Supported Locales](#-configure-supported-locales)
        - [Simple Locales](#simple-locales)
        - [Custom Slugs](#custom-slugs)
        - [Custom Domains](#custom-domains)
    - [Use Fallback Locale](#-use-fallback-locale)
    - [Omit Slug for Main Locale](#-omit-slug-for-main-locale)
    - [Scoped Options](#-scoped-options)
- [Add Middleware to Update App Locale](#-add-middleware-to-update-app-locale)
    - [Detectors](#detectors)
    - [Stores](#stores)
- [Register Routes](#-register-routes)
    - [Translate Parameters with Route Model Binding](#-translate-parameters-with-route-model-binding)
    - [Translate Hard-Coded URI Slugs](#-translate-hard-coded-uri-slugs)
- [Localize 404 Pages](#-localize-404-pages)
- [Cache Routes](#-cache-routes)
- [Generate Route URLs](#-generate-route-urls)
    - [Generate URLs for the Active Locale](#-generate-urls-for-the-active-locale)
    - [Generate URLs for a Specific Locale](#-generate-urls-for-a-specific-locale)
    - [Generate URLs with Localized Parameters](#-generate-urls-with-localized-parameters)
    - [Fallback URLs](#-fallback-urls)
    - [Generate Localized Versions of the Current URL](#-generate-localized-versions-of-the-current-url)
    - [Example Locale Switcher](#-example-locale-switcher)
- [Generate Signed Route URLs](#-generate-signed-route-urls)
- [Redirect to Routes](#-redirect-to-routes)
- [Automatically Redirect to Localized URLs](#-automatically-redirect-to-localized-urls)
- [Helpers](#-helpers)
- [Testing](#-testing)
- [Credits](#-credits)
- [Security](#-security)
- [Changelog](#-changelog)
- [License](#-license)

✅ Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10
- Composer ^2.3 (for [codezero/composer-preload-files](https://github.com/tool-mountain/composer-preload-files))

⬆ Upgrade
---------

[](#-upgrade)

Upgrading to a new major version? Check our [upgrade guide](UPGRADE.md) for instructions.

📦 Install
---------

[](#-install)

Install this package with Composer:

```
composer require tool-mountain/laravel-localized-routes
```

Laravel will automatically register the ServiceProvider.

⚙ Configure
-----------

[](#-configure)

### ☑ Publish Configuration File

[](#-publish-configuration-file)

```
php artisan vendor:publish --provider="ToolMountain\LocalizedRoutes\LocalizedRoutesServiceProvider" --tag="config"
```

You will now find a `localized-routes.php` file in the `config` folder.

### ☑ Configure Supported Locales

[](#-configure-supported-locales)

#### Simple Locales

[](#simple-locales)

Add any locales you wish to support to your published `config/localized-routes.php` file:

```
'supported_locales' => ['en', 'nl'];
```

These locales will be used as a slug, prepended to the URL of your localized routes.

#### Custom Slugs

[](#custom-slugs)

You can also use a custom slug for a locale:

```
'supported_locales' => [
    'en' => 'english-slug',
    'nl' => 'dutch-slug',
];
```

#### Custom Domains

[](#custom-domains)

Or you can use a custom domain for a locale:

```
'supported_locales' => [
    'en' => 'english-domain.test',
    'nl' => 'dutch-domain.test',
];
```

### ☑ Use Fallback Locale

[](#-use-fallback-locale)

When using the `route()` helper to generate a URL for a locale that is not supported, a `Symfony\Component\Routing\Exception\RouteNotFoundException` is thrown by Laravel. However, you can configure a fallback locale to attempt to resolve a fallback URL instead. If that fails too, the exception is thrown.

```
'fallback_locale' => 'en',
```

### ☑ Omit Slug for Main Locale

[](#-omit-slug-for-main-locale)

Specify your main locale if you want to omit its slug from the URL:

```
'omitted_locale' => 'en',
```

This option has no effect if you use domains instead of slugs.

### ☑ Scoped Options

[](#-scoped-options)

To set an option for one localized route group only, you can specify it as the second parameter of the localized route macro. This will override the config file settings. Currently, only 2 options can be overridden.

```
Route::localized(function () {
    Route::get('about', [AboutController::class, 'index']);
}, [
    'supported_locales' => ['en', 'nl', 'fr'],
    'omitted_locale' => 'en',
]);
```

🧩 Add Middleware to Update App Locale
-------------------------------------

[](#-add-middleware-to-update-app-locale)

By default, the app locale will always be what you configured in `config/app.php`. To automatically update the app locale, you need to register the middleware in the `web` middleware group. Make sure to add it after `StartSession` and before `SubstituteBindings`.

The order of the middleware is important if you are using localized route keys (translated slugs)! The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.

### Laravel 11 and newer:

[](#laravel-11-and-newer)

Add the middleware to the `web` middleware group in `bootstrap/app.php`.

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(remove: [
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ]);
    $middleware->web(append: [
        \ToolMountain\LocalizedRoutes\Middleware\SetLocale::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ]);
})
```

### Laravel 10:

[](#laravel-10)

Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.

```
// app/Http/Kernel.php
protected $middlewareGroups = [
    'web' => [
        //...
        \Illuminate\Session\Middleware\StartSession::class, //  You can create your own store by implementing the `ToolMountain\LocalizedRoutes\Middleware\Stores\Store` interface and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

Although no further configuration is needed, you can change advanced settings in the config file.

🚘 Register Routes
-----------------

[](#-register-routes)

Define your routes inside the `Route::localized()` closure, to automatically register them for each locale.

This will prepend the locale to the route's URI and name. If you configured custom domains, it will use those instead of the URI slugs. You can also use route groups inside the closure.

```
Route::localized(function () {
    Route::get('about', [AboutController::class, 'index'])->name('about');
});
```

With supported locales `['en', 'nl']`, the above would register:

URIName`/en/about``en.about``/nl/about``nl.about`And with the omitted locale set to `en`, the result would be:

URIName`/about``en.about``/nl/about``nl.about`> In a most practical scenario, you would register a route either localized or non-localized, but not both. If you do, you will always need to specify a locale to generate the URL with the `route()` helper, because existing route names always have priority. Especially when omitting a main locale from the URL, this would be problematic, because you can't have, for example, a localized `/about` route and a non-localized `/about` route in this case. The same idea applies to the `/` (root) route! Also note that the route names still have the locale prefix even if the slug is omitted.

### ☑ Translate Parameters with Route Model Binding

[](#-translate-parameters-with-route-model-binding)

When resolving incoming route parameters from a request, you probably rely on [Laravel's route model binding](https://laravel.com/docs/routing#route-model-binding). You typehint a model in the controller, and it will look for a `{model}` by its ID, or by a specific attribute like `{model:slug}`. If it finds one that matches the parameter value in the URL, it is injected in the controller.

```
// Example: use the post slug as the route parameter
Route::get('posts/{post:slug}', [PostsController::class, 'index']);

// PostsController.php
public function index(Post $post)
{
    return $post;
}
```

However, to resolve a localized parameter you need to add a `resolveRouteBinding()` method to your model. In this method you need to write the logic required to find a match, using the parameter value from the URL.

For example, you might have a JSON column in your database containing translated slugs:

```
public function resolveRouteBinding($value, $field = null)
{
    // Default field to query if no parameter field is specified
    $field = $field ?: $this->getRouteKeyName();

    // If the parameter field is 'slug',
    // lets query a JSON field with translations
    if ($field === 'slug') {
        $field .= '->' . App::getLocale();
    }

    // Perform the query to find the parameter value in the database
    return $this->where($field, $value)->firstOrFail();
}
```

> If you are looking for a good solution to implement translated attributes on your models, be sure to check out [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable).

### ☑ Translate Hard-Coded URI Slugs

[](#-translate-hard-coded-uri-slugs)

This package includes [tool-mountain/laravel-uri-translator](https://github.com/tool-mountain/laravel-uri-translator). This registers a `Lang::uri()` macro that enables you to translate individual, hard-coded URI slugs. Route parameters will not be translated by this macro.

Routes with translated URIs need to have a name in order to generate localized versions of it using the `route()` helper or the `Route::localizedUrl()` macro. Because these routes have different slugs depending on the locale, the route name is the only thing that links them together.

First, you create a `routes.php` translation file in your app's `lang` folder for each locale, for example:

```
lang/nl/routes.php
lang/fr/routes.php
```

Then you add the appropriate translations to each file:

```
// lang/nl/routes.php
return [
    'about' => 'over',
    'us' => 'ons',
];
```

And finally, you use the macro when registering routes:

```
Route::localized(function () {
    Route::get(Lang::uri('about/us'), [AboutController::class, 'index'])->name('about');
});
```

The URI macro accepts 2 additional parameters:

1. A locale, in case you need translations to a locale other than the current app locale.
2. A namespace, in case your translation files reside in a package.

```
Lang::uri('hello/world', 'fr', 'my-package');
```

You can also use `trans()->uri('hello/world')` instead of `Lang::uri('hello/world')`.

### Example

[](#example)

Using these example translations:

```
// lang/nl/routes.php
return [
    'hello' => 'hallo',
    'world' => 'wereld',
    'override/hello/world' => 'something/very/different',
    'hello/world/{parameter}' => 'uri/with/{parameter}',
];
```

These are possible translation results:

```
// Translate every slug individually
// Translates to: 'hallo/wereld'
Lang::uri('hello/world');

// Keep original slug when missing translation
// Translates to: 'hallo/big/wereld'
Lang::uri('hello/big/world');

// Translate slugs, but not parameter placeholders
// Translates to: 'hallo/{world}'
Lang::uri('hello/{world}');

// Translate full URIs if an exact translation exists
// Translates to: 'something/very/different'
Lang::uri('override/hello/world');

// Translate full URIs if an exact translation exists (with placeholder)
// Translates to: 'uri/with/{parameter}'
Lang::uri('hello/world/{parameter}');
```

### 🔦 Localize 404 Pages

[](#-localize-404-pages)

A standard `404` response has no actual `Route` and does not go through the middleware. This means our middleware will not be able to update the locale and the request can not be localized.

To fix this, you can register this fallback route at the end of your `routes/web.php` file:

```
Route::fallback(\ToolMountain\LocalizedRoutes\Controllers\FallbackController::class);
```

Because the fallback route is an actual `Route`, the middleware will run and update the locale.

The fallback route is a "catch all" route that Laravel provides. If you type in a URL that doesn't exist, this route will be triggered instead of a typical 404 exception.

The `FallbackController` will attempt to respond with a 404 error view, located at `resources/views/errors/404.blade.php`. If this view does not exist, the normal `Symfony\Component\HttpKernel\Exception\NotFoundHttpException` will be thrown. You can configure which view to use by changing the `404_view` entry in the config file.

Fallback routes will not apply when:

- your existing routes throw a `404` exception (as in `abort(404)`)
- your existing routes throw a `ModelNotFoundException` (like with route model binding)
- your existing routes throw any other exception

🗄 Cache Routes
--------------

[](#-cache-routes)

In production, you can safely cache your routes per usual.

```
php artisan route:cache
```

⚓ Generate Route URLs
---------------------

[](#-generate-route-urls)

### ☑ Generate URLs for the Active Locale

[](#-generate-urls-for-the-active-locale)

You can get the URL of your named routes as usual, using the `route()` helper.

```
$url = route('about');
```

If you registered an `about` route that is not localized, then `about` is an existing route name and its URL will be returned. Otherwise, this will try to generate the `about` URL for the active locale, e.g. `en.about`.

### ☑ Generate URLs for a Specific Locale

[](#-generate-urls-for-a-specific-locale)

In some cases, you might need to generate a URL for a specific locale. For this purpose, an additional locale parameter was added to Laravel's `route()` helper.

```
$url = route('about', [], true, 'nl'); // this will load 'nl.about'
```

### ☑ Generate URLs with Localized Parameters

[](#-generate-urls-with-localized-parameters)

There are a number of ways to generate route URLs with localized parameters.

#### Pass Localized Parameters Manually

[](#pass-localized-parameters-manually)

Let's say we have a `Post` model with a `getSlug()` method:

```
public function getSlug($locale = null)
{
    $locale = $locale ?: App::getLocale();

    $slugs = [
        'en' => 'en-slug',
        'nl' => 'nl-slug',
    ];

    return $slugs[$locale] ?? '';
}
```

> Of course, in a real project the slugs wouldn't be hard-coded. If you are looking for a good solution to implement translated attributes on your models, be sure to check out [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable).

Now you can pass a localized slug to the `route()` function:

```
route('posts.show', [$post->getSlug()]);
route('posts.show', [$post->getSlug('nl')], true, 'nl');
```

#### Use a Custom Localized Route Key

[](#use-a-custom-localized-route-key)

You can let Laravel resolve localized parameters automatically by adding the `getRouteKey()` method to your model:

```
public function getRouteKey()
{
    $locale = App::getLocale();

    $slugs = [
        'en' => 'en-slug',
        'nl' => 'nl-slug',
    ];

    return $slugs[$locale] ?? '';
}
```

Now you can just pass the model:

```
route('posts.show', [$post]);
route('posts.show', [$post], true, 'nl');
```

### ☑ Fallback URLs

[](#-fallback-urls)

A fallback locale can be provided in the config file. If the locale parameter for the `route()` helper is not a supported locale, the fallback locale will be used instead.

```
// When the fallback locale is set to 'en'
// and the supported locales are 'en' and 'nl'

$url = route('about', [], true, 'nl'); // this will load 'nl.about'
$url = route('about', [], true, 'wk'); // this will load 'en.about'
```

If neither a regular nor a localized route can be resolved, a `Symfony\Component\Routing\Exception\RouteNotFoundException` will be thrown.

### ☑ Generate Localized Versions of the Current URL

[](#-generate-localized-versions-of-the-current-url)

To generate a URL for the current route in any locale, you can use the `Route::localizedUrl()` macro.

#### Pass Parameters Manually

[](#pass-parameters-manually)

Just like with the `route()` helper, you can pass parameters as a second argument.

Let's say we have a `Post` model with a `getSlug()` method:

```
public function getSlug($locale = null)
{
    $locale = $locale ?: App::getLocale();

    $slugs = [
        'en' => 'en-slug',
        'nl' => 'nl-slug',
    ];

    return $slugs[$locale] ?? '';
}
```

Now you can pass a localized slug to the macro:

```
$current = Route::localizedUrl(null, [$post->getSlug()]);
$en = Route::localizedUrl('en', [$post->getSlug('en')]);
$nl = Route::localizedUrl('nl', [$post->getSlug('nl')]);
```

#### Use a Custom Route Key

[](#use-a-custom-route-key)

If you add the model's `getRouteKey()` method, you don't need to pass the parameter at all.

```
public function getRouteKey()
{
    $locale = App::getLocale();

    $slugs = [
        'en' => 'en-slug',
        'nl' => 'nl-slug',
    ];

    return $slugs[$locale] ?? '';
}
```

The macro will now automatically figure out what parameters the current route has and fetch the values.

```
$current = Route::localizedUrl();
$en = Route::localizedUrl('en');
$nl = Route::localizedUrl('nl');
```

#### Multiple Route Keys

[](#multiple-route-keys)

If you have a route with multiple keys, like `/en/posts/{id}/{slug}`, then you can implement the `ProvidesRouteParameters` interface in your model. From the `getRouteParameters()` method, you then return the required parameter values.

```
use ToolMountain\LocalizedRoutes\ProvidesRouteParameters;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements ProvidesRouteParameters
{
    public function getRouteParameters($locale = null)
    {
        return [
            $this->id,
            $this->getSlug($locale) // Add this method yourself of course :)
        ];
    }
}
```

Now, the parameters will still be resolved automatically:

```
$current = Route::localizedUrl();
$en = Route::localizedUrl('en');
$nl = Route::localizedUrl('nl');
```

#### Keep or Remove Query String

[](#keep-or-remove-query-string)

By default, the query string will be included in the generated URL. If you don't want this, you can pass an extra parameter to the macro:

```
$keepQuery = false;
$current = Route::localizedUrl(null, [], true, $keepQuery);
```

### ☑ Example Locale Switcher

[](#-example-locale-switcher)

The following Blade snippet will add a link to the current page in every alternative locale.

It will only run if the current route is localized or a fallback route.

```
@if (Route::isLocalized() || Route::isFallback())

        @foreach(LocaleConfig::getLocales() as $locale)
            @if ( ! App::isLocale($locale))

                        {{ strtoupper($locale) }}

            @endif
        @endforeach

@endif
```

🖋 Generate Signed Route URLs
----------------------------

[](#-generate-signed-route-urls)

Generating a localized signed route and temporary signed route URL is just as easy as generating normal route URLs. Pass it the route name, the necessary parameters, and you will get the URL for the current locale.

```
$signedUrl = URL::signedRoute('reset.password', ['user' => $id]);
$signedUrl = URL::temporarySignedRoute('reset.password', now()->addMinutes(30), ['user' => $id]);
```

You can also generate a signed route URL for a specific locale:

```
$signedUrl = URL::signedRoute('reset.password', ['user' => $id], null, true, 'nl');
$signedUrl = URL::temporarySignedRoute('reset.password', now()->addMinutes(30), ['user' => $id], true, 'nl');
```

Check out the [Laravel docs](https://laravel.com/docs/urls#signed-urls) for more info on signed routes.

🚌 Redirect to Routes
--------------------

[](#-redirect-to-routes)

You can redirect to routes, just like you would in a normal Laravel app, using the `redirect()` helper or the `Redirect` facade.

If you register an `about` route that is not localized, then `about` is an existing route name and its URL will be redirected to. Otherwise, this will try to redirect to the `about` route for the active locale, e.g. `en.about`:

```
return redirect()->route('about');
```

You can also redirect to URLs in a specific locale:

```
// Redirects to 'nl.about'
return redirect()->route('about', [], 302, [], 'nl');
```

A localized version of the `signedRoute` and `temporarySignedRoute` redirects are included as well:

```
// Redirects to the active locale
return redirect()->signedRoute('signed.route', ['user' => $id]);
return redirect()->temporarySignedRoute('signed.route', now()->addMinutes(30), ['user' => $id]);

// Redirects to 'nl.signed.route'
return redirect()->signedRoute('signed.route', ['user' => $id], null, 302, [], 'nl');
return redirect()->temporarySignedRoute('signed.route', now()->addMinutes(30), ['user' => $id], 302, [], 'nl');
```

🪧 Automatically Redirect to Localized URLs
------------------------------------------

[](#-automatically-redirect-to-localized-urls)

To redirect any non-localized URL to its localized version, you can set the config option `redirect_to_localized_urls` to `true`, and register the following fallback route with the `FallbackController` at the end of your `routes/web.php` file.

```
Route::fallback(\ToolMountain\LocalizedRoutes\Controllers\FallbackController::class);
```

The fallback route is a "catch all" route that Laravel provides. If you type in a URL that doesn't exist, this route will be triggered instead of a typical 404 exception.

The `FallbackController` will attempt to redirect to a localized version of the URL, or return a [localized 404 response](#-localize-404-pages) if it doesn't exist.

For example:

URIRedirects To`/``/en``/about``/en/about`If the omitted locale is set to `en`:

URIRedirects To`/en``/``/en/about``/about`If a route doesn't exist, a `404` response will be returned.

🪜 Helpers
---------

[](#-helpers)

### `Route::hasLocalized()`

[](#routehaslocalized)

```
// Check if a named route exists in the active locale:
$exists = Route::hasLocalized('about');
// Check if a named route exists in a specific locale:
$exists = Route::hasLocalized('about', 'nl');
```

### `Route::isLocalized()`

[](#routeislocalized)

```
// Check if the current route is localized:
$isLocalized = Route::isLocalized();
// Check if the current route is localized and has a specific name:
$isLocalized = Route::isLocalized('about');
// Check if the current route has a specific locale and has a specific name:
$isLocalized = Route::isLocalized('about', 'nl');
// Check if the current route is localized and its name matches a pattern:
$isLocalized = Route::isLocalized(['admin.*', 'dashboard.*']);
// Check if the current route has one of the specified locales and has a specific name:
$isLocalized = Route::isLocalized('about', ['en', 'nl']);
```

### `Route::isFallback()`

[](#routeisfallback)

```
// Check if the current route is a fallback route:
$isFallback = Route::isFallback();
```

🚧 Testing
---------

[](#-testing)

```
composer test
```

☕ Credits
---------

[](#-credits)

- [Ivan Vermeyen](https://github.com/ivanvermeyen) [†](https://github.com/codezero-be/laravel-uri-translator/pull/2#issuecomment-2747179649)
- [All contributors](https://github.com/tool-mountain/laravel-localized-routes/contributors)

🔒 Security
----------

[](#-security)

If you discover any security related issues, please [e-mail me](mailto:roj@vroe.men) instead of using the issue tracker.

📑 Changelog
-----------

[](#-changelog)

A complete list of all notable changes to this package can be found on the [releases page](https://github.com/tool-mountain/laravel-localized-routes/releases).

📜 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance57

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82% of commits — single point of failure

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 ~40 days

Total

4

Last Release

285d ago

### Community

Maintainers

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

---

Top Contributors

[![ivanvermeyen](https://avatars.githubusercontent.com/u/3598622?v=4)](https://github.com/ivanvermeyen "ivanvermeyen (241 commits)")[![rojtjo](https://avatars.githubusercontent.com/u/1123887?v=4)](https://github.com/rojtjo "rojtjo (32 commits)")[![tanerkay](https://avatars.githubusercontent.com/u/224194?v=4)](https://github.com/tanerkay "tanerkay (3 commits)")[![bumbummen99](https://avatars.githubusercontent.com/u/4533331?v=4)](https://github.com/bumbummen99 "bumbummen99 (3 commits)")[![Skullbock](https://avatars.githubusercontent.com/u/1104083?v=4)](https://github.com/Skullbock "Skullbock (2 commits)")[![kedniko](https://avatars.githubusercontent.com/u/42846752?v=4)](https://github.com/kedniko "kedniko (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![mallardduck](https://avatars.githubusercontent.com/u/619938?v=4)](https://github.com/mallardduck "mallardduck (1 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (1 commits)")[![trippo](https://avatars.githubusercontent.com/u/497169?v=4)](https://github.com/trippo "trippo (1 commits)")[![andrewnclark](https://avatars.githubusercontent.com/u/38881834?v=4)](https://github.com/andrewnclark "andrewnclark (1 commits)")[![WhiteWolf99](https://avatars.githubusercontent.com/u/1449365?v=4)](https://github.com/WhiteWolf99 "WhiteWolf99 (1 commits)")[![domgew](https://avatars.githubusercontent.com/u/44265359?v=4)](https://github.com/domgew "domgew (1 commits)")[![hfalucas](https://avatars.githubusercontent.com/u/7132610?v=4)](https://github.com/hfalucas "hfalucas (1 commits)")[![hlaCk](https://avatars.githubusercontent.com/u/27328114?v=4)](https://github.com/hlaCk "hlaCk (1 commits)")[![juliangarcess](https://avatars.githubusercontent.com/u/41131304?v=4)](https://github.com/juliangarcess "juliangarcess (1 commits)")[![lada](https://avatars.githubusercontent.com/u/179279?v=4)](https://github.com/lada "lada (1 commits)")

---

Tags

phplaravellocalizationlanguageroutestranslationroutinglocalecountry

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tool-mountain-laravel-localized-routes/health.svg)

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

###  Alternatives

[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)[codezero/laravel-localizer

Automatically detect and set an app locale that matches your visitor's preference.

50394.3k4](/packages/codezero-laravel-localizer)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)

PHPackages © 2026

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