Add a translation assistant to the panel
Each field's original sits beside the field to write, and a translation that fell behind shows what the original said when it was translated and what it says now, word by word. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
34
app/Filament/Support/TranslateAction.php
Normal file
34
app/Filament/Support/TranslateAction.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Filament\Pages\TranslationAssistant;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* "Translate into…": this record in the translation assistant, one entry per
|
||||
* language there is to translate into.
|
||||
*/
|
||||
final class TranslateAction
|
||||
{
|
||||
public static function make(): ActionGroup
|
||||
{
|
||||
$default = (string) config('locales.default');
|
||||
|
||||
return ActionGroup::make(collect(config('locales.supported'))
|
||||
->except($default)
|
||||
->map(fn (array $meta, string $locale) => Action::make("translate_{$locale}")
|
||||
->label($meta['native'] ?? $locale)
|
||||
->url(fn (Model $record) => TranslationAssistant::urlFor($record, $locale)))
|
||||
->values()
|
||||
->all())
|
||||
->label(__('panel.translate.action'))
|
||||
->icon('heroicon-o-language')
|
||||
->color('gray')
|
||||
->button();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user