PHPackages                             pmochine/laravel-tongue - 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. pmochine/laravel-tongue

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

pmochine/laravel-tongue
=======================

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

5.0.0(3y ago)4158.4k8[8 issues](https://github.com/pmochine/Laravel-Tongue/issues)MITPHPPHP ^7.4 || ^8.1CI failing

Since Jul 14Pushed 3y ago6 watchersCompare

[ Source](https://github.com/pmochine/Laravel-Tongue)[ Packagist](https://packagist.org/packages/pmochine/laravel-tongue)[ RSS](/packages/pmochine-laravel-tongue/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (5)Versions (21)Used By (0)

Laravel Tongue 👅 - Multilingual subdomain URLs and redirects
============================================================

[](#laravel-tongue----multilingual-subdomain-urls-and-redirects)

[![Build Status](https://camo.githubusercontent.com/c87e1f4c2724fc2436abb26ebcaaf3fe12e052b4e3044adedb59e7b54a7cb771/68747470733a2f2f7472617669732d63692e6f72672f706d6f6368696e652f4c61726176656c2d546f6e6775652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pmochine/Laravel-Tongue)[![styleci](https://camo.githubusercontent.com/6d1afbfe2b93a3166cc5763359771ad262c61f0fb154f6e856d72963647c12b7/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134303935343330302f736869656c64)](https://styleci.io/repos/140954300)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/22ff922fcbbf01a4f4b4a67d9803a7e40ef407e79a8203447a92304d4f021776/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f706d6f6368696e652f6c61726176656c2d746f6e6775652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pmochine/laravel-tongue/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/279cb1626f51e542df96e4e5378a6eb39631f543e57a021f38863ff378edfc67/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f706d6f6368696e652f4c61726176656c2d546f6e6775652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/pmochine/Laravel-Tongue?branch=master)

[![Packagist](https://camo.githubusercontent.com/5a5d6ec12ed75414081a596cb40d5d26a5e35fb9c47385c3fc3fd0d53354b8db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706d6f6368696e652f6c61726176656c2d746f6e6775652e737667)](https://packagist.org/packages/pmochine/laravel-tongue)[![Packagist](https://camo.githubusercontent.com/8e619b207dd4c5ddbbb930c4477faaddd2c2819936356e698abce1ba30f3be8f/68747470733a2f2f706f7365722e707567782e6f72672f706d6f6368696e652f6c61726176656c2d746f6e6775652f642f746f74616c2e737667)](https://packagist.org/packages/pmochine/laravel-tongue)[![Packagist](https://camo.githubusercontent.com/3fd7887e8988b21551a8eaceb11d5ca87ca28c6175029ee6d740a41dabb20461/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706d6f6368696e652f6c61726176656c2d746f6e6775652e737667)](https://packagist.org/packages/pmochine/laravel-tongue)

[![Laravel Tongue](img/laravel-tongue.png)](img/laravel-tongue.png)

**If you are looking for an easy package for subdomain multilingual URLs, this package is for you. 😜**

**Old Way**: `https://example.com/de`, `https://example.com/fr` etc.
**New Way**: `https://de.example.com`, `https://fr.example.com` etc.

> \***Prerequisites**: PHP ^7.4 || ^8.1 and Laravel ^8.41 || PHP ^8.0.2 and Laravel ^9.0 and Laravel ^10.0 \***Older Laravel Versions**: [Click here](https://github.com/pmochine/Laravel-Tongue#support-for-laravel-5xx)

Installation in 4 Steps\*
-------------------------

[](#installation-in-4-steps)

### 1: Add with composer 💻

[](#1-add-with-composer-)

```
  composer require pmochine/laravel-tongue
```

### 2: Publish Configuration File (you need to change some things to use it 😎)

[](#2-publish-configuration-file-you-need-to-change-some-things-to-use-it-)

```
  php artisan vendor:publish --provider="Pmochine\LaravelTongue\ServiceProvider" --tag="config"
```

### 3: Add the Middleware 🌐

[](#3-add-the-middleware-)

**Laravel Tongue** comes with a middleware that can be used to enforce the use of a language subdomain. For example the user calls example.com it goes directly to fr.example.com.

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

```
  ...
  'speaks-tongue' => \Pmochine\LaravelTongue\Middleware\TongueSpeaksLocale::class,
  ...
```

### 4: Add in your Env 🔑

[](#4-add-in-your-env-)

```
  APP_DOMAIN=yourdomain.com #Only important for domains with many dots like: '155ad73e.eu.ngrok.io'
  SESSION_DOMAIN=.yourdomain.com #Read down below why
```

**Important!** Note the dot before the domain name. Now the session is available in every subdomain 🙃. This is important because you want to save all your cookie 🍪 data in one place and not in many other.

> \****Note*!** 📝 This step is optional if you use laravel&gt;=5.5 with package auto-discovery feature. Add service provider to `config/app.php` in `providers` section
>
> ```
>    Pmochine\LaravelTongue\ServiceProvider::class,
> ```

Usage - (or to make it runnable 🏃‍♂️)
-------------------------------------

[](#usage---or-to-make-it-runnable-‍️)

### Locale detection 🔍

[](#locale-detection-)

Open `app/Providers/RouteServiceProvider.php` and add this

```
  public function boot()
  {
      // This will guess a locale from the current HTTP request
      // and set the application locale.
      tongue()->detect();

      //If you use Carbon you can set the Locale right here.
      \Carbon\Carbon::setLocale(tongue()->current());

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

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-dependent 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 `routes/web.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' => [ 'speaks-tongue' ]], function() {

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

  });
```

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

### Frontend 😴

[](#frontend-)

```

      @include('layouts.head')

    ...
```

The above `` tag will always have a supported locale and directionality (‘ltr’ or ‘rtl’). The latter is important for right-to-left languages like Arabic and Hebrew since the whole page layout will change for those.

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

[](#configuration)

Once you have imported the config file, you will find it at `config/localization.php`.

**Important**: Before you start changing the values, you still need to set the "main language" of your page. If your main language is `fr`, please add this to your `config/app.php` file under `'fallback_locale' => 'fr',`.

We asume that your fallback language has always translated pages. We get the current locale via four ways:

1. First we determine the local with the subdomain of the URL the user is coming from

If there is no subdomain added, we get the locale from:

2. an already set language cookie
3. or the browsers prefered language
4. or at the end we fall back to the `fallback_locale`

> *Note*: The value `locale` in `config/app.php` has no impact and is going to overwritten by ` tongue()->detect();` in `app/Providers/RouteServiceProvider.php`

### Configuration values

[](#configuration-values)

- `domain` (default: `null`)

You don't need to worry about this, only when you are using domains with multiple dots, like: `155ad73e.eu.ngrok.io`. Without it, we cannot check what your subdomain is.

- `beautify_url` (default: `true`)

Makes the URL BEAUTIFUL 💁‍♀️. ( Use to set fallback language to mydomain.com and not to en.mydomain.com). That is why I even created this package. I just could not find this! 😭

- `subdomains` (default: `[]`)

Sometimes you would like to have your admin panel as a subdomain URL. Here you can whitelist those subdomains (only important if those URLs are using the [middleware](https://github.com/pmochine/Laravel-Tongue#middleware-)).

- `aliases` (default: `[]`) Sometimes you would like to specify aliases to use custom subdomains instead of locale codes. For example:

```
  gewinnen.domain.com --> "de"
  gagner.domain.com --> "fr",

```

- `acceptLanguage` (default: `true`)

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

- `cookie_localization` (default: `true`)

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

- `cookie_serialize` (default: `false`)

If you have not changed anything in your middleware "EncryptCookies", you don't need to change anything here as well. [More](https://laravel.com/docs/5.6/upgrade#upgrade-5.6.30)

- `prevent_redirect` (default: `false`)

Important for debugging, when you want to deactivate the middleware `speaks-tongue`.

- `supportedLocales` (default: `🇬🇧🇩🇪🇪🇸🇫🇷🇭🇺`)

Don't say anyone that I copied it from [mcamara](https://github.com/mcamara/laravel-localization) 🤫

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 `routes/web.php`:

```
  Route::group([ 'middleware' => [ 'speaks-tongue' ]], function() {

      Route::get(dialect()->interpret('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 interpret() method.

Helper Functions - (finally something useful 😎)
-----------------------------------------------

[](#helper-functions---finally-something-useful-)

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

### Translate your current URL into the given language

[](#translate-your-current-url-into-the-given-language)

```
  See the french version
```

### Get all translated URL except the current URL

[](#get-all-translated-url-except-the-current-url)

```
  @foreach (dialect()->translateAll(true) as $locale => $url)
      {{ $locale }}
  @endforeach
```

You can pass `false` as parameter so it won't exclude the current URL.

### Translate URL to the language you want

[](#translate-url-to-the-language-you-want)

```
  See JohnDoe's profile
  // Result: https://fr.example.com/utilisateur/JohnDoe
```

> Remember: Set the translation in the lang folder

Use `dialect()->translate($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 ☺️.

### Redirect URL to the language you want

[](#redirect-url-to-the-language-you-want)

```
  See Homepage in French
  // Result: https://fr.example.com
```

Use `dialect()->redirectUrl($url = null, $locale = null);` to redirect for example to the same URL but in different locale. ***Warning***: Works only when the paths are not translated. Use `dialect()->translate()` for that.

### Get your config supported locale list

[](#get-your-config-supported-locale-list)

```
  $collection = tongue()->speaking(); //returns collection
```

Remember it returns a collection. You can add methods to it ([see available methods](https://laravel.com/docs/5.6/collections#available-methods)) Examples:

```
  $keys = tongue()->speaking()->keys()->all(); //['en','de',..]
  $sorted = tongue()->speaking()->sort()->all(); //['de','en',..]
```

Additionally, you can even get some addtional information:

```
  tongue()->speaking('BCP47', 'en'); // en-GB
  tongue()->speaking('subdomains'); // ['admin']
  tongue()->speaking('subdomains', 'admin'); // true
  tongue()->speaking('aliases'); // ['gewinnen' => 'de', 'gagner' => 'fr]
  tongue()->speaking('aliases', 'gewinnen'); //' de'
```

### Get the current language that is set

[](#get-the-current-language-that-is-set)

```
  $locale = tongue()->current(); //de
```

Or if you like you can get the full name, the alphabet script, the native name of the language &amp; the regional code.

```
  $name = tongue()->current('name'); //German
  $script = tongue()->current('script'); //Latn
  $native = tongue()->current('native'); //Deutsch
  $regional = tongue()->current('regional'); //de_DE
```

How to Switch Up the Language 🇬🇧-&gt;🇩🇪
---------------------------------------

[](#how-to-switch-up-the-language--)

For example with a selector:

```

      @foreach(tongue()->speaking()->all() as $localeCode => $properties)

                  {{ $properties['native'] }}

      @endforeach

```

Or in a controller far far away...

```
  /**
   * Sets the locale in the app
   * @return redirect to previous url
   */
  public function store()
  {
    $locale = request()->validate([
      'locale' => 'required|string|size:2'
    ])['locale'];

    return tongue()->speaks($locale)->back();
  }
```

Upgrade Guide 🎢
---------------

[](#upgrade-guide-)

### Upgrade to 2.x.x from 1.x.x

[](#upgrade-to-2xx-from-1xx)

There are little changes that might be important for you.

- We added two new config elements in localization. `domain` and `aliases`. Add these like [here](https://github.com/pmochine/Laravel-Tongue/blob/master/config/localization.php).
- Add `APP_DOMAIN` in your .env if you have a complicated domain, like: `155ad73e.eu.ngrok.io`
- Now you are able to use aliases in your subdomain. For example: `gewinnen.domain.com --> "de"`
- If a subdomain is invalid, it returns to the latest valid locale subdomain.

### Support for Laravel 9.x.x

[](#support-for-laravel-9xx)

If you want to use:

> PHP &lt;=8.0 and Laravel 9.x.x

you need to download the version 4.0.0.

```
  composer require pmochine/laravel-tongue:4.0.0
```

### Support for Laravel 7.22.0 up to Laravel 8.41.0

[](#support-for-laravel-7220-up-to-laravel-8410)

If you want to use:

> PHP &gt;=7.3 and at least 7.22.0 &lt;= Laravel &lt;=8.41.0

you need to download the version 3.0.0.

```
  composer require pmochine/laravel-tongue:3.0.0
```

### Support for Laravel 6.x.x up to Laravel 7.21.0

[](#support-for-laravel-6xx-up-to-laravel-7210)

If you want to use:

> PHP &gt;=7.2 and at least 6.x.x &lt;= Laravel &lt;=7.21.0

you need to download the version 2.2.1 or lower.

```
  composer require pmochine/laravel-tongue:2.2.1
```

### Support for Laravel 5.x.x

[](#support-for-laravel-5xx)

If you want to use:

> PHP &gt;=7.0 and at least 5.4 &lt;= Laravel &lt;=5.8

you need to download the version 2.0.0 or lower.

```
  composer require pmochine/laravel-tongue:2.0.0
```

Security
--------

[](#security)

If you discover any security related issues, please don't email me. I'm afraid 😱.

Credits
-------

[](#credits)

Now comes the best part! 😍 This package is based on

-
-

Oh come on. You read everything?? If you liked it so far, hit the ⭐️ button to give me a 🤩 face.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 68.8% 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 ~89 days

Recently: every ~234 days

Total

20

Last Release

1160d ago

Major Versions

1.0.8 → 2.0.02019-04-28

2.3.1 → 3.0.02020-09-09

3.1.0 → 4.0.02022-04-11

4.0.0 → 5.0.02023-03-10

PHP version history (5 changes)1.0.0PHP &gt;=7.0

2.1.0PHP &gt;=7.2

3.0.0PHP &gt;=7.3

3.1.0PHP ^7.4 || ^8.0

5.0.0PHP ^7.4 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e68dd3cd66bd504c0db12a3f51357324b35f1a7807344af63e9a556dac96732?d=identicon)[pmochine](/maintainers/pmochine)

---

Top Contributors

[![pmochine](https://avatars.githubusercontent.com/u/25006691?v=4)](https://github.com/pmochine "pmochine (11 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![pschocke](https://avatars.githubusercontent.com/u/26882621?v=4)](https://github.com/pschocke "pschocke (1 commits)")[![ruban-s](https://avatars.githubusercontent.com/u/44894135?v=4)](https://github.com/ruban-s "ruban-s (1 commits)")[![web-ruslan](https://avatars.githubusercontent.com/u/22293750?v=4)](https://github.com/web-ruslan "web-ruslan (1 commits)")

---

Tags

laravellocalizationmiddlewarepackagesubdomaintonguelaravellocalizationi18nlanguagepackagesubdomaintongue

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pmochine-laravel-tongue/health.svg)

```
[![Health](https://phpackages.com/badges/pmochine-laravel-tongue/health.svg)](https://phpackages.com/packages/pmochine-laravel-tongue)
```

###  Alternatives

[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M16](/packages/josiasmontag-laravel-redis-mock)[longman/laravel-multilang

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

5514.4k1](/packages/longman-laravel-multilang)[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)[laurentesc/laravel-subdomain-localization

Subdomain localization support for Laravel

1911.3k](/packages/laurentesc-laravel-subdomain-localization)[jrmajor/laravel-fluent

Fluent translations for Laravel

208.4k](/packages/jrmajor-laravel-fluent)

PHPackages © 2026

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