backtik-ch / filament-translatable
This packages provides a simple way to translate Filament texts with AI (or manually). It is to be used in combination with Spatie's Laravel Translatable package.
Package info
github.com/backtik-ch/filament-translatable
pkg:composer/backtik-ch/filament-translatable
Fund package maintenance!
Requires
- php: ^8.3
- filament/filament: ^4.0 || ^5.0
- laravel/ai: ^0.7
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.7|^4.0
- pestphp/pest-plugin-arch: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- pestphp/pest-plugin-livewire: ^3.0|^4.0
This package is auto-updated.
Last update: 2026-05-26 06:27:32 UTC
README
A Filament 4 & 5 plugin that provides translatable form fields and infolist entries with AI-powered translation generation via laravel/ai. Designed to work with spatie/laravel-translatable.
Features
- TranslatableInput — A form field with two display modes: modal (default) or inline
- TranslatableEntry — An infolist entry with two display modes: inline (expandable) or modal
- AI Translation — Generate all translations in a single API call using structured output
- Configurable — Set languages, source locale, AI provider/model globally or per-panel
- Disable AI — Optionally disable the AI section while keeping manual translation editing
Requirements
- PHP ^8.3
- Laravel ^12.0 | ^13.0
- Filament ^4.0 | ^5.0
Installation
composer require backtik-ch/filament-translatable
Publish the config file:
php artisan vendor:publish --tag="filament-translatable-config"
Configuration
// config/filament-translatable.php return [ 'languages' => ['fr', 'de', 'it', 'en'], 'source_locale' => 'fr', 'ai' => [ 'enabled' => env('FILAMENT_TRANSLATABLE_AI_ENABLED', true), 'provider' => env('FILAMENT_TRANSLATABLE_AI_PROVIDER', 'anthropic'), 'model' => env('FILAMENT_TRANSLATABLE_AI_MODEL', 'claude-haiku-4-5-20251001'), 'prompt' => 'Translate the following text from :source_language to :target_language. Return only the translation, nothing else.', ], ];
API Keys
API keys are managed by laravel/ai. Add the relevant key to your .env:
# Anthropic ANTHROPIC_API_KEY=sk-ant-... # OpenAI OPENAI_API_KEY=sk-... # Disable AI (keep manual editing only) FILAMENT_TRANSLATABLE_AI_ENABLED=false
See the laravel/ai documentation for all supported providers.
Panel Plugin Setup
Register the plugin in your PanelProvider:
use Backtik\FilamentTranslatable\FilamentTranslatablePlugin; public function panel(Panel $panel): Panel { return $panel ->plugin( FilamentTranslatablePlugin::make() ->languages(['fr', 'de', 'en']) ->sourceLocale('fr') ->aiProvider('openai') ->aiModel('gpt-4o-mini') ); }
All plugin methods are optional — values fall back to the config file.
Usage
Model Setup
Your model must use spatie/laravel-translatable and the translatable columns must be json in the database:
use Spatie\Translatable\HasTranslations; class Post extends Model { use HasTranslations; public $translatable = ['title', 'description']; }
Form Field
use Backtik\FilamentTranslatable\Forms\Components\TranslatableInput; // Simple text input (short content like titles) TranslatableInput::make('title') // Textarea for longer content TranslatableInput::make('description')->inputType('textarea') // Inline mode — all locale fields rendered directly in the form TranslatableInput::make('title')->inline() // Inline textarea TranslatableInput::make('description')->inline()->inputType('textarea')
Modal mode (default)
The field displays the source locale value as a readonly preview. Clicking the translate button opens a modal where you can:
- Edit translations for each configured language
- Select a source language
- Click "Generate translations" to auto-translate all languages in one AI call
Inline mode
All locale fields are rendered directly in the form without requiring a modal. The AI generation section is also displayed inline. Best suited for forms where you want all translations visible at a glance.
Infolist Entry
use Backtik\FilamentTranslatable\Infolists\Components\TranslatableEntry; // Inline mode (default) — shows all translations with expand/collapse TranslatableEntry::make('title') // Modal mode — shows source text, click to view all translations in a modal TranslatableEntry::make('description')->modal() // Truncate text to a specific number of lines TranslatableEntry::make('description')->lineClamp(3) TranslatableEntry::make('description')->modal()->lineClamp(2)
Inline mode (default)
Displays the first language inline with an expandable section to reveal the remaining translations.
Modal mode
Displays the source locale text directly. A "View translations" link opens a Filament modal showing all translations. Best for longer text content.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.