PHPackages                             elsayed85/country-switch - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. elsayed85/country-switch

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

elsayed85/country-switch
========================

Country Switch

0655PHP

Since Jan 15Pushed 2y agoCompare

[ Source](https://github.com/elsayed85/country-switch)[ Packagist](https://packagist.org/packages/elsayed85/country-switch)[ RSS](/packages/elsayed85-country-switch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Filament Language Switch](./.github/banner.jpg?raw=true "Filament Language Switch")](https://github.com/Elsayed85/filament-language-switch) [ ![FILAMENT 8.x](https://camo.githubusercontent.com/c98f15eb6bb59ce4fc768808e21fd46a07d238312928102f3d7ad4bed7c31f70/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c414d454e542d322e782d4542423330343f7374796c653d666f722d7468652d6261646765) ](https://filamentadmin.com/docs/2.x/admin/installation) [ ![Packagist](https://camo.githubusercontent.com/a2c25d43c7068442fb9fc6c0bff221ec4091472046d1365eaf6cfe6e6b6e512a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f456c736179656438352f66696c616d656e742d6c616e67756167652d7377697463682e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/Elsayed85/filament-language-switch) [ ![Tests Passing](https://camo.githubusercontent.com/cd75a6b72dbbe579c5aa312de6e4b6513f7ff1b5401d42ab33b56d49f87efd51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f456c736179656438352f66696c616d656e742d6c616e67756167652d7377697463682f72756e2d74657374732e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d7465737473) ](https://github.com/Elsayed85/filament-language-switch/actions?query=workflow%3Arun-tests+branch%3Amain) [ ![Code Style Passing](https://camo.githubusercontent.com/ed82fa9d2e7beb23ed28e022a6137bee667a0f2b71d571526de4f36ad6c1badc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f456c736179656438352f66696c616d656e742d6c616e67756167652d7377697463682f72756e2d6c61726176656c2d70696e742e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d636f64652532307374796c65) ](https://github.com/Elsayed85/filament-language-switch/actions?query=workflow%3A)[ ![Downloads](https://camo.githubusercontent.com/063d32be9ed841660d90adab4d303efc4dd904a0a7bf68330974457e51b16f00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f456c736179656438352f66696c616d656e742d6c616e67756167652d7377697463682e7376673f7374796c653d666f722d7468652d6261646765) ](https://packagist.org/packages/Elsayed85/filament-language-switch)[ ![Downloads](https://camo.githubusercontent.com/aa3be700d8bb9c67a3756844445707bddd54bacf7f71096fec90a0779c75c025/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3838333038333739323131323330303130343f6c6162656c3d446973636f7264267374796c653d666f722d7468652d6261646765) ](https://discord.com/channels/883083792112300104/990920249744453642)

---

Language Switch
===============

[](#language-switch)

The **Language Switch** plugin is a versatile and user-friendly tool designed for Filament Panels. It offers a seamless way to integrate language switching capabilities into your Filament Panels. With a range of customizable options and a fluent API, the plugin allows you to easily configure language selection for your users. It supports displaying language options both within and outside of Filament panels, and it provides the flexibility to specify which panels or routes should include the language switch and much more.

Requirement
-----------

[](#requirement)

- [Filament v3](https://filamentphp.com/docs/3.x/panels/installation)

Note

For [Filament v2](https://filamentphp.com/docs/2.x/admin/installation) use [v1](https://github.com/Elsayed85/filament-language-switch/tree/1.x)

---

Important

Migrating form 2.x to 3.x

- Unregister the plugin form all your panels
- Remove the config file `config/filament-language-switch.php`
- Remove the `filament-language-switch` directory from `resources/views/vendor`
- Bump the package version to `^3.0` in your `composer.json` file
- Run `composer update`
- Checkout the [Usage](#usage) section below to get up and running.
- Checkout the [Configuration](#configuration) section to see what's new and how to configure the plugin.

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

[](#installation)

Install the package via composer:

```
composer require Elsayed85/filament-language-switch
```

Usage
-----

[](#usage)

The plugin boots after installation automatically. For the plugin to work, provide an array of locales that your Panel(s) support to switch between them inside a service provider's `boot()` method. You can either create a new service provider or use the default `AppServiceProvider` as follow:

```
...
use Elsayed85\FilamentCountrySwitch\CountrySwitch;

class AppServiceProvider extends ServiceProvider
{
    ...

    public function boot()
    {
        ...

        CountrySwitch::configureUsing(function (CountrySwitch $switch) {
            $switch
                ->locales(['ar','en','fr']); // also accepts a closure
        });

        ...
    }
}
```

Though this is all you would need, but the plugin is designed to be very customizable. Delve into the **Configuration** section below for detailed customization options.

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

[](#configuration)

The plugin comes with following options that you can customize and configure as per your requirements. The plugin has a fluent API so you can chain the methods and easily configure it all in one place.

### Visibility Control

[](#visibility-control)

The `visible()` method configures the visibility of the **Language Switch** within the application's UI. It has two parameters:

- **insidePanels**: Determines if the language switcher is visible inside Filament panels, which is `true` by default. The language switcher will be visible inside panels only if the `insidePanels` condition is true, more than one locale is available, and the current panel is included (not excluded).
- **outsidePanels**: Controls visibility outside of the panels, with a default of false. The language switcher will be visible outside of panels only if the `outsidePanels` condition is true, the current route is included in the `outsidePanelRoutes()`, and the current panel is included (not excluded).

Both arguments can be provided as a `boolean` or a `Closure` that returns a boolean value. The Closure enables dynamic determination of visibility, allowing you to incorporate complex logic based on the application state, user permissions, or other criteria.

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->visible(outsidePanels: true)
            ...;
    });
    ...
```

### Outside Panel Routes

[](#outside-panel-routes)

The `outsidePanelRoutes()` method is used to define the routes where the **Language Switch** should be visible outside of the Filament panels. This method accepts either an `array` of route names or a `Closure` that returns an array of route names. By default, it includes common authentication routes such as `auth.login`, `auth.profile`, and `auth.register`.

To specify custom routes for displaying the language switcher, pass an array of route names to the method:

```
// AppServiceProvider.php
...
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
    $switch
        ...
        ->outsidePanelRoutes([
            'profile',
            'home',
            // Additional custom routes where the switcher should be visible outside panels
        ])
        ...;
});
...
```

If you want to dynamically determine the routes, use a Closure:

```
// AppServiceProvider.php
...
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
    $switch
        ...
        ->outsidePanelRoutes(fn() => someCondition() ? ['dynamic.route'] : ['default.route'])
        ...;
});
...
```

### Outside Panel Placement

[](#outside-panel-placement)

The `outsidePanelPlacement()` method specifies the placement of the **Language Switch** when it is rendered outside of Filament panels. This method accepts an `Placement` enum value that determines the switch's position on the screen.

You can choose from the following placements defined in the `Placement` enum:

- `TopLeft` default
- `TopCenter`
- `TopRight`
- `BottomLeft`
- `BottomCenter`
- `BottomRight`

Set the desired placement for the **language switch** outside Filament Panels like this:

```
// AppServiceProvider.php
...
use Elsayed85\FilamentCountrySwitch\Enums\Placement;

LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
    $switch
        ...
        ->outsidePanelPlacement(Placement::BottomRight)
        // Sets the language switch to appear at the bottom right outside of panels
        ...;
});
...
```

### Localized Labels

[](#localized-labels)

The `displayLocale()` method is used to set the locale that influences how labels for given locales are generated by PHP's native function `locale_get_display_name()`. This method specifies the language in which the labels for given locales are displayed when custom labels are not set using the `labels()` method.

By default, if `displayLocale()` is not explicitly set, the locale labels are generated based on the application's current locale. This affects the automatic label generation for locales without custom labels.

For example, if your application's current locale is `English ('en')`, and you have not set a specific display locale, then the labels for locales like `pt_BR` and `pt_PT` would automatically be generated as `Portuguese (Brazil)` and `Portuguese (Portugal)` respectively, in English.

To specify a different language for the automatic label generation, use `displayLocale()`:

```
// AppServiceProvider.php
...
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
    $switch
        ...
        ->displayLocale('fr') // Sets French as the language for label localization
        ...;
});
...
```

### Custom Labels

[](#custom-labels)

The `labels()` method in the **Language Switch** allows you to define custom text labels for each locale that your application supports. This customization is particularly useful when the default labels generated by PHP's native function `locale_get_display_name()` are not suitable for your application's needs.

By default, if no custom labels are provided, the **Language switch** will generate labels for each locale using the native PHP function `locale_get_display_name()`, which creates a label based on the current application's locale. For example, the locales `pt_BR` and `pt_PT` will be labeled as **Portuguese (Brazil)** and **Portuguese (Portugal)** respectively, when the application's locale is set to `en`.

However, you might prefer to display labels that are shorter or differently formatted. This is where the `labels()` method is beneficial. You can specify exactly how each language should be labeled, overriding the default behavior.

Here's how to set custom labels:

```
// AppServiceProvider.php
...
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
    $switch
        ...
        ->locales(['en','fr','pt_BR','pt_PT'])
        ->labels([
            'pt_BR' => 'Português (BR)',
            'pt_PT' => 'Português (PT)',
            // Other custom labels as needed
        ])
        ...;
});
...
```

### Panel Exclusion

[](#panel-exclusion)

By default the **Language Switch** will be available inside all existing Panels. But you can choose which panels will have the switch by providing an array of valid panel ids using the `exclude()` method. The method also accepts a `Closure` so you have more control over how to exclude certain panels.

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->excludes([
                'app'
            ])
            ...;
    });
    ...
```

