PHPackages                             swayok/laravel-language-detector - 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. swayok/laravel-language-detector

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

swayok/laravel-language-detector
================================

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

v1.0.20(9y ago)0838MITPHP

Since Jun 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/swayok/laravel-language-detector)[ Packagist](https://packagist.org/packages/swayok/laravel-language-detector)[ RSS](/packages/swayok-laravel-language-detector/feed)WikiDiscussions 1.0 Synced yesterday

READMEChangelog (1)Dependencies (8)Versions (32)Used By (0)

Laravel Language Detector
=========================

[](#laravel-language-detector)

[![Join the chat at https://gitter.im/vluzrmos/laravel-language-detector](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/vluzrmos/laravel-language-detector?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Latest Stable Version](https://camo.githubusercontent.com/e867b4ecfa0d9dc52a272367dab0ef9c54d44df1a110256f181a2a232f9bb583/68747470733a2f2f706f7365722e707567782e6f72672f766c757a726d6f732f6c616e67756167652d6465746563746f722f762f737461626c65)](https://packagist.org/packages/vluzrmos/language-detector)[![Total Downloads](https://camo.githubusercontent.com/fab5ecb8e92f2c42479614a07c90f6dd3c71954081ff05db7a0e61e5b4336725/68747470733a2f2f706f7365722e707567782e6f72672f766c757a726d6f732f6c616e67756167652d6465746563746f722f646f776e6c6f616473)](https://packagist.org/packages/vluzrmos/language-detector)[![License](https://camo.githubusercontent.com/13833b28f3e35901e382e728004bb52f5d4bec512e1fb9083439fc6cf748638b/68747470733a2f2f706f7365722e707567782e6f72672f766c757a726d6f732f6c616e67756167652d6465746563746f722f6c6963656e7365)](https://packagist.org/packages/vluzrmos/language-detector)

[![Build Status](https://camo.githubusercontent.com/d50fe8a8fcff74bbdf8c3786503b2b2e5669ff9e6d2a22ef3060bc5dbce2aada/68747470733a2f2f7472617669732d63692e6f72672f766c757a726d6f732f6c61726176656c2d6c616e67756167652d6465746563746f722e737667)](https://travis-ci.org/vluzrmos/laravel-language-detector)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9b3594685783ef06773667d63fdc6975364d47d317d7686ad5310e708675b031/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766c757a726d6f732f6c61726176656c2d6c616e67756167652d6465746563746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vluzrmos/laravel-language-detector/?branch=master)[![Code Climate](https://camo.githubusercontent.com/9a03414ba96f1b66610bde4a31b166d98a43986d136e862d1d156682acd4e7a5/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f766c757a726d6f732f6c61726176656c2d6c616e67756167652d6465746563746f722f6261646765732f6770612e737667)](https://codeclimate.com/github/vluzrmos/laravel-language-detector)[![Codacy Badge](https://camo.githubusercontent.com/43b5ac361710ab5b2dd84bda7598a9362ab87ba7cca3b988461a4adde3d8415a/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f6630323466623139376531633461323938613533373739346362303737393031)](https://www.codacy.com/app/vluzrmos/laravel-language-detector)[![StyleCI](https://camo.githubusercontent.com/2f1f388cb0f8a23e139708f165e6fa156c33bb42f0d557ce997c73b043f3efe4/68747470733a2f2f7374796c6563692e696f2f7265706f732f33383233313239332f736869656c64)](https://styleci.io/repos/38231293)

This package provides an easy way to detect and apply the language for your application using [browser preferences](#browser-preferences), [subdomains](#subdomains) or [route prefixes](#route-prefixes).

Installation
============

[](#installation)

Require the package using composer:

`composer require vluzrmos/language-detector`

Add the service provider as follows:

Laravel
-------

[](#laravel)

Edit your `config/app.php`:

Insert this line of code **above** the listed RouteServiceProvider, ex:

```
Vluzrmos\LanguageDetector\Providers\LanguageDetectorServiceProvider::class,
App\Providers\RouteServiceProvider::class,

```

> ::class notation is optional.

Lumen
-----

[](#lumen)

Edit the `bootstrap/app.php`:

```
$app->register(Vluzrmos\LanguageDetector\Providers\LanguageDetectorServiceProvider::class);
```

> ::class notation is optional.

Configuration
=============

[](#configuration)

Two options for Laravel, either publish the package conﬁguration using:

```
php artisan vendor:publish

```

then edit the new `conﬁg/lang-detector.php` ﬁle or add the following lines to your .env ﬁle:

```
#Indicates whether the language should be autodetected (can be removed)
LANG_DETECTOR_AUTODETECT=true

#Driver to use, the default is browser
LANG_DETECTOR_DRIVER="browser"

#Segment to use in the uri or subdomain driver, default 0 (can be removed)
LANG_DETECTOR_SEGMENT=0

#Name of cookie to cache the detected language (use false|null to disable)
LANG_DETECTOR_COOKIE=locale

#Comma-separated list of languages provided on the app
LANG_DETECTOR_LANGUAGES="en,fr,pt_BR"

#To alias the language use the notation ":", "=", ":=" or  "=>" to separate the alias and its value.
# LANG_DETECTOR_LANGUAGES="en, en-us:en, pt-br:pt_BR"
```

If you not want to use that, just publish the configurations of the package with `php artisan vendor:publish` and edit on `config/lang-detector.php` generated.

**For Lumen**, consider to copy `vendor/vluzrmos/language-detector/config/lang-detector.php`to your configs dir and use `$app->configure('lang-detector')` before register the `LanguageDetectorServiceProvider`.

Detector Drivers
================

[](#detector-drivers)

There are a few drivers that you might to use, choose one which matches with your application design:

Browser Preferences
-------------------

[](#browser-preferences)

The driver `browser` will try to detect the language of the application based on the request languages (browser preferences). This driver doesn't need any other configuration, just configure the available languages.

Subdomains
----------

[](#subdomains)

The driver `subdomain` will try to detect the language of the application which matches with subdomain of the hostname. eg.:

```
http://fr.site.domain

```

The `subdomain` driver will detect language `fr` and set the application to `fr` if it is one of the available languages in the `lang-detector` conﬁg ﬁle.

> Note: subdomain and uri drivers require [aliases](#aliasing-language-locales) of the the language-locales in the lang-detector conﬁg ﬁle.

Route Prefixes
--------------

[](#route-prefixes)

The driver `uri` will try to detect the language based on the route prefix:

```
http://site.domain/en-us/home

```

That driver will detect en-us and set it to the application. (Note: Consider to [aliase](#aliasing-language-locales) that locale)

And don't worry, if the url is like:

```
http://site.domain/home

```

The language will not be changed, the application will use your default language configured on your `config/app.php` file.

With `uri` driver, your route group needs be like this:

```
//That would be nice if you put (edit) it on your App\Providers\RouteServiceProvider.

// Laravel
Route::group(['prefix' => app('language.routePrefix'), 'namespace' => 'App\Http\Controllers'], function ($router) {
	require __DIR__.'/../Http/routes.php';
});

//For lumen, it should be on bootstrap/app.php.

// Lumen
$app->group(['prefix' => app('language.routePrefix'), 'namespace' => 'App\Http\Controllers'], function ($app) {
   require __DIR__.'/../app/Http/routes.php';
}
```

**Issue**: Lumen 5.0 doesn't support route prefix with empty strings, you should use that script:

```
$prefix = app('language.routePrefix');

$options = [];

if (!empty($prefix) && $prefix!="/") {
    $options['prefix'] = $prefix;
}

// any other options here
$options['namespace'] = 'App\Http\Controllers';

$app->group($options, function () use($app) {
	// ...
});
```

> Note: That is only for Lumen 5.0, the newest version (5.1) already fixes it.

Aliasing language locales
=========================

[](#aliasing-language-locales)

You might to use the style `lang_LOCALE` or just `lang` on your `resources/lang` dir. The language detector driver you have chosen will try to detect the language which matches with `lang` or `lang_LOCALE` available on your `config/lang-detector.php`.

```
'languages' => ['en', 'pt_BR' ...]
```

example:

```
├── lang
│   ├── en
│   │   ├── messages.php
│   │   └── validation.php
│   └── pt_BR
│       ├── messages.php
│       └── validation.php

```

If you are not following that style of languages names or if you are using the `subdomain` or `uri` drivers, just configure it on `config/lang-detector.php` file:

```
'languages' => [
    'pt_BR' => 'pt-BR', //will detect pt_BR language, and set pt-BR to the application,
    'pt' => 'pt-BR', //aliasing, will detect pt and set pt-BR to the application
    'pt-br' => "pt-BR", //aliasing, will detect pt-br and set pt-BR to the application (you will need it with subdomain driver)
    'en', //will detect 'en' language
]
```

or if you are using `.env` instead of config file:

```
#Just put the languages in a comma-separated string.
#To aliase the language use the notation ":", "=", ":=" or  "=>" to separate the alias and its value.
LANG_DETECTOR_LANGUAGES="pt_BR:pt-BR, pt:pt-BR, pt-br:pt-BR, en"

```

Suggestions
===========

[](#suggestions)

The default Laravel language lines are available translated into 51 languages here:

- [caouecs/laravel-lang](https://github.com/caouecs/Laravel-lang)

If you want to translate your models you can use this package:

- [dimsav/laravel-translatable](https://github.com/dimsav/laravel-translatable)

License
=======

[](#license)

MIT.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 94.2% 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 ~54 days

Recently: every ~343 days

Total

30

Last Release

2403d ago

Major Versions

0.2.x-dev → v1.0.02015-07-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a631e17770f1ef26d05cbc896e14b218d186973a00a515eed2d86fbc9eb936a?d=identicon)[sway](/maintainers/sway)

---

Top Contributors

[![vluzrmos](https://avatars.githubusercontent.com/u/450848?v=4)](https://github.com/vluzrmos "vluzrmos (114 commits)")[![swayok](https://avatars.githubusercontent.com/u/629675?v=4)](https://github.com/swayok "swayok (3 commits)")[![bitbeans](https://avatars.githubusercontent.com/u/1482102?v=4)](https://github.com/bitbeans "bitbeans (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![guiguille](https://avatars.githubusercontent.com/u/2471210?v=4)](https://github.com/guiguille "guiguille (1 commits)")[![mbardelmeijer](https://avatars.githubusercontent.com/u/1583095?v=4)](https://github.com/mbardelmeijer "mbardelmeijer (1 commits)")

---

Tags

laraveli18nlanguagelumenlocale

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/swayok-laravel-language-detector/health.svg)

```
[![Health](https://phpackages.com/badges/swayok-laravel-language-detector/health.svg)](https://phpackages.com/packages/swayok-laravel-language-detector)
```

###  Alternatives

[vluzrmos/language-detector

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

109554.8k3](/packages/vluzrmos-language-detector)[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)[longman/laravel-multilang

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

5514.4k1](/packages/longman-laravel-multilang)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)

PHPackages © 2026

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