PHPackages                             laurentesc/laravel-subdomain-localization - 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. laurentesc/laravel-subdomain-localization

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

laurentesc/laravel-subdomain-localization
=========================================

Subdomain localization support for Laravel

1.0.0(10y ago)1911.3k7[2 issues](https://github.com/LaurentEsc/Laravel-Subdomain-Localization/issues)MITPHPPHP &gt;=5.4.0

Since Aug 17Pushed 8y ago3 watchersCompare

[ Source](https://github.com/LaurentEsc/Laravel-Subdomain-Localization)[ Packagist](https://packagist.org/packages/laurentesc/laravel-subdomain-localization)[ Docs](https://github.com/LaurentEsc/Laravel-Subdomain-Localization)[ RSS](/packages/laurentesc-laravel-subdomain-localization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

**Important notice: this package is no longer maintained.**

Laravel-Subdomain-Localization
==============================

[](#laravel-subdomain-localization)

[![Latest Stable Version](https://camo.githubusercontent.com/99b5b8cb25b70e78950ce1c01d7d79ff0fd6a065b0f59705faa40ee47f8e172f/68747470733a2f2f706f7365722e707567782e6f72672f6c617572656e746573632f6c61726176656c2d737562646f6d61696e2d6c6f63616c697a6174696f6e2f76657273696f6e)](https://packagist.org/packages/laurentesc/laravel-subdomain-localization) [![Total Downloads](https://camo.githubusercontent.com/9b9ef832d60e0bdaeaa7c5728a839e9f5f163e2fffa5ccd7383ca645cf2da38b/68747470733a2f2f706f7365722e707567782e6f72672f6c617572656e746573632f6c61726176656c2d737562646f6d61696e2d6c6f63616c697a6174696f6e2f642f746f74616c2e706e67)](https://packagist.org/packages/laurentesc/laravel-subdomain-localization)[![Build Status](https://camo.githubusercontent.com/3058c0226cbd55eedfa95d8a763c3510a61916013bd7fa6a353d6d6bab5a2acf/68747470733a2f2f6170692e7472617669732d63692e6f72672f4c617572656e744573632f4c61726176656c2d537562646f6d61696e2d4c6f63616c697a6174696f6e2e706e67)](https://travis-ci.org/LaurentEsc/Laravel-Subdomain-Localization)

Subdomain localization support for Laravel.

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

[](#table-of-contents)

- [Installation](#installation)
    - [Composer](#composer)
    - [Manually](#manually)
    - [Laravel](#laravel)
- [Usage](#usage)
    - [Locale detection](#locale-detection)
    - [Middleware](#middleware)
    - [Route translation](#route-translation)
- [Configuration](#configuration)
    - [Configuration file](#configuration-file)
    - [Configuration values](#configuration-values)
- [Useful functions](#useful-functions)
- [Changelog](#changelog)
- [License](#license)

Installation
------------

[](#installation)

### Composer

[](#composer)

Add Laravel-Subdomain-Localization to your `composer.json` file.

```
"laurentesc/laravel-subdomain-localization": "dev-master"

```

Run `composer install` to get the latest version of the package.

### Manually

[](#manually)

It's recommended that you use Composer, however you can download and install from this repository.

### Laravel

[](#laravel)

Laravel-Subdomain-Localization comes with a service provider for Laravel.

To register the service provider in your Laravel application, open `config/app.php` and add the following line to the `providers` array:

```
	...
	LaurentEsc\Localization\LocalizationServiceProvider::class
	...
```

Laravel-Subdomain-Localization comes with 2 facades: `Localize` and `Router`.

If you want to use them, open `config/app.php` and add the following lines to the `aliases` array:

```
	...
    'Localize'  => LaurentEsc\Localization\Facades\Localize::class,
    'Router'    => LaurentEsc\Localization\Facades\Router::class,
	...
```

Laravel comes with a middleware that can be used to enforce the use of a language subdomain.

If you want to use it, open `app/Http/kernel.php` and register this route middleware by adding it to the `routeMiddleware` array:

```
	...
    'localize' => \LaurentEsc\Localization\Middleware\Localization::class,
	...
```

Usage
-----

[](#usage)

### Locale detection

[](#locale-detection)

Open `app/Providers/RouteServiceProvider.php` and add a call to detectLocale() from the boot method. For example, using the facade:

```
	...
	use LaurentEsc\Localization\Facades\Localize;
	...
    public function boot(Router $router)
    {
        // This will guess a locale from the current HTTP request
        // and set the application locale
        Localize::detectLocale();

        parent::boot($router);
    }
	...
```

Once you have done this, there is nothing more that you MUST do. Laravel application locale has been set and you can use other locale-dependant Laravel components (e.g. Translation) as you normally do.

### Middleware

[](#middleware)

If you want to enforce the use of a language subdomain for some routes, you can simply assign the middleware provided, for example as follows in `app/Http/routes.php`:

```
    // Without the localize middleware, this route can be reached with or without language subdomain
    Route::get('logout', 'AuthController@logout');

    // With the localize middleware, this route cannot be reached without language subdomain
    Route::group([ 'middleware' => [ 'localize' ]], function() {

        Route::get('welcome', 'WelcomeController@index');

    });
```

For more information about Middleware, please refer to [Laravel docs](http://laravel.com/docs/middleware).

### Route translation

[](#route-translation)

If you want to use translated routes (en.yourdomain.com/welcome, fr.yourdomain.com/bienvenue), proceed as follows:

First, create language files for the languages that you support:

`resources/lang/en/routes.php`:

```
    return [

        // route name => route translation
        'welcome' => 'welcome',
        'user_profile' => 'user/{username}',

    ];
```

`resources/lang/fr/routes.php`:

```
    return [

        // route name => route translation
        'welcome' => 'bienvenue',
        'user_profile' => 'utilisateur/{username}',

    ];
```

Then, here is how you define translated routes in `app/Http/routes.php`:

```
    Route::group([ 'middleware' => [ 'localize' ]], function() {

        Route::get(Router::resolve('routes.welcome'), 'WelcomeController@index');

    });
```

You can of course name the language files as you wish, and pass the proper prefix (routes. in the example) to the resolve() method.

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

[](#configuration)

### Configuration file

[](#configuration-file)

In order to edit the default package configuration, you can run the following artisan command:

```
php artisan vendor:publish --provider="LaurentEsc\Localization\LocalizationServiceProvider" --tag="config"

```

Once you have done that, you will find the config file at `config/localization.php`.

### Configuration values

[](#configuration-values)

- `available_locales` (default: `['en', 'de']`)

An array of the locales accepted by the routing system.

- `cookie_localization` (default: `true`)

Use this option to enable or disable the use of cookies during the locale detection.

- `browser_localization` (default: `true`)

Use this option to enable or disable the use of the browser settings during the locale detection.

- `cookie_name` (default: `'locale'`)

Here you may change the name of the cookie used to save the locale. This option is used only if localization with cookie is enabled.

- `domain` (default: `env('DOMAIN')`)

Here you may change the name of the domain used in your application. By default, the domain is read from the .env file.

Useful functions
----------------

[](#useful-functions)

The package provides useful functions that you can use - for example - in your views:

### Translate current URL

[](#translate-current-url)

```
    See the french version
```

Use `Router::current(string $locale)` this to generate an alternate version of the current route. This will return an url with the proper subdomain and also translate the uri if necessary.

### Get alternate versions of the current URL

[](#get-alternate-versions-of-the-current-url)

```
    @foreach (Router::getCurrentVersions() as $locale => $url)
    {{ $locale }}
    @endforeach
```

Use `Router::getCurrentVersions(bool $excludeCurrentLocale = true)` to fetch all localized versions of the current route. This will return an array of $locale =&gt; $url items that you can use to generate links to alternate versions.

You can pass `false` as parameter for `$excludeCurrentLocale` to let function also returns an item for the current locale.

### Get localized version for a given route

[](#get-localized-version-for-a-given-route)

```
    See JohnDoe's profile
```

Use `Router::url($routeName, $routeAttributes = null, $locale = null)` to generate an alternate version of the given route. This will return an url with the proper subdomain and also translate the uri if necessary.

You can pass route parameters if necessary. If you don't give a specific locale, it will use the current locale.

### Changelog

[](#changelog)

To see what has changed in recent versions, see the [CHANGELOG](https://github.com/LaurentEsc/Laravel-Subdomain-Localization/blob/master/CHANGELOG.md).

### License

[](#license)

This package is licensed under the [MIT license](https://github.com/LaurentEsc/Laravel-Subdomain-Localization/blob/master/LICENSE).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.7% 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

Unknown

Total

1

Last Release

3927d ago

### Community

Maintainers

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

---

Top Contributors

[![LaurentEsc](https://avatars.githubusercontent.com/u/5583887?v=4)](https://github.com/LaurentEsc "LaurentEsc (29 commits)")[![believer-ufa](https://avatars.githubusercontent.com/u/801727?v=4)](https://github.com/believer-ufa "believer-ufa (1 commits)")

---

Tags

laravellaravel-5-packagelocalizationmiddlewaresubdomainphplaravellocalizationsubdomain

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laurentesc-laravel-subdomain-localization/health.svg)

```
[![Health](https://phpackages.com/badges/laurentesc-laravel-subdomain-localization/health.svg)](https://phpackages.com/packages/laurentesc-laravel-subdomain-localization)
```

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M112](/packages/mcamara-laravel-localization)[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M16](/packages/josiasmontag-laravel-redis-mock)[pmochine/laravel-tongue

🎉 Finally a subdomain localization that works how you want it to work. 🌐

4158.4k](/packages/pmochine-laravel-tongue)[josiasmontag/laravel-localization

Localization for Laravel framework

2336.2k](/packages/josiasmontag-laravel-localization)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)

PHPackages © 2026

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