PHPackages                             flamix/laravel-lang - 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. flamix/laravel-lang

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

flamix/laravel-lang
===================

Laravel Language Detection.

0480↓35.3%PHP

Since Apr 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/rshkabko/laravel-lang)[ Packagist](https://packagist.org/packages/flamix/laravel-lang)[ RSS](/packages/flamix-laravel-lang/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Lang
============

[](#laravel-lang)

Language detection and switching for Laravel. Uses a driver-based approach: cookies, authenticated user, browser headers, URL prefix.

Install
-------

[](#install)

```
composer require flamix/laravel-lang
```

Publish config:

```
php artisan vendor:publish --provider="Flamix\Lang\ServiceProvider" --tag=config
```

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

[](#configuration)

```
// config/lang.php
return [
    // Auto-register SetLang middleware in "web" group
    'autoload' => env('LANG_AUTOLOAD', true),

    // Available languages
    'available' => [
        'en' => 'English',
        'ru' => 'Русский',
        'ua' => 'Українська',
    ],

    // Detection drivers (checked top to bottom, first match wins)
    'drivers' => [
        'get' => [
            \Flamix\Lang\Drivers\Cookies::class,
            \Flamix\Lang\Drivers\AuthUser::class,  // requires `lang` column on users table
            \Flamix\Lang\Drivers\Browser::class,    // reads Accept-Language header
        ],
        // Where to persist when user switches language
        'set' => [
            \Flamix\Lang\Drivers\Cookies::class,
            \Flamix\Lang\Drivers\AuthUser::class,
        ],
    ],
];
```

Usage
-----

[](#usage)

### Helpers

[](#helpers)

```
// Get current language (runs through detection drivers)
lang()->get(); // "en"

// Set language (persists to all "set" drivers)
lang()->set('ru');

// Generate named route with locale prefix
lang_route('dashboard'); // route("en.dashboard")
```

### Language switcher

[](#language-switcher)

Built-in route to change language via GET request:

```
GET /lang/change/{lang}

```

```
English
Русский
```

Sets the language in all configured `set` drivers and redirects back.

### Middleware

[](#middleware)

Two middlewares are registered automatically:

**`lang-set`** — detects and applies locale. Auto-added to `web` group when `autoload` is `true`.

```
// Manual registration if autoload is disabled
Route::middleware('lang-set')->group(function () {
    // ...
});
```

**`lang-prefix`** — for URL-prefix-based localization (`/en/about`, `/ru/about`). Redirects to prefixed URL if prefix is missing.

```
// routes/web.php
Route::prefix('{lang}')->middleware('lang-prefix')->group(function () {
    Route::get('/about', [AboutController::class, 'index'])->name('about');
});
```

Requires `Prefix` driver in your config:

```
'get' => [
    \Flamix\Lang\Drivers\Prefix::class,
    \Flamix\Lang\Drivers\Cookies::class,
    // ...
],
```

Drivers
-------

[](#drivers)

DriverDetectsPersistsNotes`Cookies``lang` cookieForever cookieDefault, works for guests`AuthUser``auth()->user()->lang`Updates user modelRequires `lang` column`Browser``Accept-Language` header--Read-only, fallback`Prefix`URL first segment (`/en/...`)--Read-only, use with `lang-prefix` middleware### Custom driver

[](#custom-driver)

```
use Flamix\Lang\Drivers\AbstractDriver;
use Flamix\Lang\Drivers\Contracts\DetectInterface;
use Flamix\Lang\Drivers\Contracts\SetInterface;

class SessionDriver extends AbstractDriver implements DetectInterface, SetInterface
{
    public function detect(): ?string
    {
        $lang = session('lang');
        return $this->isAvailable($lang) ? $lang : null;
    }

    public function set(string $lang): mixed
    {
        session(['lang' => $lang]);
        return $lang;
    }
}
```

Add to config:

```
'drivers' => [
    'get' => [SessionDriver::class, ...],
    'set' => [SessionDriver::class, ...],
],
```

`DetectInterface` — for detection only (like `Browser`). Add `SetInterface` if the driver can persist.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance56

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16613944?v=4)[flamix](/maintainers/flamix)[@flamix](https://github.com/flamix)

---

Top Contributors

[![rshkabko](https://avatars.githubusercontent.com/u/33148760?v=4)](https://github.com/rshkabko "rshkabko (9 commits)")

### Embed Badge

![Health badge](/badges/flamix-laravel-lang/health.svg)

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

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)

PHPackages © 2026

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