amrikasir/lang-selector
Composer 安装命令:
composer require amrikasir/lang-selector
包简介
Livewire-based language selector for Laravel 11
README 文档
README
A simple, elegant, and reusable Livewire 3/4 language switcher for Laravel 11.
This package provides a ready-to-use dropdown component to switch application locales dynamically — complete with middleware, configuration, and publishable views.
✨ Features
- ⚡ Supports Livewire 3 and 4
- 🌍 Easy multi-language switching (session-based)
- ⚙️ Configurable via
config/lang-selector.php - 🎨 Publishable views for full customization
- 🧩 Simple integration with your existing layout
📦 Installation
Require the package via Composer:
composer require amrikasir/lang-selector
⚙️ Publish Config & Views
You can publish the default configuration and views to customize them:
php artisan vendor:publish --tag=lang-selector-config php artisan vendor:publish --tag=lang-selector-views
This will create:
config/lang-selector.php
resources/views/vendor/lang-selector/
🧩 Usage
- Register Middleware
In app/Http/Kernel.php, add the middleware to your web group:
protected $middlewareGroups = [ 'web' => [ // ... \Kaldiaris\LangSelector\Http\Middleware\LocaleMiddleware::class, ], ];
- Add Component to Blade
Just drop the component anywhere in your layout:
<livewire:language-selector />
That’s it! 🎉
The dropdown will automatically display all available locales from your config.
⚙️ Configuration
config/lang-selector.php
return [ 'available_locales' => [ 'en' => 'English', 'id' => 'Bahasa Indonesia', // add more as needed ], 'default_locale' => 'en', ];
🧠 How It Works
- The
LocaleMiddlewaresetsApp::setLocale()based on the session. - The
LanguageSelectorLivewire component updates session locale dynamically. - The selected locale persists until changed again.
🧰 Example Styling
You can freely modify the published views at:
resources/views/vendor/lang-selector/livewire/language-selector.blade.php
Example minimal Tailwind version:
<div class="relative"> <button wire:click="$toggle('open')" class="px-3 py-2 rounded bg-gray-100 hover:bg-gray-200"> {{ $locales[$current] ?? strtoupper($current) }} </button> @if ($open ?? false) <div class="absolute bg-white border rounded mt-1 shadow"> @foreach ($locales as $key => $label) <button wire:click="setLocale('{{ $key }}')" class="block w-full text-left px-4 py-2 hover:bg-gray-100"> {{ $label }} </button> @endforeach </div> @endif </div>
🧾 License
This package is open-sourced software licensed under the MIT license.
amrikasir/lang-selector 适用场景与选型建议
amrikasir/lang-selector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 amrikasir/lang-selector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 amrikasir/lang-selector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-22