parfaitementweb/filament-plugin-translatable-inline
## Getting Started
### Minimal Setup
1. **Install Dependencies**
Update the installation commands to reflect Filament 5 compatibility:
```bash
composer require lara-zeus/spatie-translatable parfaitementweb/filament-plugin-translatable-inline:"^4.1"
Ensure you have Filament v5 installed (this is now required).
Publish Config (if needed)
The package remains mostly configuration-free, but verify config/filament.php includes:
'plugins' => [
// ...
\Parfaitementweb\FilamentPluginTranslatableInline\FilamentPluginTranslatableInlinePlugin::make(),
],
Note: Filament 5 may require additional plugin registration in app/Providers/FilamentPluginServiceProvider.php:
public function register(): void
{
FilamentPluginServiceProvider::register(
plugins: [
\Parfaitementweb\FilamentPluginTranslatableInline\FilamentPluginTranslatableInlinePlugin::make(),
],
);
}
First Use Case: Translatable Model
Add the Translatable trait to your model (unchanged):
use Spatie\Translatable\HasTranslations;
class Post extends Model
{
use HasTranslations;
public $translatable = ['title', 'content'];
}
Then, in your Filament 5 Resource, use the plugin’s field wrapper:
use Parfaitementweb\FilamentPluginTranslatableInline\Fields\TranslatableInlineField;
public static function form(Form $form): Form
{
return $form
->schema([
TranslatableInlineField::make('title')
->required()
->maxLength(255),
// Other fields...
]);
}
View Translations Inline
Open the Filament 5 form—translatable fields now show a language toggle dropdown (e.g., en, fr) and a missing translation indicator (⚠️). The UI may have subtle Filament 5 styling updates (e.g., dark mode support).
Bulk Translation Editing (Filament 5)
TranslatableInlineField::make('title')
->availableLocales(['en', 'fr', 'es'])
->defaultLocale('en')
->modalMaxWidth('4xl') // Customize modal size
->useDrawer(); // Optional: Use Filament 5's drawer instead of modal
Conditional Translatable Fields (Filament 5)
visible() and disabled() methods:TranslatableInlineField::make('content')
->visible(fn ($record) => $record->is_translatable)
->disabled(fn ($record) => !$record->is_editable),
Nested Translatable Relationships (Filament 5)
use Parfaitementweb\FilamentPluginTranslatableInline\Fields\TranslatableInlineRelationship;
TranslatableInlineRelationship::make('comments')
->relationName('translatableComments')
->translatable(['body'])
->resource(\App\Filament\Resources\CommentResource::class); // Explicit resource binding
Customizing the UI (Filament 5)
TranslatableInlineField::make('title')
->languageSelectorPosition('top')
->missingTranslationBadgeIcon('heroicon-o-globe-alt')
->color('success') // Filament 5 color palette
->extraAttributes(['class' => 'filament-translatable-field']);
Validation Across Locales (Filament 5)
TranslatableInlineField::make('title')
->rules([
'en' => ['required', 'max:255'],
'fr' => ['required', 'max:255'],
])
->validationAttribute('title'); // Custom validation message attribute
use Parfaitementweb\FilamentPluginTranslatableInline\Columns\TranslatableInlineColumn;
TranslatableInlineColumn::make('title')
->searchable(isGloballySearchable: true)
->sortable(sort: 'asc')
->toggleable(isToggleable: true),
spatie/laravel-translatable.Filament 5 Migration Issues
app/Providers/FilamentPluginServiceProvider.php is properly configured (see Getting Started).php artisan filament:cache-reset
php artisan optimize:clear
Locale Mismatch (Filament 5)
config/app.php includes all locales:
'locales' => ['en', 'fr', 'es'],
availableLocales match:
TranslatableInlineField::make('title')
->availableLocales(config('app.locales')),
Caching Issues (Filament 5)
livewire:update event debugging:
php artisan filament:livewire-debug
php artisan view:clear
Nested Model Conflicts (Filament 5)
Method [resource] does not exist.TranslatableInlineRelationship::make('comments')
->relationName('comments')
->translatable(['body'])
->resource(CommentResource::class),
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
Filament 5 Plugin Registration
app/Providers/FilamentPluginServiceProvider.php:
public function register(): void
{
FilamentPluginServiceProvider::register(
plugins: [
\Parfaitementweb\FilamentPluginTranslatableInline\FilamentPluginTranslatableInlinePlugin::make(),
],
);
}
config/app.php under providers.php artisan tinker
$post = App\Models\Post::find(1);
$post->getTranslation('title', 'fr'); // Debug translations
config/filament.php:
'plugins' => [
\Parfaitementweb\FilamentPluginTranslatableInline\FilamentPluginTranslatableInlinePlugin::make()
->debug(true) // Logs missing translations and locale issues
->debugMode('dev'), // 'dev' | 'production'
],
Check logs at storage/logs/filament.log.RichEditor):
// In a service provider
\Parfaitementweb\FilamentPluginTranslatableInline\FilamentPluginTranslatableInlinePlugin::macro(
'richEditorTranslatableField',
fn ($attribute) => new \YourNamespace\Fields\RichEditorTranslatableInlineField($attribute)
);
Usage:
TranslatableInlineField::make('content')
How can I help you explore Laravel packages today?