### Render Hook

[](#render-hook)

By default the `panels::global-search.after` hook is used to render the **Language Switch**. But you can use any of the [Render Hooks](https://filamentphp.com/docs/3.x/support/render-hooks) available in Filament using the `renderHook()` method as:

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->renderHook('panels::global-search.before')
            ...;
    });
    ...
```

### Flags

[](#flags)

By default the **Language Switch** uses the locales as `Language Badges` to serve as placeholders for the flags. But you may associate each locale with its corresponding flag image by passing an array to the `flags()` method. Each key in the array represents the locale code, and its value should be the asset path to the flag image for that locale. For example, to set flag images for Arabic, French, and English (US), you would provide an array like this:

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->flags([
                'ar' => asset('flags/saudi-arabia.svg'),
                'fr' => asset('flags/france.svg'),
                'en' => asset('flags/usa.svg'),
            ])
            ...;
    });
    ...
```

Make sure that the provided paths in the `asset()` helper point to the correct location of the flag images in your Laravel project's public directory.

### Flags Only

[](#flags-only)

The `flagsOnly()` method controls whether the **Language Switch** displays only flag images, without accompanying text labels. This method can enhance the UI by providing a cleaner look when space is limited or when you prefer a more visual representation of language options.

To display only the flags for each language, invoke the method and make sure you have provided the flags for locales just like shown above using the `flags()` method:

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->flags([
                'ar' => asset('flags/saudi-arabia.svg'),
                'fr' => asset('flags/france.svg'),
                'en' => asset('flags/usa.svg'),
            ])
            ->flagsOnly()
            ...;
    });
    ...
