PHP code example of aar / laravel-auto-translator

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

    

aar / laravel-auto-translator example snippets


return [
    'locales'       => ['en', 'ar', 'fr', 'es'],
    'source_locale' => 'en',
    'storage'       => 'both',          // 'file', 'database', or 'both'
    'scan_paths'    => ['app', 'resources'],
    'excluded_dirs' => ['vendor', 'node_modules', 'storage'],
    'translator'    => env('AAR_TRANSLATOR_PROVIDER', 'libretranslate'),
    'memory'        => ['enabled' => true, 'driver' => 'database'],
    'dashboard'     => [
        'enabled'    => true,
        'path'       => 'admin/translations',
        'middleware' => ['web'],
    ],
];

'dashboard' => [
    'enabled'    => true,
    'path'       => 'admin/translations',
    'middleware' => ['web', 'auth'],        // Require authenticated users
    // Or with permissions:
    // 'middleware' => ['web', 'can:manage-translations'],
],

// config/aar-translator.php
'memory' => [
    'enabled' => true,
    'driver'  => 'database',   // 'database' or 'cache'
],

use Aar\AutoTranslator\Translators\TranslatorInterface;

class MyCustomTranslator implements TranslatorInterface
{
    public function translate(string $text, string $targetLang, string $sourceLang = 'en'): string
    {
        // your implementation
    }

    public function translateBatch(array $texts, string $targetLang, string $sourceLang = 'en'): array
    {
        return array_map(fn($t) => $this->translate($t, $targetLang, $sourceLang), $texts);
    }

    public function getProviderName(): string
    {
        return 'my-custom-translator';
    }
}
bash
php artisan vendor:publish --tag=aar-translator-config
bash
php artisan migrate
bash
# Preview dead keys without deleting (dry run)
php artisan aar:clean --dry-run

# Delete dead keys (with confirmation prompt)
php artisan aar:clean

# Delete without confirmation
php artisan aar:clean --force
bash
php artisan aar:export               # JSON (default)
php artisan aar:export --format=csv  # CSV
php artisan aar:export --format=zip  # ZIP (one JSON per locale)
php artisan aar:export --locale=ar   # Export single locale
bash
php artisan aar:status
bash
# Add a new locale
php artisan aar:lang add de

# Remove a locale
php artisan aar:lang remove es