kpebedko22/filament-translation

Package for simply translate filament components.

v1.0.0 2023-08-17 14:58 UTC

This package is auto-updated.

Last update: 2024-10-31 00:18:59 UTC


README

Installation

Install package with composer:

composer require kpebedko22/filament-translation

Publish config:

php artisan vendor:publish --tag=filament-translation-config

Usage

Main purpose is using in filament resources and relation managers. To avoid duplicating of calling label and placeholder methods with passing similar parameters.

TextInput::make('title')
    ->label(__('filament/resource/example.common.title'))
    ->placeholder(__('filament/resource/example.placeholder.title')),

Filament Resource

use Filament\Resources\Resource;
use Kpebedko22\FilamentTranslation\Traits\Translatable;

class ExampleResource extends Resource
{
    use Translatable;

    public static function translation(): FilamentTranslation
    {
        return FilamentTranslation::make(static::class, 'example');
    }
    
    public static function form(Form $form): Form
    {
        return $form
            ->schema(self::trans([
                Forms\Components\TextInput::make('title'),
                Forms\Components\TextInput::make('slug'),
                Forms\Components\Textarea::make('description'),
            ]));
    }
    
    public static function table(Table $table): Table
    {
        return $table
            ->columns(self::trans([
                Tables\Columns\TextColumn::make('title'),
            ]))
            ->filters(self::trans([
                Tables\Filters\SelectFilter::make('author_id'),
            ]))
            ->actions([])
            ->bulkActions([]);
    }
}