PHPackages                             benconstable/laravel-localize-middleware - 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. benconstable/laravel-localize-middleware

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

benconstable/laravel-localize-middleware
========================================

Configurable localization middleware for your Laravel &gt;=5.1 application

v1.2.1(8y ago)9231.4k11[2 issues](https://github.com/BenConstable/laravel-localize-middleware/issues)[3 PRs](https://github.com/BenConstable/laravel-localize-middleware/pulls)MITPHPPHP &gt;=5.5.9

Since Apr 20Pushed 6y ago2 watchersCompare

[ Source](https://github.com/BenConstable/laravel-localize-middleware)[ Packagist](https://packagist.org/packages/benconstable/laravel-localize-middleware)[ Docs](https://github.com/BenConstable/laravel-localize-middleware)[ RSS](/packages/benconstable-laravel-localize-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Laravel Localize Middleware
===========================

[](#laravel-localize-middleware)

> Configurable localization middleware for your Laravel &gt;=5.1 application.

[![Build Status](https://camo.githubusercontent.com/ecee6c7b79b22810c1badbb651aa2a90792c1e060b369aa9696917e96a6ca8a2/68747470733a2f2f7472617669732d63692e6f72672f42656e436f6e737461626c652f6c61726176656c2d6c6f63616c697a652d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BenConstable/laravel-localize-middleware)[![Latest Stable Version](https://camo.githubusercontent.com/b42d66d7343dd0cf2657178417158001071abdd1b2dfe8ef6c7372e447562af6/68747470733a2f2f706f7365722e707567782e6f72672f62656e636f6e737461626c652f6c61726176656c2d6c6f63616c697a652d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/benconstable/laravel-localize-middleware)[![License](https://camo.githubusercontent.com/07c2aa1fc33b619dc6e313653b60c115495cc968844dec69ff4eeccd0096b690/68747470733a2f2f706f7365722e707567782e6f72672f62656e636f6e737461626c652f6c61726176656c2d6c6f63616c697a652d6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/benconstable/laravel-localize-middleware)

This package provides a simple set of configuration and middleware to allow you to automatically set your application's locale using the current request. You can set the locale from a request parameter, header, the current host, a cookie or session data.

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

[](#installation)

Install the package via Composer:

```
$ composer require benconstable/laravel-localize-middleware

```

Next, add the package's service provider to your `config/app.php`:

```
// config/app.php

'providers' => [
    BenConstable\Localize\LocalizeServiceProvider::class
]
```

and then you'll just need to publish the package's configuration:

```
$ php artisan vendor:publish --provider="BenConstable\Localize\LocalizeServiceProvider"

```

which will create `config/localize-middleware.php`.

Usage
-----

[](#usage)

Out-of-the-box, the package is configured to set the application locale using a request parameter called `locale` (see the next section for more info). To enable this functionality, just [register the provided middleware](https://laravel.com/docs/5.4/middleware#registering-middleware) in your `app/Http/Kernel.php` class:

```
// app/Http/Kernel.php

protected $middleware = [
    \BenConstable\Localize\Http\Middleware\Localize::class
];
```

It's recommended to set this middleware globally and early in the stack, but you're free to register it in whatever way that suits your needs.

### Configuration

[](#configuration)

Configuration can be found at `config/localize-middleware.php`. From there, you can configure which localization determiner you'd like to use in your application and set options for it. You simply have to change the `driver` option.

The list of available determiners is shown below.

### Determining the locale from a request parameter

[](#determining-the-locale-from-a-request-parameter)

**Driver name:** `parameter`

The default determiner sets the application locale from a request parameter called `locale`. You can change this using the `parameter` configuration option.

The parameter will be discovered in the query string or request body.

### Determining the locale from a request header

[](#determining-the-locale-from-a-request-header)

**Driver name:** `header`

This determiner sets the application locale from a request header, which defaults to `Accept-Language`. You can change this using the `header` configuration option.

*Aside:* For information on using `Accept-Language` to determine the locale, see [this info from the W3C](https://www.w3.org/International/questions/qa-accept-lang-locales).

### Determining the locale using the current host

[](#determining-the-locale-using-the-current-host)

**Driver name:** `host`

This determiner sets a different application locale depending on the current host. You'll need to set a map of your application's locales to hosts using the `hosts`configuration option.

### Determining the locale from a cookie

[](#determining-the-locale-from-a-cookie)

**Driver name:** `cookie`

This determiner sets the application locale from a cookie called `locale`. You can change this using the `cookie` configuration option.

### Determining the locale from the session

[](#determining-the-locale-from-the-session)

**Driver name:** `session`

This determiner sets the application locale from a session value called `locale`. You can change this using the `session` configuration option.

### Using multiple determiners

[](#using-multiple-determiners)

Sometimes it might be useful to try and determine the locale from more than one source. If you'd like to do this, just set the `driver` configuration option to an array of other driver names. For example:

```
'driver' => [
    'cookie',
    'parameter'
]
```

The locale will then be deteremined from whichever determiner first provides a successful match, so make sure you add the drivers in the correct order (earliest in the array will be used first).

### Determining the locale outside of middleware

[](#determining-the-locale-outside-of-middleware)

You don't have to use the provided middleware if you don't want to. You can instead write your own, or avoid using middleware entirely.

To determine the locale in your own code, first register an alias for the provided facade (which is actually a reference to `BenConstable\Localize\DeterminerManager`, if you want to inject it).

```
// config/app.php

'aliases' => [
    'Localizer' => BenConstable\Localize\DeterminerFacade::class
]
```

Then, you can just do:

```
$locale = Localizer::determineLocale($request);
```

to determine the locale and do with it what you like.

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](https://github.com/BenConstable/laravel-localize-middleware/blob/master/CONTRIBUTING.md).

Other Localization Projects
---------------------------

[](#other-localization-projects)

Here are some other Laravel localization projects that might be useful to you:

- [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization)
- [Waavi/translation](https://github.com/Waavi/translation)
- [caouecs/Laravel-lang](https://github.com/caouecs/Laravel-lang)

License
-------

[](#license)

MIT © Ben Constable 2017. See [LICENSE](https://github.com/BenConstable/laravel-localize-middleware/blob/master/LICENSE) for more info.

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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 ~136 days

Total

4

Last Release

3261d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5daa92fa95390a7879db63309e39f96fd2839aa06914e8bc2a079a2abaf8743a?d=identicon)[BenConstable](/maintainers/BenConstable)

---

Top Contributors

[![BenConstable](https://avatars.githubusercontent.com/u/817029?v=4)](https://github.com/BenConstable "BenConstable (36 commits)")[![bryant1410](https://avatars.githubusercontent.com/u/3905501?v=4)](https://github.com/bryant1410 "bryant1410 (1 commits)")

---

Tags

laravellocalisationlocalizationmiddlewaremiddlewarelaravellocalizelocalise

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/benconstable-laravel-localize-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/benconstable-laravel-localize-middleware/health.svg)](https://phpackages.com/packages/benconstable-laravel-localize-middleware)
```

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M111](/packages/mcamara-laravel-localization)[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

135304.0k2](/packages/vemcogroup-laravel-translation)

PHPackages © 2026

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