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

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

r0073rr0r/laravel-language-switcher
===================================

Laravel Jestream Livewire Language Switcher Component

1.1.4(6mo ago)171[1 PRs](https://github.com/r0073rr0r/laravel-language-switcher/pulls)MITPHPPHP ^8.2CI passing

Since Nov 7Pushed 1mo agoCompare

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

READMEChangelog (3)Dependencies (8)Versions (7)Used By (0)

Laravel Jetstream Livewire Language Switcher
============================================

[](#laravel-jetstream-livewire-language-switcher)

A beautiful and easy-to-use language switcher component for **Laravel** applications using **Jetstream** and **Livewire**. This package provides a dropdown menu with country flags for switching between different application languages.

[![Packagist Version](https://camo.githubusercontent.com/01ac3823d41e84977ec3cfa7481b0723422c238e729ae289d814ea81b56ef25b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7230303733727230722f6c61726176656c2d6c616e67756167652d73776974636865722e737667)](https://packagist.org/packages/r0073rr0r/laravel-language-switcher)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Laravel](https://camo.githubusercontent.com/b72e0aa3b09f6ee9f1cd47f19792a8204408312803c6b277768a5d2c99ffd60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d7265642e737667)](https://laravel.com)[![Livewire](https://camo.githubusercontent.com/6a2b379b020a064bcd80f4b70536601a9cb8db17f251dd951be63b30f8efb6d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c697665776972652d332e782d70696e6b2e737667)](https://livewire.laravel.com)[![Laravel Jetstream](https://camo.githubusercontent.com/67ac06273a3bcbae76a972de1903424cd9d82a17bb7000257edc4011cd918f6b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a657473747265616d2d352e782d626c75652e737667)](https://jetstream.laravel.com)[![Total Downloads](https://camo.githubusercontent.com/a06144f82e4869b44bf34d674ca065e7d76becad2ecc8a9964ba3a280668476b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7230303733727230722f6c61726176656c2d6c616e67756167652d73776974636865722e737667)](https://packagist.org/packages/r0073rr0r/laravel-language-switcher)[![Monthly Downloads](https://camo.githubusercontent.com/808b23cb919ea38ec4c71881a136bdd500ce70ddf2f7bbe9355a8c4a9fbab87b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f7230303733727230722f6c61726176656c2d6c616e67756167652d73776974636865722e737667)](https://packagist.org/packages/r0073rr0r/laravel-language-switcher)[![GitHub Stars](https://camo.githubusercontent.com/a2828e59d1ee593cf16cd42ab024073c7282f468b653d707db76f361732d772a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f7230303733727230722f6c61726176656c2d6c616e67756167652d73776974636865723f7374796c653d736f6369616c)](https://github.com/r0073rr0r/laravel-language-switcher/stargazers)[![GitHub Issues](https://camo.githubusercontent.com/47d6754fbaa7d29b49db95ea59b2776456f9ff40489169e31d888c3755b97d48/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7230303733727230722f6c61726176656c2d6c616e67756167652d7377697463686572)](https://github.com/r0073rr0r/laravel-language-switcher/issues)[![GitHub Forks](https://camo.githubusercontent.com/2cdef1292c251827bd176939316810c8a08939c580e63a2b9754dfa3eaecde4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f7230303733727230722f6c61726176656c2d6c616e67756167652d73776974636865723f7374796c653d736f6369616c)](https://github.com/r0073rr0r/laravel-language-switcher/network)[![CodeQL](https://github.com/r0073rr0r/laravel-language-switcher/workflows/CodeQL/badge.svg)](https://github.com/r0073rr0r/laravel-language-switcher/actions/workflows/github-code-scanning/codeql)[![Tests](https://github.com/r0073rr0r/laravel-language-switcher/actions/workflows/tests.yml/badge.svg)](https://github.com/r0073rr0r/laravel-language-switcher/actions/workflows/tests.yml)

📑 Table of Contents
-------------------

[](#-table-of-contents)

- [✨ Features](#-features)
- [📋 Requirements](#-requirements)
- [📦 Installation](#-installation)
- [⚙️ Configuration](#%EF%B8%8F-configuration)
- [🚀 Usage](#-usage)
- [⚙️ How It Works](#%EF%B8%8F-how-it-works)
- [🎨 Customization](#-customization)
- [💻 Development](#-development)
- [🤝 Contributing](#-contributing)
- [🔒 Security](#-security)
- [📝 License](#-license)
- [🙏 Credits](#-credits)
- [💬 Support](#-support)

✨ Features
----------

[](#-features)

- 🎨 Beautiful dropdown with country flags
- ⚡ Built with Livewire 3
- 🔧 Easy integration with Laravel Jetstream
- 🌍 Automatic locale detection and persistence
- 🎯 Middleware for automatic locale setting
- 📦 Auto-discovery support
- 🎭 Uses flag-icons for beautiful country flags

📋 Requirements
--------------

[](#-requirements)

- PHP ^8.2
- **Laravel ^12.0**
- **Livewire ^3.0**
- **Jetstream ^5.0**

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require r0073rr0r/laravel-language-switcher
```

#### Install flag-icons package:

[](#install-flag-icons-package)

```
npm install flag-icons
```

---

### Publish Assets

[](#publish-assets)

Publish the package assets

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

This will publish to your `public/vendor/language-switcher` directory.

[![Language Switcher Installation](https://camo.githubusercontent.com/73292da7b3d6b5b4ac87ae8cf2fda1d313badd2acce1efaa4c0e7aa3b20089a1/68747470733a2f2f61736369696e656d612e6f72672f612f34795a667a49746271706967464954476c4348396d667639632e737667)](https://asciinema.org/a/4yZfzItbqpigFITGlCH9mfv9c)---

Include the CSS file in your `resources/css/app.css` file:

```
@import "/node_modules/flag-icons/css/flag-icons.min.css";
```

---

#### Build project:

[](#build-project)

```
npm run build
```

---

⚙️ Configuration
----------------

[](#️-configuration)

### 1. Register the Middleware

[](#1-register-the-middleware)

Add the `SetLocale` middleware to your `bootstrap/app.php`:

```
use r0073rr0r\LanguageSwitcher\Http\Middleware\SetLocale;

->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        SetLocale::class,
    ]);
})
```

### Configure Available Locales

[](#configure-available-locales)

In your `config/app.php`, make sure you have your supported locales defined:

```
'locale' => 'en',
'fallback_locale' => 'en',

```

### Add Translation Files

[](#add-translation-files)

Create translation files for your supported languages in lang/ directory:

```
lang/
  en/
  sr/
  de/

```

### Configuration Options

[](#configuration-options)

The package configuration file `config/language-switcher.php` contains the following options:

#### `supported_locales` (array)

[](#supported_locales-array)

List of language codes (ISO 639-1) your application supports. These codes are used to:

- Generate the language dropdown dynamically
- Validate language selection in the LanguageSwitcher component
- Filter available languages in the middleware

**Example:**

```
'supported_locales' => ['en', 'sr', 'ru', 'de', 'fr'],
```

#### `default_locale` (string)

[](#default_locale-string)

The default language code that will be used when:

- No language is set in the user's session
- The session contains an unsupported locale
- A user visits the site for the first time

This should match your Laravel app's default locale in `config/app.php`.

**Example:**

```
'default_locale' => 'en',
```

#### `flags` (array)

[](#flags-array)

Maps each language code to a corresponding country flag code (ISO 3166-1 alpha-2) from the flag-icons library. This is used to display the correct flag icon next to each language option in the dropdown.

**Example:**

```
'flags' => [
    'en' => 'gb',  // English → Great Britain flag
    'sr' => 'rs',  // Serbian → Serbia flag
    'ru' => 'ru',  // Russian → Russia flag
],
```

#### `names` (array)

[](#names-array)

Maps each language code to its display name that will be shown in the language switcher dropdown. These names are typically written in the native language. If a language code is not found in this array, the component will fall back to displaying the uppercase locale code.

**Example:**

```
'names' => [
    'en' => 'English',
    'sr' => 'Srpski',
    'ru' => 'Русский',
],
```

#### `reload_method` (string)

[](#reload_method-string)

Defines how the application should handle the page after switching the language. This ensures that the new locale is applied correctly across the entire application.

Available options:

- **`'js'`** (default): Uses JavaScript to reload the page (`window.location.reload()`). This is the most reliable method and ensures the locale is applied immediately. Works well in most scenarios and is recommended for most applications.
- **`'redirect'`**: Uses Laravel redirect to navigate back to the previous page or home. This method uses server-side redirect which can be more SEO-friendly and provides better control over the navigation flow. Useful when you want to maintain the URL structure or need server-side processing.
- **`'none'`**: Does not reload or redirect. The locale change will be applied on the next request. Use this if your application handles locale changes without requiring a page reload (e.g., if you're using Livewire's reactive properties or if the middleware properly handles the locale change on subsequent requests).

**Example:**

```
// Use JavaScript reload (default - most reliable)
'reload_method' => 'js',

// Use server-side redirect
'reload_method' => 'redirect',

// Don't reload - let middleware handle it on next request
'reload_method' => 'none',
```

> **Note:** If you experience issues where the language doesn't change after switching, try using `'js'` (default) or `'redirect'`. If your application already handles locale changes properly without reload, you can set it to `'none'` for a smoother user experience.

🚀 Usage
-------

[](#-usage)

### Add to Jetstream Navigation

[](#add-to-jetstream-navigation)

Add the language switcher component to your Jetstream navigation menu in navigation-menu.blade.php:

[![Language Switcher](https://camo.githubusercontent.com/c988317c24dbf9dc4a2ce9d6bbed5b7392ab401e4b68139fdd8cd53084290c3e/68747470733a2f2f636c6f75642e64626173652e696e2e72732f7075626c69632e7068702f6461762f66696c65732f4d66644a47436f78365374346d73332f)](https://camo.githubusercontent.com/c988317c24dbf9dc4a2ce9d6bbed5b7392ab401e4b68139fdd8cd53084290c3e/68747470733a2f2f636c6f75642e64626173652e696e2e72732f7075626c69632e7068702f6461762f66696c65732f4d66644a47436f78365374346d73332f)

```

```

### Customize Available Languages

[](#customize-available-languages)

The default supported languages are defined in `config/language-switcher.php`:

- `supported_locales` — list of language codes (e.g., 'en', 'sr', 'de')
- `flags` — maps language code to flag-icons class
- `names` — optional display names for languages
- `reload_method` — how to handle page after language switch: `'redirect'` (default), `'js'`, or `'none'`

You can add new languages by updating these arrays. See the [Configuration Options](#configuration-options) section above for detailed information about each option.

If you update supported languages, make sure to update the `supported_locales` array in `config/app.php`. And clear config cache:

```
php artisan config:clear
php artisan cache:clear
```

⚙️ How It Works
---------------

[](#️-how-it-works)

1. **Middleware**: The SetLocale middleware automatically sets the application locale based on the session value
2. **Livewire Component**: The LanguageSwitcher component provides the UI for language selection
3. **Session Persistence**: Selected language is stored in the session and persists across requests
4. **Flag Icons**: Uses the flag-icons library to display beautiful country flags

🎨 Customization
---------------

[](#-customization)

### Adding More Languages

[](#adding-more-languages)

To add more languages, edit the languages array in the component with the language code and corresponding flag code (ISO 3166-1-alpha-2).

Example flag codes:

- gb - Great Britain (English)
- rs - Serbia (Serbian)
- de - Germany (German)
- fr - France (French)
- es - Spain (Spanish)
- it - Italy (Italian)

💻 Development
-------------

[](#-development)

The package uses Laravel Pint for code formatting:

```
./vendor/bin/pint
```

### Running Tests

[](#running-tests)

Install dev dependencies and run the test suite:

```
composer install
composer test
```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

🔒 Security
----------

[](#-security)

If you discover any security-related issues, please email `velimir@majstorov.rs` instead of using the issue tracker.

📝 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

🙏 Credits
---------

[](#-credits)

- Flag Icons for the beautiful flag icons

💬 Support
---------

[](#-support)

If you find this package useful, please consider giving it a star on GitHub!

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance81

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.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 ~0 days

Total

3

Last Release

187d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ebbcd8b937d006e91b7ac7c2f3942f11cf86e0f7f6d7d9d40d0256021d0f905?d=identicon)[r00terr0r](/maintainers/r00terr0r)

---

Top Contributors

[![r0073rr0r](https://avatars.githubusercontent.com/u/11500982?v=4)](https://github.com/r0073rr0r "r0073rr0r (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M112](/packages/mcamara-laravel-localization)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

135304.0k2](/packages/vemcogroup-laravel-translation)

PHPackages © 2026

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