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

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

ied3vil/language-switcher
=========================

Laravel Language Switcher

1.1.1(8y ago)4543.6k↓46.2%20[1 issues](https://github.com/ied3vil/LanguageSwitcher/issues)[1 PRs](https://github.com/ied3vil/LanguageSwitcher/pulls)Apache 2.0PHPPHP &gt;=5.3.0

Since Jul 15Pushed 4y ago5 watchersCompare

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

READMEChangelog (1)DependenciesVersions (13)Used By (0)

LanguageSwitcher
================

[](#languageswitcher)

Laravel Language Switcher Package

Description
-----------

[](#description)

This package provides an easy to work with language switcher that you can use in your projects with a wide variety of config options. It automatically bootstraps to your Laravel project, sets the locale, and switches the languages when needed.

Configuration provided supports a dynamic array of different options to adjust the functionality of the package to suit your needs, whereas the default provided config will allow you to use the package right after installing, with almost no additional work.

I know it may seem very simple and perhaps over-complicated, but you don't have to waste time and thought process on the simple things.

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

[](#installation)

To install the package, just run composer require ied3vil/language-switcher and follow the instructions. If you want to add it to your composer.json manually, just open composer.json and search for the "autoload" field and add

```
composer require ied3vil/language-switcher

```

After the package is installed, you should run the vendor:publish command in the console so the package publishes its config file to your application. The package should work fine without this step, all config options have fall backs - however it may impact future use, so it is recommended not to skip the vendor:publish command.

```
php artisan vendor:publish

```

To start using the package,you have to include its service provider and middleware in your application. To include the service provider, just go to your `config/app.php` file, find the providers array and append the language switcher provider at the bottom.

```
    'providers' => [
        .
        .
        .
        ied3vil\LanguageSwitcher\Providers\LanguageSwitcherProvider::class,
    ],

```

Next, go to `app/Http/Kernel.php` and find the middleware array. You have two options:

1. Register the middleware as a route and use it within your routes, if you only want to use it only for the routes you need it for
2. **Recommended:** Include the middleware within the 'web' middleware group, making it globally available. Not including the middleware will fail to register the locale and the current selected language will not register. Make sure you include the middleware at the end of the array, because it is reliant on Session to work.

```
        'web' => [
            .
            .
            .
            \ied3vil\LanguageSwitcher\Middleware\LanguageSwitcherMiddleware::class,
        ],

```

You are now ready to use the language switcher!

Usage
-----

[](#usage)

The default language set in your app.locale config value will be set. You can find it in the `config/app.php` config file.

Switching the current language can be done in quite a few ways.

1. Using the provided facade: `LanguageSwitcher::setLanguage($language)`
2. Using the provided `/lang/{language}` route. The config file provides flexibility in changing the actual "lang" route. This route can be changed using the [configuration](#configuration).

When using the provided routes for switching languages, you will be redirected to the '/' route after the new language is set.

You should be all set! You can start writing your content in multiple languages! For more information on how to do this, please consult [Laravel's Documentation](https://laravel.com/docs/5.2/localization).

Alternatively, you can set this yourself using your own routes, just set the session value `'language'` to the new locale and redirect.

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

[](#configuration)

The package ships with quite a few configuration options:

```
return [
    'switchPath' => 'lang',
    'store' => 'session',
    'key' => 'language',
    'redirect' => 'route', //can be set to route | back
    'redirect_route' => '/',
];

```

The above config options can be used to customize the switcher's functionality, as described below. You are free to use any method to configure the package. Remember to use the publish:vendor command to avoid unexpected issues.

To set options, you can use any of the following methods:

1. Changing the config file `config/languageswitcher.php`, editing the values of the provided keys (recommended)
2. Using laravel's runtime configuration helper - `Config::set()` | `config()->set()`, with the specification that you use the 'languageswitcher' preffix for the keys (eg. `languageswitcher.switchPath` for changing the switch path).

##### Changing the switcher's route (default: lang/{language\_flag})

[](#changing-the-switchers-route-default-langlanguage_flag)

- Config key: `languageswitcher.switchPath`
- Default Value: `lang`

This config setting dynamically sets the route created in the package for switching the language.

##### Changing store method - session | cookie (default: session)

[](#changing-store-method---session--cookie-default-session)

- Config key: `languageswitcher.store`
- Default value: `session`
- Accepted values: `session | cookie`

This config setting changes the storage method of the language flag. Default is session, but cookies with forever as expiry date can be used. Initially this was set up as a cookie with a configurable expiry date, but for obvious reasons it was set up to never expire.

##### Changing the key where the language flag is stored (default: lang)

[](#changing-the-key-where-the-language-flag-is-stored-default-lang)

- Config key: `languageswitcher.key`
- Default value: `language`

This config setting decides what key to be used when storing the language flag, to the session or cookie.

##### Changing the redirect type (default: route redirect to '/')

[](#changing-the-redirect-type-default-route-redirect-to-)

- Config keys: `languageswitcher.redirect` and `languageswitcher.redirect_route`
- Default value for `languageswitcher.redirect`: `route`
- Accepted values: `route | back`
- Default value for `languageswitcher.redirect_route`: `/`

When the `languageswitcher.redirect` config value is set to route, the user is redirected to the specified `languageswitcher.redirect_route` after the new language flag is set. Setting the `languageswitcher.redirect` to `back` will redirect the user back to the previous page after the new language flag is set.

Examples
--------

[](#examples)

My preffered way to usage is this: I include the library, create my UI for switching the language, and start translating!

Example HTML:

```

    {{ trans('locale.en') }}
    {{ trans('locale.dk') }}
    {{ trans('locale.sw') }}

```

If you want to evidentiate the current selection language, you can use App::getLocale() or LanguageSwitcher::getCurrentLanguage().

Bugs/Issues/Improvements
------------------------

[](#bugsissuesimprovements)

Feel free to use github for issues and suggesting improvements.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 86.1% 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 ~43 days

Recently: every ~118 days

Total

12

Last Release

3120d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3307719e5467609dbab6c750dc90202ecdadb863f59ea4444889b09ec9b38cb8?d=identicon)[ied3vil](/maintainers/ied3vil)

---

Top Contributors

[![ied3vil](https://avatars.githubusercontent.com/u/673331?v=4)](https://github.com/ied3vil "ied3vil (31 commits)")[![erik-ropez](https://avatars.githubusercontent.com/u/1631035?v=4)](https://github.com/erik-ropez "erik-ropez (2 commits)")[![ettiennelouw](https://avatars.githubusercontent.com/u/1754421?v=4)](https://github.com/ettiennelouw "ettiennelouw (2 commits)")[![nniicc](https://avatars.githubusercontent.com/u/5363602?v=4)](https://github.com/nniicc "nniicc (1 commits)")

---

Tags

phplaravellanguageswitcher

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/ied3vil-language-switcher/health.svg)](https://phpackages.com/packages/ied3vil-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)[akaunting/laravel-language

Language switcher package for Laravel

223285.2k1](/packages/akaunting-laravel-language)[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M16](/packages/josiasmontag-laravel-redis-mock)[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)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

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

Localization for Laravel framework

2336.2k](/packages/josiasmontag-laravel-localization)

PHPackages © 2026

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