Download the PHP package bezhansalleh/filament-language-switch without Composer

On this page you can find all versions of the php package bezhansalleh/filament-language-switch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package filament-language-switch

FILAMENT 8.x Packagist Tests Passing Code Style Passing Downloads Downloads


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

[!NOTE]
For Filament v2 use v1


[!IMPORTANT] Migrating from 2.x to 3.x

  • Unregister the plugin from 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 section below to get up and running.
  • Checkout the Configuration section to see what's new and how to configure the plugin.

Installation

Install the package via composer:

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:

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

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

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

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.

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:

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

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:

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

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():

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:

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.

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 available in Filament using the renderHook() method as:

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:

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

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:

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.

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:

... now build your theme using:

Views

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

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

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

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

Now, run composer update.

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of filament-language-switch with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
filament/filament Version ^3.0
spatie/laravel-package-tools Version ^1.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bezhansalleh/filament-language-switch contains the following files

Loading the files please wait ....