abdulmajeed-jamaan/filament-translatable-tabs
Installation
composer require abdulmajeed-jamaan/filament-translatable-tabs
Publish the config (if needed):
php artisan vendor:publish --provider="AbdulmajeedJamaan\FilamentTranslatableTabs\FilamentTranslatableTabsServiceProvider"
Register in Filament
Add to your app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->tabs([
Tab::make('Translations')
->translatableTabs(), // <-- Add this line
]);
}
First Use Case
For a translatable model (e.g., using spatie/laravel-translatable):
use AbdulmajeedJamaan\FilamentTranslatableTabs\Tab;
Tab::make('Translations')
->translatableTabs()
->columns(2) // Optional: Adjust layout
->locales(['en', 'fr', 'es']) // Optional: Custom locales
->fields([
TextInput::make('title')->translatable(),
RichEditor::make('description')->translatable(),
]);
Basic Tab Integration Replace default tabs with translatable ones in a Filament resource:
public static function form(Form $form): Form
{
return $form
->schema([
Tab::make('Translations')
->translatableTabs()
->fields([
TextInput::make('name')->translatable(),
Select::make('category')->translatable(),
]),
]);
}
Dynamic Locale Handling Fetch locales dynamically from a config or database:
Tab::make('Translations')
->translatableTabs()
->locales(config('app.available_locales'))
->defaultLocale(app()->getLocale());
Nested Translatable Fields
Combine with other translatable packages (e.g., filament-translatable-fields):
Tab::make('Translations')
->translatableTabs()
->fields([
TranslatableTextInput::make('bio'),
TranslatableRichEditor::make('content'),
]);
Conditional Rendering Show/hide tabs based on user roles or permissions:
Tab::make('Translations')
->translatableTabs()
->visible(fn (User $user) => $user->can('manage_translations')),
Custom Tab Icons/Colors Style tabs per locale:
Tab::make('Translations')
->translatableTabs()
->tabs([
'en' => Tab::make('English')->icon('heroicon-o-globe-americas'),
'fr' => Tab::make('Français')->icon('heroicon-o-globe-europe'),
]);
Spatie Translatable Models
Ensure your model uses HasTranslations trait:
use Spatie\Translatable\HasTranslations;
class Post extends Model
{
use HasTranslations;
public $translatable = ['title', 'content'];
}
Filament Resource Integration
Override editForm or createForm to inject translatable tabs:
public static function form(Form $form): Form
{
return $form->schema([
// ... other fields
Tab::make('Translations')->translatableTabs(),
]);
}
Livewire + Filament Sync
For real-time updates, pair with filament-livewire:
Tab::make('Translations')
->translatableTabs()
->wireModel('translations'); // Sync with Livewire property
Locale Mismatch
translatableTabs() or use a default:
->locales(['en', 'fr']) // Explicit locales
->defaultLocale('en') // Fallback
JSON Serialization Errors
->json() for custom serialization:
TextInput::make('tags')->translatable()->json(),
Caching Conflicts
php artisan filament:cache-clear
Field Validation
->rules() per field:
TextInput::make('title')
->translatable()
->rules(['required', 'max:255']),
Permission Overrides
Tab::make('Translations')
->translatableTabs()
->canSee(fn (User $user) => $user->can('edit_translations')),
Check JSON Output Inspect the raw JSON stored in the database:
$post->getTranslations('en')->toJson();
Log Locale Switches Debug locale changes in the browser console:
console.log(window.FilamentTranslatableTabs.locale);
Validate Model Events
Listen for saving/saved events to debug translation logic:
$model->saved(function ($model) {
\Log::info('Translations saved:', $model->getTranslations());
});
Custom Tab Components Extend the base tab class:
namespace App\Filament\Tabs;
use AbdulmajeedJamaan\FilamentTranslatableTabs\Tab;
class CustomTranslatableTab extends Tab
{
protected static string $view = 'filament-tabs.custom';
}
Override Default Views Publish and modify views:
php artisan vendor:publish --tag="filament-translatable-tabs-views"
Edit resources/views/vendor/filament-translatable-tabs/....
Add Custom Actions Attach actions to translatable tabs:
Tab::make('Translations')
->translatableTabs()
->actions([
Action::make('export')
->label('Export Translations')
->url(fn ($record) => route('translations.export', $record)),
]),
Hook into Translation Events
Listen for translatable-tab-updated events:
event(new TranslatableTabUpdated($record, $locale, $data));
Theme Customization Override Tailwind/AlpineJS via config:
'tab_colors' => [
'en' => 'bg-blue-500',
'fr' => 'bg-green-500',
],
How can I help you explore Laravel packages today?