This package is a Filament plugin that allows you to group multilingual fields into tabs. It can be configured which languages are required to be filled out.
Filament | branch/tag |
---|---|
v3.x | main, v2.x |
v2.x | v1.x |
You can install the package via composer:
composer require pixelpeter/filament-language-tabs
You can publish the config file with:
php artisan vendor:publish --tag="filament-language-tabs-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-language-tabs-views"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | Default Locales |-------------------------------------------------------------------------- | | These are the locales this package will use generate the tabs | */ 'default_locales' => ['de', 'en', 'fr'], /* |-------------------------------------------------------------------------- | Required Locales |-------------------------------------------------------------------------- | | These are the locales this package will use to set the field as required | This can be used if one translation or language is optional | */ 'required_locales' => ['de', 'en'],];
composer require spatie/laravel-translatable
// Models/Post.phpclass Post extends Model{ use HasFactory, HasTranslations; public $translatable = ['headline', 'body', 'slug']; protected $casts = [ 'headline' => 'array', 'body' => 'array', 'slug' => 'array', ]; protected $guarded = ['id'];}
// database/migrations...public function up(): void { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->json('headline'); $table->json('slug'); $table->json('body'); $table->timestamps(); }); }...
// app/Filament/Resources/PostResource.php...use Pixelpeter\FilamentLanguageTabs\Forms\Components\LanguageTabs; class PostResource extends Resource{ public static function form(Form $form): Form { return $form ->schema([ Forms\Components\Grid::make(1) ->schema([ LanguageTabs::make([ Forms\Components\TextInput::make('headline')->label('headline')->required(), Forms\Components\TextInput::make('slug')->label('slug'), Forms\Components\MarkdownEditor::make('body')->label('body'), ]), ]), ]); }
// config/filament-language-tabs.phpreturn [ 'default_locales' => ['de', 'en', 'fr'],]
If a field is defined as required
...->schema([ Forms\Components\TextInput::make('headline')->label('headline')->required(), ...]),...
it will only be set as required for the languages configured in required_locals
// config/filament-language-tabs.phpreturn [ 'required_locales' => ['de', 'en'],]
The
headline
is not (marked as) required for French language
./vendor/bin/pest
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.
Full-Stack Engineer from 🇩🇪 who is in ❤️ with the TALL stack and also proficient with Javascript, Typescript, Python and a lot of other stuff because he has to 🤪. Maybe someday there will be a real homepage