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

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

industryarena/laravel-subdomain-localization
============================================

Subdomain localization support for Laravel

08.7k1PHP

Since Jun 26Pushed 2y ago3 watchersCompare

[ Source](https://github.com/industryarena/Laravel-Subdomain-Localization)[ Packagist](https://packagist.org/packages/industryarena/laravel-subdomain-localization)[ RSS](/packages/industryarena-laravel-subdomain-localization/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-subdomain-localization)

[![Latest Stable Version](https://camo.githubusercontent.com/f6153d928df7d4b2749ac4b816a4026fe6a0f3856230fe7eadb9f8b189450716/68747470733a2f2f706f7365722e707567782e6f72672f696e6475737472796172656e612f6c61726176656c2d737562646f6d61696e2d6c6f63616c697a6174696f6e2f76657273696f6e)](https://packagist.org/packages/industryarena/laravel-subdomain-localization) [![Total Downloads](https://camo.githubusercontent.com/28cea85f6e7e9a50ea116ffb0497e538b8e2b302e6ca8acec426d55a7f685322/68747470733a2f2f706f7365722e707567782e6f72672f696e6475737472796172656e612f6c61726176656c2d737562646f6d61696e2d6c6f63616c697a6174696f6e2f642f746f74616c2e706e67)](https://packagist.org/packages/industryarena/laravel-subdomain-localization)[![Build Status](https://camo.githubusercontent.com/54cf8f5a6069c79d9dbc9b932e8e71b76ea27a550eefa89c87e04c33b376c63b/68747470733a2f2f6170692e7472617669732d63692e6f72672f696e6475737472796172656e612f4c61726176656c2d537562646f6d61696e2d4c6f63616c697a6174696f6e2e706e67)](https://travis-ci.org/industryarena/Laravel-Subdomain-Localization)

Subdomain localization support for Laravel. Only for **Laravel 5.4** Version (Fork [LaurentEsc/Laravel-Subdomain-Localization](https://github.com/LaurentEsc/Laravel-Subdomain-Localization))

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.

```
"industryarena/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/industryarena/Laravel-Subdomain-Localization/blob/master/CHANGELOG.md).

### License

[](#license)

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

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/0472dc30fb5080c1ea5c4b46ef871bff216e476fed894731242b0fb3c69e6c2a?d=identicon)[approached](/maintainers/approached)

---

Top Contributors

[![LaurentEsc](https://avatars.githubusercontent.com/u/5583887?v=4)](https://github.com/LaurentEsc "LaurentEsc (25 commits)")[![approached](https://avatars.githubusercontent.com/u/3439330?v=4)](https://github.com/approached "approached (9 commits)")[![johannebert](https://avatars.githubusercontent.com/u/19428345?v=4)](https://github.com/johannebert "johannebert (4 commits)")[![gkermer](https://avatars.githubusercontent.com/u/8224376?v=4)](https://github.com/gkermer "gkermer (3 commits)")[![dgrempka](https://avatars.githubusercontent.com/u/52920526?v=4)](https://github.com/dgrempka "dgrempka (1 commits)")

### Embed Badge

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

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

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

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