<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
solution-forest / filament-translate-field example snippets
use SolutionForest\FilamentTranslateField\FilamentTranslateFieldPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(FilamentTranslateFieldPlugin::make());
}
use SolutionForest\FilamentTranslateField\FilamentTranslateFieldPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
FilamentTranslateFieldPlugin::make()
->defaultLocales(['en', 'es', 'fr']),
);
}
use SolutionForest\FilamentTranslateField\Facades\FilamentTranslateField;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
FilamentTranslateField::defaultLocales(['en', 'es', 'fr']);
}
}
return [
'locales' => ['en', 'es', 'fr'],
];
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\RichEditor;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->schema([
// Your form fields here
])
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()->locales(['en', 'es'])
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->schema([
// Fields
])
->prefixLocaleLabel()
->suffixLocaleLabel()
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->preformLocaleLabelUsing(fn (string $locale, string $label) => "[{$label}]");
use Filament\Forms\Components\Component;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
// ...
->prefixLocaleLabel(function(Component $field) {
// need return boolean value
return $field->getName() == 'title';
})
->suffixLocaleLabel(function(Component $field) {
// need return boolean value
return $field->getName() == 'title';
})
use Filament\Forms\Components\Actions\Action;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->actions([
Action::make('fillDumpTitle')
])
use Filament\Forms\Components\Actions\Action;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->actions([
Action::make('fillDumpTitle')
->action(function (array $arguments) {
$locale = $arguments['locale'];
// ...
})
])
use Filament\Forms\Components\TextInput;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->schema(fn (string $locale) => [TextInput::make('title')->
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make()
->contained(false)
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
Translate::make([
Forms\Components\TextInput::make('title'),
Forms\Components\TextInput::make('description'),
])
->exclude(['description'])
use SolutionForest\FilamentTranslateField\FilamentTranslateFieldPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(FilamentTranslateFieldPlugin::make()
->defaultLocales(['en', 'es', 'fr'])
);
}
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\RichEditor;
use Filament\Resources\Resource;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
class NewsResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Translate::make()
->columnSpanFull()
->columns(2)
->schema([
TextInput::make('title')->nts) {
$locale = $arguments['locale'] ?? null;
if (! $locale) {
return;
}
$set("title.$locale", fake()->text(50));
})
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\ColumnGroup::make('Data')
->columns([
Tables\Columns\TextColumn::make('title')
->getStateUsing(fn ($record) => new HtmlString(collect($record->title)
->map(fn ($state, $locale) => <<<Html
<div class="flex gap-2">
<div class="text-sm text-gray-500">$locale</div>
<div>$state</div>
</div>
Html)
->implode(''))),
Tables\Columns\TextColumn::make('short_desc')
->getStateUsing(fn ($record) => new HtmlString(collect($record->short_desc)
->map(fn ($state, $locale) => <<<Html
<div class="flex gap-2">
<div class="text-sm text-gray-500">$locale</div>
<div>$state</div>
</div>
Html)
->implode(''))),
Tables\Columns\TextColumn::make('description')
->getStateUsing(fn ($record) => new HtmlString(collect($record->description)
->map(fn ($state, $locale) => <<<Html
<div class="flex gap-2">
<div class="text-sm text-gray-500">$locale</div>
<div>$state</div>
</div>
Html)
->implode(''))),
]),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}
// ...
}
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class News extends Model
{
use HasTranslations;
// ...
protected $guarded = ['id'];
public $translatable = ['title', 'short_desc', 'description'];
public $casts = [
'title' => 'json',
'short_desc' => 'json',
'description' => 'json',
];
// ...
}