PHP code example of martin6363 / filament-ai-translator

1. Go to this page and download the library: Download martin6363/filament-ai-translator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

martin6363 / filament-ai-translator example snippets


use Martin6363\FilamentAiTranslator\FilamentAiTranslatorPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentAiTranslatorPlugin::make(),
        ]);
}



return [

    'api_key' => env('GEMINI_API_KEY'),

    'model' => env('GEMINI_MODEL', 'gemini-2.0-flash'),

    'default_locales' => [
        'en',
        'ru',
    ],

];

use Filament\Forms\Components\TextInput;

TextInput::make('title')
    ->aiTranslate();

TextInput::make('title_en')
    ->aiTranslate(['en', 'hy', 'fr', 'es']);

use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;

Section::make('Content')
    ->schema([
        TextInput::make('title')
            ->

use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;

Tabs::make('Translations')
    ->tabs([
        Tab::make('English')
            ->schema([
                TextInput::make('title_en')
                    ->label('Title')
                    ->aiTranslate(['en', 'ru']) // <-- empty parameter = config('filament-ai-translator.default_locales'),

                RichEditor::make('description_en')
                    ->label('Description')
                    ->aiTranslate(['en', 'ru'])
                    ->columnSpanFull(),
            ]),

        Tab::make('Russian')
            ->schema([
                TextInput::make('title_ru')
                    ->label('Title')
                    ->aiTranslate(['en', 'ru']),

                RichEditor::make('description_ru')
                    ->label('Description')
                    ->aiTranslate(['en', 'ru'])
                    ->columnSpanFull(),
            ]),
    ])
    ->columnSpanFull();
bash
php artisan vendor:publish --tag=filament-ai-translator-config
bash
php artisan vendor:publish --tag=filament-ai-translator-translations
bash
php artisan vendor:publish --tag=filament-ai-translator-translations