PHP code example of statikbe / laravel-ai-translation

1. Go to this page and download the library: Download statikbe/laravel-ai-translation 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/ */

    

statikbe / laravel-ai-translation example snippets


use Statikbe\AiTranslation\AiTranslationService;

// Single string
app(AiTranslationService::class)->translate('Hello world', 'en', 'nl');

// Batch
app(AiTranslationService::class)->translateBatch(
    ['greeting' => 'Hello', 'farewell' => 'Goodbye'],
    'en', 'nl'
);

// Translate all missing keys for a locale (

use Statikbe\AiTranslation\Facades\AiTranslation;

AiTranslation::translate('Hello', 'en', 'nl');
AiTranslation::driver('libretranslate')->translateBatch(['key' => 'text'], 'en', 'nl');

'prompts' => [
    'system' => 'Your custom global prompt here.',
    'group_overrides' => [
        // Append to global prompt:
        'validation' => 'Keep validation messages concise and user-friendly.',
        // Fully replace the global prompt:
        'emails' => [
            'prompt'  => 'You are translating marketing email content. Use a warm, professional tone.',
            'replace' => true,
        ],
    ],
],
bash
php artisan vendor:publish --tag=ai-translation-config
bash
php artisan vendor:publish --tag=ai-translation-views
bash
php artisan ai-translation:translate nl
bash
php artisan ai-translation:translate nl
bash
php artisan queue:work --queue=translations