jeromesiau/filament-multilang
Composer 安装命令:
composer require jeromesiau/filament-multilang
包简介
Multi-language input component for Filament 3
README 文档
README
A component for managing multilingual fields in Filament 3, integrated with Spatie Laravel Translatable.
Why This Plugin?
This plugin was created to offer a focused, input-level approach to multilingual content in Filament forms, unlike other solutions that implement translations at the page or fieldset level.
Key features:
- Input-level language tabs: Each translatable field has its own compact set of language tabs directly on the input
- Flexible validation: Define which languages are required on a per-field basis
- Multiple input types: Works seamlessly with both standard text inputs and rich text editors
The goal is to provide a streamlined editing experience for multilingual content that feels natural and integrated with Filament's design philosophy.
Installation
You can install the package via composer:
composer require jeromesiau/filament-multilang
This package automatically integrates Spatie Laravel Translatable to efficiently manage translations storage.
To configure available languages, you can publish the configuration file:
php artisan vendor:publish --tag="filament-multilang-config"
The published configuration file will look like this:
return [ 'locales' => [ 'fr' => ['name' => 'French'], 'en' => ['name' => 'English'], ], ];
Simply modify the locales array to add, remove, or change the available languages for your application. Each language requires a key (language code) and a name that will be displayed in the language tabs.
By default, when displaying values in Filament tables, the component will use the translation that corresponds to your application's current locale (APP_LOCALE environment variable by defaut). This ensures a consistent display in listings while still maintaining full multilingual capabilities in forms.
Model Configuration
To use the component with your models, make sure they use Spatie's HasTranslations trait:
use Spatie\Translatable\HasTranslations; use Illuminate\Database\Eloquent\Model; class Page extends Model { use HasTranslations; public $translatable = ['title', 'content']; }
Important: Spatie Translatable recommends that translatable database fields should be defined as json type (or text if JSON is not available in your database). Make sure your migration reflects this:
Schema::create('pages', function (Blueprint $table) { $table->id(); $table->json('title'); $table->json('content'); $table->timestamps(); });
Usage
use JeromeSiau\FilamentMultilang\Components\MultiLangInput; // In your Filament form MultiLangInput::make('title') ->required() // All languages will be required // For rich text fields MultiLangInput::make('content') ->type('rich') ->required() // To make only specific languages required MultiLangInput::make('title') ->required() ->requiredLocales(['fr']) // Customize available languages MultiLangInput::make('title') ->locales([ 'fr' => ['name' => 'French'], 'en' => ['name' => 'English'], 'es' => ['name' => 'Spanish'], ]) // Customize rich editor toolbar buttons MultiLangInput::make('content') ->type('rich') ->toolbarButtons([ 'bold', 'italic', 'link', ]) // Set editor height MultiLangInput::make('content') ->type('rich') ->editorHeight('300px')
Data Transformation
You can transform data before it's stored:
MultiLangInput::make('content') ->type('rich') ->transform( function ($value) { // Transform value before storing return clean($value); }, function ($value) { // Transform value when retrieved return $value; } )
Data Structure
Data is stored as an associative array with language codes as keys:
[
'fr' => 'French content',
'en' => 'English content',
]
With Spatie Laravel Translatable, this array is automatically stored in a JSON field in your database, which greatly simplifies translation management.
Styling
The component comes with default styling that places language tabs neatly at the top-right of each input field. You can customize the appearance by targeting the .fi-multilang-input CSS class in your own stylesheets.
Credits
License
MIT
jeromesiau/filament-multilang 适用场景与选型建议
jeromesiau/filament-multilang 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 315 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jeromesiau/filament-multilang 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jeromesiau/filament-multilang 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 315
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-30
