An interactive Artisan command that scans your Laravel project for translation keys, translates them using Google's Gemini AI, and generates the necessary language files with advanced safety and performance features.
- AI-Powered Translation: Uses Gemini AI for high-quality translations with context awareness
- Interactive & Cross-Platform: Works on all operating systems with robust fallback
- Flexible Concurrency: Fork driver for Linux/macOS, sync driver for Windows
- Smart Key Detection: Scans Blade, PHP, Vue, JS, and TypeScript files comprehensively
- Framework Integration: Automatic Laravel framework translation bootstrapping
- Three Operational Modes: Full sync, missing-only (
--skip-existing), refresh-only (--refresh) - Production-Ready Safety: Atomic file writes, path validation, and security checks
- Module Support: Full integration with
nwidart/laravel-moduleswith consolidation options
- PHP 8.2 or higher
- Laravel 11.0 or higher
- Google Gemini API key
pcntlextension (for fork driver on Linux/macOS)tokenizerPHP extension (for proper code parsing)
composer require jayesh/laravel-gemini-translator
php artisan vendor:publish --provider="Jayesh\LaravelGeminiTranslator\TranslationServiceProvider"Add to your .env:
GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
GEMINI_REQUEST_TIMEOUT=600Get your API key from Google AI Studio.
config/gemini.php file from the google-gemini-php/laravel package, make sure the request_timeout is cast to an integer:
// ✅ CORRECT
'request_timeout' => (int) env('GEMINI_REQUEST_TIMEOUT', 600),
// ❌ WRONG - Will cause "Configuration value must be an integer" error
'request_timeout' => env('GEMINI_REQUEST_TIMEOUT', 600),# Linux/macOS (fastest with configurable concurrency)
php artisan translations:extract-and-generate --driver=fork --concurrency=10
# Windows (stable)
php artisan translations:extract-and-generate --driver=sync
# Preview changes without writing files
php artisan translations:extract-and-generate --dry-run
# Refresh only existing translations (re-translate existing keys only)
php artisan translations:extract-and-generate --refresh
# Add only missing translations (recommended for updates)
php artisan translations:extract-and-generate --skip-existingFor detailed documentation, step-by-step guides, and advanced usage examples, visit our comprehensive documentation:
# Custom languages (English is always used as source)
php artisan translations:extract-and-generate --langs=en,es,fr,de
# Skip existing translations (translate only missing keys)
php artisan translations:extract-and-generate --skip-existing
# Refresh existing translations (re-translate existing keys only)
php artisan translations:extract-and-generate --refresh
# Preview without writing files
php artisan translations:extract-and-generate --dry-run
# Custom chunk size for API requests
php artisan translations:extract-and-generate --chunk-size=50
# Custom concurrency (when using fork driver)
php artisan translations:extract-and-generate --concurrency=20
# Exclude directories
php artisan translations:extract-and-generate --exclude=vendor,node_modules
# Custom target directory
php artisan translations:extract-and-generate --target-dir=custom-lang
# Provide project context for better translations
php artisan translations:extract-and-generate --context="E-commerce platform with payment features"# Concurrency driver (default, fork, sync)
php artisan translations:extract-and-generate --driver=fork
# Retry settings
php artisan translations:extract-and-generate --max-retries=3 --retry-delay=5
# Custom extensions
php artisan translations:extract-and-generate --extensions=php,blade.php,vue,js,ts,json
# Consolidate module translations
php artisan translations:extract-and-generate --consolidate-modules
# Get help
php artisan help translations:extract-and-generate--refreshand--skip-existingare mutually exclusive (the command will fail if both are used)--dry-runworks with all other options to preview changes--concurrencyonly affects fork driver
lang/
├── en/
│ ├── auth.php
│ ├── pagination.php
│ ├── passwords.php
│ └── validation.php
├── es/
│ ├── auth.php
│ ├── pagination.php
│ ├── passwords.php
│ └── validation.php
├── en.json
├── es.json
└── fr.json
- Templates:
.blade.php - PHP Files:
.php - Frontend:
.vue,.js,.jsx,.ts,.tsx - Configuration:
.json
- Laravel:
__(),trans(),trans_choice(),@lang(),@choice() - Facade:
Lang::get(),Lang::choice(),Lang::has() - Vue:
$t(),i18n.t() - Attributes:
v-t,x-text,:v-t,:x-text,v-bind:v-t,v-bind:x-text
Supports all quote types: single ('), double ("), and backtick (`).
- Automatic locale canonicalization (converts
en-UStoen_US) - Script-aware formatting (title case for English, sentence case for other Latin languages)
- Proper handling for RTL, CJK, Brahmic, and Cyrillic scripts
- Placeholder preservation across all language families
- Placeholder mismatch detection to prevent runtime errors
- Pluralization string handling to maintain Laravel pluralization format
- Smart machine key humanization for better offline placeholders
- Context-aware translation via project-specific context option
- Fork Driver: Parallel processing (Linux/macOS) with configurable processes
- Sync Driver: Sequential processing (Windows/Linux) - more stable
- Configurable Concurrency: Control number of parallel processes
- Atomic File Writes: Temp files with atomic rename to prevent corruption
- Path Validation: Protection against directory traversal attacks
- Memory Optimization: Efficient chunk processing to minimize memory usage
- Retry Logic: Intelligent error handling with differentiated retry strategies
- Automatic Laravel framework translation bootstrapping
- Smart merging of vendor and app translations
- Only updates files when new keys are detected
- Path Validation: All file paths validated against base directory
- Atomic Operations: Temp file strategy prevents partial writes
- Input Sanitization: User inputs and context properly sanitized
- Directory Traversal Prevention: Strict path checking before file operations
- Free tier has 15 RPM / 1000 daily requests
- Use
--retry-delayand--max-retriesfor better rate limit handling - Upgrade to Gemini Pro for higher quotas
- Use
--driver=fork --concurrency=Non Linux/macOS for best performance - Adjust
--chunk-sizebased on API limits (default: 25 keys per request) - Increase
--concurrencycarefully to avoid hitting rate limits
If you see this error:
Configuration value for key [gemini.request_timeout] must be an integer, string given.
Fix: Edit config/gemini.php and cast the timeout to integer:
'request_timeout' => (int) env('GEMINI_REQUEST_TIMEOUT', 600),- Windows: Use
--driver=syncinstead of fork for stability - Large Projects: Use smaller
--chunk-sizeto avoid API timeouts - Module Projects: Ensure
nwidart/laravel-modulesis properly configured - Empty Keys: Package automatically filters empty/whitespace-only keys (v4.0.1+)
- Very Long Keys: Automatic chunk size adjustment for keys >80 characters (v4.0.1+)
- Use
--dry-runto preview changes without writing - Check
translation_extraction_log.jsonfor detailed code extraction - Check
failed_translation_keys.jsonfor failed translations
- Full integration with
nwidart/laravel-modules - Ability to consolidate module translations to main app directory
- Independent module language file management
- Proper separation of application and module keys
- Atomic file operations prevent corruption
- Comprehensive error handling and logging
- Dry-run mode for safe testing
- Configurable concurrency for server environments
- Placeholder safety checking prevents runtime errors
- Multiple fallback chains for translation failures
- Cross-checking between languages
- Validation of translation quality
The MIT License (MIT). Please see License File for more information.
⭐ Star this repo if you find it helpful! | 🐛 Report issues on GitHub | 📖 Read full docs at Here