PHPackages                             alkhatibdev/language-switcher - 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. alkhatibdev/language-switcher

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

alkhatibdev/language-switcher
=============================

Laravel dynamic language switcher for web and api routes

v0.0.2(2y ago)124.2k↑33.3%MITPHP

Since Aug 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/alkhatibdev/language-switcher)[ Packagist](https://packagist.org/packages/alkhatibdev/language-switcher)[ Docs](https://github.com/alkhatibdev/language-switcher)[ RSS](/packages/alkhatibdev-language-switcher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

[![Social Card of Language Switcher Package](https://raw.githubusercontent.com/alkhatibdev/language-switcher/main/socialcard.png)](https://raw.githubusercontent.com/alkhatibdev/language-switcher/main/socialcard.png)

Laravel dynamic language switcher
=================================

[](#laravel-dynamic-language-switcher)

[![Latest Version](https://camo.githubusercontent.com/ec4162a31b540aa40f503fb89815f90b8d4c13678a692aae84e0dc952f15e2e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f616c6b68617469626465762f6c616e67756167652d73776974636865722e7376673f7374796c653d666c61742d737175617265)](https://github.com/alkhatibdev/language-switcher/releases)[![Packagist Downloads (custom server)](https://camo.githubusercontent.com/dd945f98435ed5c509254942bcc5f52d54f55991f81030230b1f148fcb7b86aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6b68617469626465762f6c616e67756167652d7377697463686572)](https://camo.githubusercontent.com/dd945f98435ed5c509254942bcc5f52d54f55991f81030230b1f148fcb7b86aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6b68617469626465762f6c616e67756167652d7377697463686572)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Introduction
============

[](#introduction)

Laravel dynamic language switcher for both web and API routes with various supported options.

Features
--------

[](#features)

- Switch user locale automatically and remind newly selected language for all next requests.
- Support language switching via `request body/query keys`, `request headers keys`, and `route parameters names`.
- Support API routes (Switch language via headers for stateless requests).
- Support all HTTP methods (GET, POST, PUT and ..etc).
- SEO-friendly routes by supporting language switching depending on route parameters.
- Everything is configurable with a rich and well-documented [configuration file](https://github.com/alkhatibdev/language-switcher/blob/main/config/language-switcher.php).

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

[](#installation)

install via composer
--------------------

[](#install-via-composer)

```
composer require alkhatibdev/language-switcher
```

Publish Configs
---------------

[](#publish-configs)

```
php artisan vendor:publish --tag=language-switcher-config
```

A `language-switcher.php` config file will be published on your `configs` directory. Feel free to read and override all these configurable parts, or stick with the [defaults configs](https://github.com/alkhatibdev/language-switcher/blob/main/config/language-switcher.php)

Usage
=====

[](#usage)

Basic Usage
-----------

[](#basic-usage)

Everything is set out of the box, start calling your routes with these supported options:

### Via Request query/body keys

[](#via-request-querybody-keys)

```
// Request query key/value
http://example.com/?lang=en

// Request magic keys
http://example.com/?en

// Also you can use the same above parameters with the body of POST or PUT
curl -X POST http://example.com/api/users
     -d '{"lang": "en"}'
```

### Via request headers keys

[](#via-request-headers-keys)

```
curl --header "Accept-Language: en" http://example.com/api/users
```

### Via route parameters

[](#via-route-parameters)

For given route: `Route::get('/{locale}/home', [HomeController, 'home']);`

```
http://example.com/en/home

```

> **Note**
> \- All previous examples will ask the package to switch locale to `'en'`.
> \- Upcoming requests still remind this newly set locale.

Customize Package Scope
-----------------------

[](#customize-package-scope)

By default, the package middleware is assigned globally to all your routes. However, you can disable `assign_globally` from the package config file, and assign middleware `alias` to all routes and route groups manually.

### Disable global assignment

[](#disable-global-assignment)

```
// config/language-switcher.php

'assign_globally' => false,
```

### Assign to route or route groups

[](#assign-to-route-or-route-groups)

```
// routes/web.php

// Assign to individual route
Route::get('/{locale}/home', [HomeController, 'home'])->middleware(['switchlocale']);

// Assign to route group
Route::->middleware(['switchlocale'])->group(function () {
    //
});
```

### Assign to middleware groups

[](#assign-to-middleware-groups)

```
// app/Http/kernel.php

protected $middlewareGroups = [
    'web' => [
        // ...
        'switchlocale',
    ],

    'api' => [
        // ...
        'switchlocale',
    ],
];
```

### Disable Saving

[](#disable-saving)

By default, the package uses sessions to store the current locale, switched by a user, to keep the newly selected locale active for the next requests without a need to pass the locale in every request. However, if you want to stop this behavior, set `enable_session` to `false`.

```
// config/language-switcher.php

'enable_session' => false,
```

License
=======

[](#license)

Language Switcher is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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.

###  Release Activity

Cadence

Every ~571 days

Total

2

Last Release

802d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a98ee8122409e21e0d095bde2b1d5b6541ff0c18a693a9e7f2828b5ee76eecd?d=identicon)[alkhatibdev](/maintainers/alkhatibdev)

---

Top Contributors

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

---

Tags

languageslaravellaravel-frameworklocalizationphplaravellocalizationlanguagelocaleswitcherlanguage-switcherchange locale

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alkhatibdev-language-switcher/health.svg)

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

###  Alternatives

[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)[codezero/laravel-localizer

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

50394.3k4](/packages/codezero-laravel-localizer)[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)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)

PHPackages © 2026

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