PHPackages                             asbiin/laravel-localizer - 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. asbiin/laravel-localizer

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

asbiin/laravel-localizer
========================

Automatically detect and set an app locale that matches your visitor's preference.

4.0.0(1y ago)020.7k↓22.1%MITPHPPHP ^8.1CI failing

Since Mar 11Pushed 1mo agoCompare

[ Source](https://github.com/asbiin/laravel-localizer)[ Packagist](https://packagist.org/packages/asbiin/laravel-localizer)[ Fund](https://paypal.me/ivanvermeyen)[ Fund](https://ko-fi.com/ivanvermeyen)[ RSS](/packages/asbiin-laravel-localizer/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Localizer
=================

[](#laravel-localizer)

[![GitHub release](https://camo.githubusercontent.com/64be56ce8aa14ca9665c5be460daa2efd491a11cac98294c04f4b76830677695/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636f64657a65726f2d62652f6c61726176656c2d6c6f63616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/codezero-be/laravel-localizer/releases)[![Laravel](https://camo.githubusercontent.com/6b439d6929b4963e5e873cdf2ac7d587f60c8730be8590e1ae384897cebc6369/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31312d7265643f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com)[![License](https://camo.githubusercontent.com/170d5f36cc6194e3128db381014e5721533b01ca08f881e0b9a3fe629635f24d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64657a65726f2f6c61726176656c2d6c6f63616c697a65722e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/46393086afe78ae670370622c58186a7439273ac8eed585821af7eadfc272011/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64657a65726f2d62652f6c61726176656c2d6c6f63616c697a65722f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465266c6162656c3d7465737473)](https://github.com/codezero-be/laravel-localizer/actions)[![Code Coverage](https://camo.githubusercontent.com/78e89c1ad8469f4ace57a3f0309760eb0be487e3db78484c4934223bf97a3ce2/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f636f7665726167652f61643666636561313532623434396433383061313837613337356430663764372f6d61737465723f7374796c653d666c61742d737175617265)](https://app.codacy.com/gh/codezero-be/laravel-localizer)[![Code Quality](https://camo.githubusercontent.com/6106bc0032e3320ebb072a28619125231fb9bc023a393f8006470aff67ae4114/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f61643666636561313532623434396433383061313837613337356430663764372f6d61737465723f7374796c653d666c61742d737175617265)](https://app.codacy.com/gh/codezero-be/laravel-localizer)[![Total Downloads](https://camo.githubusercontent.com/9260423193dea3ef0fa5a7245f5f21b13e7c26964bb5a56328f51ab29cd53c4b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64657a65726f2f6c61726176656c2d6c6f63616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codezero/laravel-localizer)

[![ko-fi](https://camo.githubusercontent.com/1fedf764fa06114b797ee53e7506df10880abed6766f854202d758df1707969d/68747470733a2f2f7777772e6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/R6R3UQ8V)

Automatically detect and set an app locale that matches your visitor's preference.

- Define your supported locales and match your visitor's preference
- Uses the most common locale [detectors](#-detectors) by default
- Uses the most common locale [stores](#-stores) by default
- Easily create and add your own detectors and stores

✅ Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10.0

⬆ Upgrade
---------

[](#-upgrade)

Upgrading to a new major version? Check our [upgrade guide](UPGRADE.md) for instructions.

📦 Install
---------

[](#-install)

Install this package with Composer:

```
composer require asbiin/laravel-localizer
```

Laravel will automatically register the ServiceProvider.

🧩 Add Middleware
----------------

[](#-add-middleware)

By default, the app locale will always be what you configured in `config/app.php`. To automatically update the app locale, you need to register the middleware in the `web` middleware group. Make sure to add it after `StartSession` and before `SubstituteBindings`.

The order of the middleware is important if you are using localized route keys (translated slugs)! The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.

### Laravel 11 and newer:

[](#laravel-11-and-newer)

Add the middleware to the `web` middleware group in `bootstrap/app.php`.

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(remove: [
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ]);
    $middleware->web(append: [
        \CodeZero\Localizer\Middleware\SetLocale::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ]);
})
```

### Laravel 10:

[](#laravel-10)

Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.

```
// app/Http/Kernel.php
protected $middlewareGroups = [
    'web' => [
        //...
        \Illuminate\Session\Middleware\StartSession::class, //  ['en', 'nl'];
```

By default, the `UrlDetector` will look for these locales in the URL.

You can also use one or more custom slugs for a locale:

```
'supported_locales' => [
    'en' => 'english-slug',
    'nl' => ['dutch-slug', 'nederlandse-slug'],
];
```

Or you can use one or more custom domains for a locale:

```
'supported_locales' => [
    'en' => 'english-domain.test',
    'nl' => ['dutch-domain.test', 'nederlands-domain.test'],
];
```

🔍 Detectors
-----------

[](#-detectors)

By default, the middleware will use the following detectors to check for a supported locale in:

\#DetectorDescription1.`RouteActionDetector`Checks for a locale in a custom route action.2.`UrlDetector`Tries to find a locale based on the URL slugs or domain.3.`OmittedLocaleDetector`Required if an omitted locale is configured. This will always be used.4.`UserDetector`Checks a configurable `locale` attribute on the authenticated user.5.`SessionDetector`Checks the session for a previously stored locale.6.`CookieDetector`Checks a cookie for a previously stored locale.7.`BrowserDetector`Checks the preferred language settings of the visitor's browser.8.`AppDetector`Checks the default app locale as a last resort.Update the `detectors` array in the config file to choose which detectors to run and in what order.

> You can create your own detector by implementing the `CodeZero\Localizer\Detectors\Detector` interface and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

💾 Stores
--------

[](#-stores)

The first supported locale that is returned by a detector will automatically be stored in:

\#StoreDescription1.`SessionStore`Stores the locale in the session.2.`CookieStore`Stores the locale in a cookie.3.`AppStore`Sets the locale as the active app locale.Update the `stores` array in the config file to choose which stores to use.

> You can create your own store by implementing the `CodeZero\Localizer\Stores\Store` interface and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

🛠 More Configuration
--------------------

[](#-more-configuration)

### ☑ `omitted_locale`

[](#-omitted_locale)

If you don't want your main locale to have a slug, you can set it as the `omitted_locale` (not the custom slug).

If you do this, no additional detectors will run after the `UrlDetector` and `OmittedLocaleDetector`. This makes sense, because the locale will always be determined by those two in this scenario.

Example:

```
'omitted_locale' => 'en',
```

Result:

- /example-route (English without slug)
- /nl/example-route (Other locales with slug)

Default: `null`

### ☑ `trusted_detectors`

[](#-trusted_detectors)

Add any detector class name to this array to make it trusted. (do not remove it from the `detectors` array) When a trusted detector returns a locale, it will be used as the app locale, regardless if it's a supported locale or not.

Default: `[]`

### ☑ `url_segment`

[](#-url_segment)

The index of the URL segment that has the locale, when using the `UrlDetector`.

Default: `1`

### ☑ `route_action`

[](#-route_action)

The custom route action that holds the locale, when using the `RouteActionDetector`.

Default: `locale`

To use the custom route action `locale`, you register a route like this:

```
Route::group(['locale' => 'nl'], function () {
    //Route::get(...);
});
```

### ☑ `user_attribute`

[](#-user_attribute)

The attribute on the user model that holds the locale, when using the `UserDetector`. If the user model does not have this attribute, this detector check will be skipped.

Default: `locale`

### ☑ `session_key`

[](#-session_key)

The session key that holds the locale, when using the `SessionDetector` and `SessionStore`.

Default: `locale`

### ☑ `cookie_name`

[](#-cookie_name)

The name of the cookie that holds the locale, when using the `CookieDetector` and `CookieStore`.

Default: `locale`

### ☑ `cookie_minutes`

[](#-cookie_minutes)

The lifetime of the cookie that holds the locale, when using the `CookieStore`.

Default: `60 * 24 * 365` (1 year)

🚧 Testing
---------

[](#-testing)

```
composer test
```

☕ Credits
---------

[](#-credits)

- [Ivan Vermeyen](https://github.com/ivanvermeyen)
- [All contributors](https://github.com/codezero-be/laravel-localizer/contributors)

🔒 Security
----------

[](#-security)

If you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.

📑 Changelog
-----------

[](#-changelog)

A complete list of all notable changes to this package can be found on the [releases page](https://github.com/codezero-be/laravel-localizer/releases).

📜 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance70

Regular maintenance activity

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

433d ago

### Community

Maintainers

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

---

Top Contributors

[![ivanvermeyen](https://avatars.githubusercontent.com/u/3598622?v=4)](https://github.com/ivanvermeyen "ivanvermeyen (64 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (5 commits)")[![asbiin](https://avatars.githubusercontent.com/u/25419741?v=4)](https://github.com/asbiin "asbiin (3 commits)")[![zepfietje](https://avatars.githubusercontent.com/u/44533235?v=4)](https://github.com/zepfietje "zepfietje (1 commits)")

---

Tags

phpbrowserlaravellocalizationlanguagesessionlocalecookiecountrydetect

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asbiin-laravel-localizer/health.svg)

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

###  Alternatives

[codezero/laravel-localizer

Automatically detect and set an app locale that matches your visitor's preference.

50394.3k4](/packages/codezero-laravel-localizer)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[codezero/browser-locale

Get the most preferred locales from your visitor's browser.

161.4M13](/packages/codezero-browser-locale)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[vluzrmos/language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.

109554.8k3](/packages/vluzrmos-language-detector)

PHPackages © 2026

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