PHPackages                             cheecodes/language-detection - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cheecodes/language-detection

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

cheecodes/language-detection
============================

1.0.1(5y ago)12081MITPHPPHP ^7.1

Since Apr 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/cheecodes/language-detection)[ Packagist](https://packagist.org/packages/cheecodes/language-detection)[ Docs](https://github.com/cheecodes/language-detection)[ RSS](/packages/cheecodes-language-detection/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

Laravel Language Loader
=======================

[](#laravel-language-loader)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ccbb795a2ecbe010d09d7369fca9ed14fae0fb2344bc92a29a3f9f5109f42284/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63686565636f6465732f6c616e67756167652d646574656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cheecodes/language-detection)[![Total Downloads](https://camo.githubusercontent.com/05a35c5799bbc3e209e856e32394c0a3f656fb1e6e0ac797c67f86771d20ec51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63686565636f6465732f6c616e67756167652d646574656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cheecodes/language-detection)

This package allows you to set the application language based on request parameters like Accept-Language, a cookie, the session values. You can easily extend the detection with your own loaders aswell.

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

[](#installation)

You can install the package via composer:

```
composer require cheecodes/language-detection
```

You should then publish the config

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

#### Globally

[](#globally)

If you want to use the Middleware globally, you can register it in `App\Http\Kernel` like this

```
protected $middleware = [
        // ...
        DetectLanguage::class,
        // ...
    ];
```

#### Aliasing

[](#aliasing)

To use an alias for this middleware, register it in your `$routeMiddleware` in the Kernel

```
protected $routeMiddleware = [
    // ...
    'language' => DetectLanguage::class,
    // ...
];
```

#### Different stack of loaders

[](#different-stack-of-loaders)

The `DetectLanguage` Middleware accepts a parameter that determines the group of loaders to be used. Those groups can be defined in the config like this:

```
'loaders'   => [
    // Default group
    'default' => [
        FromHeader::class,
        FromQueryParameter::class,
        FromSession::class,
        FromCookie::class,
    ],
    // custom group
    'custom' => [
        FromHeader::class,
    ]
],
```

The names can be chosen as you see fit.

To use your custom loader stack, I firstly recommend you alias the middleware to something like `language`. You can then use it in your routes file like this:

```
Route::group('/admin', function() {
    // Your routes go here
})->middleware('language:custom'); // Changing the loader stack to "custom"
```

#### Writing your own loader

[](#writing-your-own-loader)

Writing your own loader is straightforward. All you need to do is write a class that implements `CheeCodes\LanguageDetection\Loader\LoaderContract`. This interface only exposes one single method:

```
public function load(Request $request, array $config): ?string
```

All you need to do is return a language key if your loader matched, or `null` if it didn't.

If you return a string and that string is in the allowed languages array, loader processing is stopped.

If you return null, the next loader is called or the default language is used if no further loader is in the current stack.

To register your custom loader, just add the FQDN to the loader stack:

```
'loaders' => [
    'default' => [
        // ...
        Acme\Loaders\MyCustomLoader::class,
    ]
];
```

The loaders are resolved with Laravels IoC Container, so you can easily use constructor injection like you're used to.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Fabian Bettag](https://github.com/cheecodes)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~30 days

Total

2

Last Release

2182d ago

### Community

Maintainers

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

---

Top Contributors

[![Jigsaw5279](https://avatars.githubusercontent.com/u/3465075?v=4)](https://github.com/Jigsaw5279 "Jigsaw5279 (4 commits)")[![Sentor77](https://avatars.githubusercontent.com/u/5848360?v=4)](https://github.com/Sentor77 "Sentor77 (1 commits)")

---

Tags

laravellaravel-packagelaravel6laravel7phplanguage detectioncheecodes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cheecodes-language-detection/health.svg)

```
[![Health](https://phpackages.com/badges/cheecodes-language-detection/health.svg)](https://phpackages.com/packages/cheecodes-language-detection)
```

###  Alternatives

[nitotm/efficient-language-detector

Fast and accurate natural language detection. Detector written in PHP. Nito-ELD, ELD.

59252.9k6](/packages/nitotm-efficient-language-detector)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

116.6k](/packages/tomshaw-electricgrid)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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