```

### Circular

[](#circular)

By default the **Language Switch** `Flags` or `Language Badges` are slightly rounded like the most other Filament components. But you may make it fully rounded using the `circular()` method.

```
//AppServiceProvider.php
    ...
    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
        $switch
            ...
            ->circular()
            ...;
    });
    ...
```

Theme
-----

[](#theme)

The plugin follows Filament's theming rules. So, if you have custom themes add the plugin's view path into the `content` array of your themes' `tailwind.config.js` file:

```
//tailwind.config.js
export default {
    content: [
        // ...
        './vendor/Elsayed85/filament-language-switch/resources/views/language-switch.blade.php',
    ],
    // ...
}
```

... now build your theme using:

```
npm run build
```

Views
-----

[](#views)

In case you want to tweak the design, you can publish the views using the following command and adjust it however you like:

```
php artisan vendor:publish --tag="filament-language-switch-views"
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

If you want to contribute to this packages, you may want to test it in a real Filament project:

- Fork this repository to your GitHub account.
- Create a Filament app locally.
- Clone your fork in your Filament app's root directory.
- In the `/filament-language-switch` directory, create a branch for your fix, e.g. `fix/error-message`.

Install the packages in your app's `composer.json`:

```
"require": {
    "Elsayed85/filament-language-switch": "dev-fix/error-message as main-dev",
},
"repositories": [
    {
        "type": "path",
        "url": "filament-language-switch"
    }
]
```

Now, run `composer update`.

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Bezhan Salleh](https://github.com/Elsayed85)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

[![bezhanSalleh](https://avatars.githubusercontent.com/u/10007504?v=4)](https://github.com/bezhanSalleh "bezhanSalleh (98 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![medeiroz](https://avatars.githubusercontent.com/u/11270546?v=4)](https://github.com/medeiroz "medeiroz (3 commits)")[![erjanmx](https://avatars.githubusercontent.com/u/4899432?v=4)](https://github.com/erjanmx "erjanmx (2 commits)")[![ziming](https://avatars.githubusercontent.com/u/679513?v=4)](https://github.com/ziming "ziming (1 commits)")[![dev3k](https://avatars.githubusercontent.com/u/241731?v=4)](https://github.com/dev3k "dev3k (1 commits)")[![lukas-frey](https://avatars.githubusercontent.com/u/10926334?v=4)](https://github.com/lukas-frey "lukas-frey (1 commits)")[![mustafa-online](https://avatars.githubusercontent.com/u/5323832?v=4)](https://github.com/mustafa-online "mustafa-online (1 commits)")[![tobiasla78](https://avatars.githubusercontent.com/u/17968060?v=4)](https://github.com/tobiasla78 "tobiasla78 (1 commits)")

### Embed Badge

![Health badge](/badges/elsayed85-country-switch/health.svg)

```
[![Health](https://phpackages.com/badges/elsayed85-country-switch/health.svg)](https://phpackages.com/packages/elsayed85-country-switch)
```

###  Alternatives

[icehouse-ventures/laravel-mermaid

Simple package to generate diagrams in Laravel using the Mermaid.js library

2630.0k](/packages/icehouse-ventures-laravel-mermaid)

PHPackages © 2026

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