This package inspired by this filament-translatable-fields, but allowing filament like customizability on the
Tabs
andFields
components in context of each locale.
Automatically generate tabs for translations.
This was created to be used with spatie/laravel-translatable, but it can be used standalone as well.
You can install the package via composer:
composer require abdulmajeed-jamaan/filament-translatable-tabs
Then in any registered service provider boot()
method configure the following:
TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component // locales labels ->localesLabels([ 'ar' => __('locales.ar'), 'en' => __('locales.en') ]) // default locales ->locales(['ar', 'en']);});
// Single FieldTextInput::make('title') ->translatableTabs(); // Multiple FieldsTranslatableTabs::make('anyLabel') ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]);
You can customize Tab
and Field
based on locale using the following methods:
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 methodTranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField);}); // Single FieldTextInput::make() ->translatableTabs() ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField) // Multiple FieldsTranslatableTabs::make('anyLabel') ->modifyTabsUsing($customizeTab) ->modifyFieldsUsing($customizeField) ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]);
You can add the method locale
to change it on the fly:
$localesFn = function () { return ['ar', 'en']; // also you can override label using: return [ 'ar' => 'Arabic', 'en' => 'English' ]}// Single FieldTextInput::make('title') ->translatableTabs() ->locales($localesFn); // Multiple FieldsTranslatableTabs::make('anyLabel') ->locales($localesFn) ->schema([ Forms\Components\TextInput::make("title"), Forms\Components\Textarea::make("content") ]);
In order to have similar experience to the preview set the following:
TranslatableTabs::configureUsing(function (TranslatableTabs $component) { $component ->addDirectionByLocale() ->addEmptyBadgeWhenAllFieldsAreEmpty(emptyLabel: __('locales.empty')) ->addSetActiveTabThatHasValue();});
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.