PHPackages                             chinleung/laravel-multilingual-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. chinleung/laravel-multilingual-routes

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

chinleung/laravel-multilingual-routes
=====================================

A package to register multilingual routes.

v5.1.1(10mo ago)442195.4k—5%27[2 PRs](https://github.com/chinleung/laravel-multilingual-routes/pulls)2MITPHPPHP ^8.2CI passing

Since Jul 30Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/chinleung/laravel-multilingual-routes)[ Packagist](https://packagist.org/packages/chinleung/laravel-multilingual-routes)[ Docs](https://github.com/chinleung/laravel-multilingual-routes)[ RSS](/packages/chinleung-laravel-multilingual-routes/feed)WikiDiscussions v5 Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (63)Used By (2)

Laravel Multilingual Routes
===========================

[](#laravel-multilingual-routes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e98d00cc73678ae7660b3968542f0415e1b909da71e05792f9a1e3399344314d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696e6c65756e672f6c61726176656c2d6d756c74696c696e6775616c2d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chinleung/laravel-multilingual-routes)[![Build Status](https://github.com/chinleung/laravel-multilingual-routes/workflows/tests/badge.svg)](https://github.com/chinleung/laravel-multilingual-routes/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/0dab789e2937f2f1fecb06bf097c7a6054b9ac4046e7076d3b65de1677e387b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696e6c65756e672f6c61726176656c2d6d756c74696c696e6775616c2d726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chinleung/laravel-multilingual-routes)

A package to register multilingual routes for your application.

Versioning
----------

[](#versioning)

VersionLaravel Versionv512.xv410.x, 11.xv39.xv2Older than 9.xInstallation
------------

[](#installation)

You can install the package via composer:

```
composer require chinleung/laravel-multilingual-routes
```

To detect and change the locale of the application based on the request automatically, you can add the middleware to your `bootstrap/app.php`. It must be the first item in the `web` middleware group.

```
$middleware->web(
    prepend: [
        DetectRequestLocale::class,
    ]
);
```

Configuration
-------------

[](#configuration)

By default, the application locales are only going to be `en` and the default locale is not prefixed. If you want to prefix the default locale, please run the following command to publish the configuration file:

```
php artisan vendor:publish --provider="ChinLeung\MultilingualRoutes\MultilingualRoutesServiceProvider" --tag="config"
```

If your application supports different locales, you can either set a `app.locales` configuration or follow the configuration instructions from [chinleung/laravel-locales](https://github.com/chinleung/laravel-locales#configuration).

Example
-------

[](#example)

Instead of doing this:

```
Route::get('/', 'ShowHomeController')->name('en.home');
Route::get('/fr', 'ShowHomeController')->name('fr.home');
```

You can accomplish the same result with:

```
Route::multilingual('/', 'ShowHomeController')->name('home');
```

A [demo repository](https://github.com/chinleung/laravel-multilingual-routes-demo) has been setup to showcase the basic usage of the package.

Usage
-----

[](#usage)

### Quick Usage

[](#quick-usage)

Once you have configured the locales, you can start adding routes like the following example in your `routes/web.php`:

```
Route::multilingual('test', 'TestController');
```

This will generate the following:

MethodURINameActionGET|HEADtesten.testApp\\Http\\Controllers\\TestControllerGET|HEADfr/testefr.testApp\\Http\\Controllers\\TestControllerNote the `URI` column is generated from a translation file located at `resources/lang/{locale}/routes.php` which contains the key of the route like the following:

```
