### Install Filament Translatable Tabs via Composer Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Installs the package using Composer. This is the first step to integrate the package into your Laravel project. ```bash composer require abdulmajeed-jamaan/filament-translatable-tabs ``` -------------------------------- ### Installing Filament Translatable Tabs Package Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Instructions for installing the filament-translatable-tabs package using Composer. The package utilizes Laravel's auto-discovery feature, so no further service provider registration is typically required. This command downloads and integrates the package into your Laravel project. ```bash # Install via Composer composer require abdulmajeed-jamaan/filament-translatable-tabs # Package auto-discovers via Laravel's package discovery ``` -------------------------------- ### Filament Resource Integration with Translatable Fields Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Example of integrating the TranslatableTabs component into a Filament resource. This demonstrates how to handle both single and multiple translatable fields, including custom locale configurations. It requires the 'filament/forms' and 'abdulmajeed-jamaan/filament-translatable-tabs' packages. ```php use App\Models\Product; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\RichEditor; use Filament\Forms\Components\Select; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; class ProductResource extends Resource { protected static ?string $model = Product::class; public static function form(Form $form): Form { return $form->schema([ // Non-translatable fields TextInput::make('sku') ->required() ->unique(ignoreRecord: true), TextInput::make('price') ->numeric() ->prefix('$') ->required(), Select::make('category_id') ->relationship('category', 'name') ->required(), // Single translatable field TextInput::make('name') ->translatableTabs() ->required(), // Multiple translatable fields grouped TranslatableTabs::make('product_content') ->schema([ TextInput::make('title') ->maxLength(255) ->required(), Textarea::make('short_description') ->rows(3) ->maxLength(500), RichEditor::make('full_description') ->columnSpanFull() ->fileAttachmentsDirectory('products/descriptions') ]), // SEO fields with custom locales TranslatableTabs::make('seo') ->locales(['en', 'ar']) ->schema([ TextInput::make('meta_title') ->maxLength(60) ->helperText('Recommended: 50-60 characters'), Textarea::make('meta_description') ->maxLength(160) ->rows(2) ->helperText('Recommended: 150-160 characters') ]) ]); } } ``` -------------------------------- ### Database Schema for Translatable Fields Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Example of a Laravel migration file defining a 'products' table with JSON columns for translatable attributes. This structure is necessary for storing multi-language content directly in the database. It uses the standard Laravel Schema Builder. ```php // migrations/create_products_table.php Schema::create('products', function (Blueprint $table) { $table->id(); $table->string('sku')->unique(); $table->decimal('price', 10, 2); $table->foreignId('category_id')->constrained(); $table->json('name'); // {'en': 'Product Name', 'ar': 'اسم المنتج'} $table->json('title'); $table->json('short_description')->nullable(); $table->json('full_description')->nullable(); $table->json('meta_title')->nullable(); $table->json('meta_description')->nullable(); $table->timestamps(); }); ``` -------------------------------- ### Global Configuration for TranslatableTabs in PHP Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Shows how to configure default settings for all `TranslatableTabs` components application-wide using a service provider. This allows setting default locales and locale labels that will be applied automatically. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot(): void { TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->localesLabels([ 'ar' => __('locales.ar'), 'en' => __('locales.en'), 'fr' => __('locales.fr') ]) ->locales(['ar', 'en', 'fr']); }); } } // Now all TranslatableTabs instances use these settings by default TranslatableTabs::make('content') ->schema([ TextInput::make('title'), Textarea::make('body') ]); // Automatically uses ['ar', 'en', 'fr'] locales ``` -------------------------------- ### Auto-Activate Tab with Value Enhancement for Translatable Tabs Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Automatically activates the first tab that contains data, rather than always defaulting to the first tab in the sequence. This improves usability by directly showing the user relevant content. It can be configured globally or per component instance. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Filament\Forms\Components\TextInput; TranslatableTabs::make('content') ->addSetActiveTabThatHasValue() ->locales(['en', 'ar', 'fr']) ->schema([ TextInput::make('title'), TextInput::make('subtitle') ]); // Example: If record has data: // ['title' => ['en' => '', 'ar' => 'عنوان', 'fr' => '']] // The Arabic tab will be automatically active when form loads // Global configuration TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component->addSetActiveTabThatHasValue(); }); ``` -------------------------------- ### Apply Pre-made Configurations to TranslatableTabs Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Applies pre-made configurations to the TranslatableTabs component globally. These include adding direction based on locale, an empty badge when fields are empty, and setting the active tab to one with a value. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->addDirectionByLocale() ->addEmptyBadgeWhenAllFieldsAreEmpty(emptyLabel: __('locales.empty')) ->addSetActiveTabThatHasValue(); }); ``` -------------------------------- ### Configure TranslatableTabs Component Globally Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Configures the TranslatableTabs component globally within a service provider's boot method. Allows setting locale labels and default locales. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component // locales labels ->localesLabels([ 'ar' => __('locales.ar'), 'en' => __('locales.en') ]) // default locales ->locales(['ar', 'en']); }); ``` -------------------------------- ### TranslatableTabs Component Usage in PHP Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Demonstrates how to use the TranslatableTabs component to create grouped tabbed interfaces for multiple form fields. It shows basic usage, custom locale configuration, and the expected data structure for translated fields. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\RichEditor; // Basic usage with multiple fields TranslatableTabs::make('content') ->schema([ TextInput::make('title')->required(), Textarea::make('description')->rows(3), RichEditor::make('body')->columnSpanFull() ]); // With custom locales and labels TranslatableTabs::make('product_details') ->locales([ 'en' => 'English', 'ar' => 'العربية', 'fr' => 'Français' ]) ->schema([ TextInput::make('name'), Textarea::make('description') ]); // Expected data structure // [ // 'title' => ['en' => 'English Title', 'ar' => 'العنوان العربي'], // 'description' => ['en' => 'Description', 'ar' => 'الوصف'] // ] ``` -------------------------------- ### Configure TranslatableTabs in AppServiceProvider (PHP) Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt This snippet demonstrates how to configure the TranslatableTabs component within the AppServiceProvider. It shows two options: minimal configuration for basic locale settings and full configuration allowing for custom locale labels, dynamic locale sourcing, UX enhancements, and modifications to tabs and fields based on locale. ```php // Optional: Configure in AppServiceProvider // app/Providers/AppServiceProvider.php use IlluminateSupportServiceProvider; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTab; use Filament\Forms\Components\Field; class AppServiceProvider extends ServiceProvider { public function boot(): void { // Option 1: Minimal configuration TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component->locales(['en', 'ar', 'fr']); }); // Option 2: Full configuration with all features TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component // Define locales with labels ->localesLabels([ 'ar' => 'العربية', 'en' => 'English', 'fr' => 'Français', 'es' => 'Español', 'de' => 'Deutsch' ]) // Set active locales (can be dynamic) ->locales(fn () => config('app.available_locales', ['en'])) // Add pre-made UX enhancements ->addDirectionByLocale() ->addEmptyBadgeWhenAllFieldsAreEmpty('Empty') ->addSetActiveTabThatHasValue() // Custom tab modifications ->modifyTabsUsing(function (TranslatableTab $tab, string $locale) { // Add icons $icons = [ 'ar' => 'heroicon-o-language', 'en' => 'heroicon-o-flag', 'fr' => 'heroicon-o-globe-alt' ]; if (isset($icons[$locale])) { $tab->icon($icons[$locale]); } // Highlight primary locale if ($locale === config('app.locale')) { $tab->badge('Primary')->badgeColor('success'); } }) // Custom field modifications ->modifyFieldsUsing(function (Field $field, string $locale) { // Make primary locale required if ($locale === config('app.locale')) { $field->required(); } // Add RTL/LTR helper text $direction = str($locale)->startsWith('ar') ? 'RTL' : 'LTR'; $field->hint($direction); }); }); } } ``` -------------------------------- ### Dynamically Configure Locales for Translatable Tabs Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Enables dynamic configuration of locales based on runtime data, such as authenticated user permissions or tenant settings. This feature allows for flexible locale management within your application. It accepts a closure that returns an array of locales. ```php use Filament\Forms\Components\TextInput; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; // Based on authenticated user TextInput::make('title') ->translatableTabs() ->locales(function () { return auth()->user()->available_locales ?? ['en']; }); // Based on tenant settings TranslatableTabs::make('content') ->locales(function () { $tenant = Filament::getTenant(); return $tenant->enabled_locales ?? ['en', 'ar']; }) ->schema([ TextInput::make('title'), Textarea::make('description') ]); // With closure for locale labels TranslatableTabs::make('product') ->locales(function () { return collect(config('app.available_locales')) ->mapWithKeys(fn ($name, $code) => [$code => $name]) ->toArray(); }) ->schema([ TextInput::make('name') ]); ``` -------------------------------- ### Optional Locale Configuration in config/app.php (PHP) Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt This snippet shows how to optionally configure application-wide locales in the `config/app.php` file. It includes settings for the default locale, fallback locale, and a custom `available_locales` array which can be used by the TranslatableTabs package for dynamic locale configuration. ```php // config/app.php - Optional locale configuration return [ 'locale' => 'en', 'fallback_locale' => 'en', // Custom configuration for available locales 'available_locales' => [ 'en' => 'English', 'ar' => 'العربية', 'fr' => 'Français' ] ]; ``` -------------------------------- ### Configure Global UX Enhancements for Translatable Tabs Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt This PHP code configures global settings for the TranslatableTabs component within an Illuminate Service Provider. It sets locale labels, available locales, and applies several UX enhancements like direction by locale, an empty badge, and setting the active tab with value. It also demonstrates custom tab styling and locale-specific field validation. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTab; use Filament\Forms\Components\Field; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\RichEditor; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot(): void { TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->localesLabels([ 'ar' => 'العربية', 'en' => 'English', 'fr' => 'Français' ]) ->locales(['ar', 'en', 'fr']) // Apply all UX enhancements ->addDirectionByLocale() ->addEmptyBadgeWhenAllFieldsAreEmpty(emptyLabel: 'Not Translated') ->addSetActiveTabThatHasValue() // Custom tab styling ->modifyTabsUsing(function (TranslatableTab $tab, string $locale) { if ($locale === 'ar') { $tab->icon('heroicon-o-language'); } }) // Locale-specific validation ->modifyFieldsUsing(function (Field $field, string $locale) { if ($locale === 'ar') { $field->required()->helperText('Required field'); } }); }); } } // Usage in Filament Resource public static function form(Form $form): Form { return $form->schema([ TextInput::make('sku')->required(), // Single field with all global enhancements applied TextInput::make('name')->translatableTabs(), // Multiple fields with all global enhancements applied TranslatableTabs::make('content') ->schema([ TextInput::make('title'), Textarea::make('excerpt'), RichEditor::make('description') ]), // Override global settings per instance TextInput::make('meta_title') ->translatableTabs() ->locales(['en', 'ar']), // Only EN and AR ]); } ``` -------------------------------- ### Empty Badge UX Enhancement for Translatable Tabs Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Displays a warning badge on tabs where all fields within that tab are empty. This visually alerts users to incomplete translations. The badge can be customized with a specific label, defaulting to 'Empty'. It can be configured globally or per component instance. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; TranslatableTabs::make('content') ->addEmptyBadgeWhenAllFieldsAreEmpty(emptyLabel: 'Empty') ->schema([ TextInput::make('title'), Textarea::make('description') ]); // If all fields in the Arabic tab are empty, the tab shows: // [Arabic] [Empty badge in warning color] // Global configuration TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component->addEmptyBadgeWhenAllFieldsAreEmpty( emptyLabel: __('locales.empty') ); }); ``` -------------------------------- ### Customizing Translatable Tabs with modifyTabsUsing() in PHP Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Demonstrates how to customize individual tabs within a `TranslatableTabs` component or a single translated field using the `modifyTabsUsing()` method. This allows for applying specific styling, icons, or badges to tabs based on their locale. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTab; use Filament\Forms\Components\TextInput; TranslatableTabs::make('content') ->modifyTabsUsing(function (TranslatableTab $tab, string $locale) { // Add icons per locale if ($locale === 'ar') { $tab->icon('heroicon-o-language'); } // Add badges $tab->badge($locale === 'en' ? 'Primary' : null); // Conditional styling if ($locale === 'fr') { $tab->extraAttributes(['class' => 'text-blue-500']); } }) ->schema([ TextInput::make('title'), TextInput::make('slug') ]); // Can also be used with single field TextInput::make('name') ->translatableTabs() ->modifyTabsUsing(function (TranslatableTab $tab, string $locale) { $tab->icon($locale === 'ar' ? 'heroicon-o-globe-alt' : 'heroicon-o-flag'); }); ``` -------------------------------- ### Globally Customize Tabs and Fields by Locale Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Globally configures how tabs and fields are modified based on the locale. This is done in the service provider's boot method using `modifyTabsUsing` and `modifyFieldsUsing` callbacks. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTab; use Filament\Forms\Components\Field; $customizeTab = function (TranslatableTab $component, string $locale) { // ... }; $customizeField = function (Field $component, string $locale) { // ... }; // Globally in boot method TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField); }); ``` -------------------------------- ### Use TranslatableTabs for Multiple Fields Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Creates a TranslatableTabs component to group multiple form fields, such as a text input and a textarea, allowing translation for each field within the tabs. ```php use Filament\Forms; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; TranslatableTabs::make('anyLabel') ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]); ``` -------------------------------- ### Single Field Translation with Field Macro in PHP Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Illustrates how to use the `translatableTabs()` macro, which is an extension method added to Filament form fields for enabling single-field translation. It covers simple usage, custom locale definition, and locale-specific labels. ```php use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; // Simple single field translation TextInput::make('title')->translatableTabs(); // With custom locales TextInput::make('name') ->translatableTabs() ->locales(['en', 'ar', 'es']); // With locale labels Textarea::make('description') ->translatableTabs() ->locales([ 'en' => 'English', 'ar' => 'Arabic', 'es' => 'Spanish' ]); // Expected data structure for 'title' field // ['title' => ['en' => 'Hello', 'ar' => 'مرحبا']] ``` -------------------------------- ### Automatic RTL/LTR Direction Enhancement for Translatable Tabs Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Automatically sets the text direction (RTL or LTR) for fields based on the detected locale. It defaults to detecting 'ar' for RTL and 'en' for LTR. This enhancement improves the user experience for different language scripts. It can be configured globally or per instance. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\RichEditor; // Global configuration TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component->addDirectionByLocale(); }); // Or per-instance TranslatableTabs::make('content') ->addDirectionByLocale() ->schema([ TextInput::make('title'), RichEditor::make('body') ]); // Resulting HTML for Arabic tab: // // Resulting HTML for English tab: // ``` -------------------------------- ### Customize Tabs and Fields by Locale for Multiple Fields Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Customizes tabs and fields for a TranslatableTabs component containing multiple fields. Uses `modifyTabsUsing` and `modifyFieldsUsing` directly on the `TranslatableTabs` component. ```php use Filament\Forms; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; $customizeTab = function (TranslatableTab $component, string $locale) { // ... }; $customizeField = function (Field $component, string $locale) { // ... }; TranslatableTabs::make('anyLabel') ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField) ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]); ``` -------------------------------- ### Use TranslatableTabs for Single Field Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Applies translatable tabs to a single form field, like a text input. The `translatableTabs()` method enables this functionality. ```php use Filament\Forms\Components\TextInput; TextInput::make('title') ->translatableTabs(); ``` -------------------------------- ### Customize Tabs and Fields by Locale for Single Field Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Customizes tabs and fields for a single translatable field using `modifyTabsUsing` and `modifyFieldsUsing` methods directly on the field. ```php use Filament\Forms\Components\TextInput; $customizeTab = function (TranslatableTab $component, string $locale) { // ... }; $customizeField = function (Field $component, string $locale) { // ... }; TextInput::make() ->translatableTabs() ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField); ``` -------------------------------- ### Customize Translatable Fields with modifyFieldsUsing() Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Allows locale-specific validation, styling, or behaviors for fields within each tab. It processes each field for a given locale, enabling conditional modifications. Dependencies include Filament's Form components and the TranslatableTabs class. ```php use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; use Filament\Forms\Components\Field; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Textarea; TranslatableTabs::make('content') ->modifyFieldsUsing(function (Field $field, string $locale) { // Make Arabic fields required, others optional if ($locale === 'ar') { $field->required(); } else { $field->nullable(); } // Add placeholder per locale if ($field->getName() === 'title.en') { $field->placeholder('Enter English title'); } elseif ($field->getName() === 'title.ar') { $field->placeholder('أدخل العنوان العربي'); } // Conditional max length if ($locale === 'en') { $field->maxLength(255); } }) ->schema([ TextInput::make('title'), Textarea::make('description') ]); // Single field example TextInput::make('meta_title') ->translatableTabs() ->modifyFieldsUsing(function (Field $field, string $locale) { $field->helperText("SEO title for {$locale}"); }); ``` -------------------------------- ### Accessing Translated Data in Laravel Model Source: https://context7.com/abdulmajeed-jamaan/filament-translatable-tabs/llms.txt Demonstrates how to retrieve translated field values from a model instance after it has been saved using JSON columns. This method allows direct access to specific language translations using array notation. Assumes a 'Product' model is set up with the appropriate JSON columns. ```php // Accessing translated data in model: $product = Product::find(1); $englishName = $product->name['en']; // 'Product Name' $arabicTitle = $product->title['ar']; // 'عنوان المنتج' ``` -------------------------------- ### Override Default Locales for Multiple Fields Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Overrides the default locale list for a TranslatableTabs component. The `locales` method accepts a callable returning an array of locales, potentially with custom labels. ```php use Filament\Forms; use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs; $localesFn = function () { return ['ar', 'en']; // also you can override label using: return [ 'ar' => 'Arabic', 'en' => 'English' ] } // Multiple Fields TranslatableTabs::make('anyLabel') ->locales($localesFn) ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]); ``` -------------------------------- ### Override Default Locales for Single Field Source: https://github.com/abdulmajeed-jamaan/filament-translatable-tabs/blob/4.x/README.md Overrides the default locale list for a single translatable field. The `locales` method can accept a callable that returns an array of locales, optionally with custom labels. ```php use Filament\Forms\Components\TextInput; $localesFn = function () { return ['ar', 'en']; // also you can override label using: return [ 'ar' => 'Arabic', 'en' => 'English' ] } // Single Field TextInput::make('title') ->translatableTabs() ->locales($localesFn); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.