PHP code example of bezhansalleh / filament-language-switch
1. Go to this page and download the library: Download bezhansalleh/filament-language-switch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bezhansalleh / filament-language-switch example snippets
use BezhanSalleh\LanguageSwitch\Enums\TriggerStyle;
// Visual only
$switch->trigger(style: TriggerStyle::Icon); // language icon
$switch->trigger(style: TriggerStyle::Flag); // flag image (er(style: TriggerStyle::FlagLabel); // flag + locale name
$switch->trigger(style: TriggerStyle::AvatarLabel); // abbreviation + locale name
// Label only — no visual
$switch->trigger(style: TriggerStyle::Label);
use Filament\Support\Icons\Heroicon;
// Just change the icon (style stays as default)
$switch->trigger(icon: Heroicon::GlobeAlt);
// Any Blade Icons string works too
$switch->trigger(icon: 'heroicon-o-globe-alt');
$switch->trigger(icon: 'phosphor-translate');
// Or change both in one call
$switch->trigger(
style: TriggerStyle::IconLabel,
icon: Heroicon::GlobeAlt,
);
use Filament\Support\Facades\FilamentIcon;
FilamentIcon::register([
'language-switch::trigger' => 'heroicon-o-globe-alt',
]);
use BezhanSalleh\LanguageSwitch\Enums\ItemStyle;
$switch->itemStyle(ItemStyle::FlagOnly); // flag images only, tooltips on hover
$switch->itemStyle(ItemStyle::AvatarOnly); // abbreviations only (EN, FR), tooltips on hover
$switch->itemStyle(ItemStyle::LabelOnly); // text labels only, no visual
$switch->itemStyle(ItemStyle::FlagWithLabel); // flag + locale name (default with flags)
$switch->itemStyle(ItemStyle::AvatarWithLabel); // abbreviation + locale name (default without flags)
use BezhanSalleh\LanguageSwitch\Enums\Placement;
use BezhanSalleh\LanguageSwitch\Enums\PlacementMode;
$switch->outsidePanelPlacement(Placement::TopCenter, PlacementMode::Pinned);
use Filament\View\PanelsRenderHook;
// Dock as a profile item inside the user menu dropdown
$switch->outsidePanelsRenderHook(PanelsRenderHook::USER_MENU_PROFILE_AFTER);
// Or force body-level anchoring for an in-flow mode
$switch
->outsidePanelPlacement(Placement::BottomCenter, PlacementMode::Static)
->outsidePanelsRenderHook(PanelsRenderHook::BODY_END);
use Filament\View\PanelsRenderHook;
// Force a body-start overlay even when a user menu is present
$switch
->outsidePanelPlacement(Placement::TopEnd, PlacementMode::Pinned)
->outsidePanelsRenderHook(PanelsRenderHook::BODY_START);