jayesh/laravel-gemini-translator
Interactive Artisan command to scan Laravel projects for translation keys, translate them via Google Gemini AI, and generate language files. Supports Blade/PHP/JS/Vue/TS, concurrency, safe atomic writes, and Laravel Modules integration with skip/refresh modes.
usleep() β Sleep::usleep() - Laravel sleep helpersprintf() instead of string concatenation for complex messagescount() > 0 β !== []$e β $throwabledeclare(strict_types=1) to all PHP files for type safetyLocaleHelper and TextHelper utilitiesCommandRegistration, ServiceProvider, ScannerService, and FileSystemServiceempty() with explicit array/string comparisons (=== [], !== [])in_array(): Added true parameter for strict type checking(int) casts for chunk-size, retry-delay, and concurrency optionsusleep() calls to use int instead of floatThis patch focuses on observability and debugging quality for failed translation chunks.
TranslationService when a translation task fails:
500 to 10000 characters for better visibility into malformed or partial model output.4.0.2.This patch fixes a file-generation side effect introduced in v4.0.x when users selected only JSON translation groups.
A focused stability release that addresses edge cases discovered in production use and adds intelligent optimizations for complex translation scenarios.
The package now automatically adjusts chunk sizes based on key complexity:
storage/logs/laravel.log with full contextconfig/gemini.php type casting requirementBefore v4.0.1:
After v4.0.1:
The Architectural Revolution Update
This is the biggest upgrade ever, transforming the tool into a production-grade, enterprise-ready translation automation platform with enhanced safety, smarter extraction, and powerful new operational modes.
--source option (use interactive selection)--no-advanced option (pattern detection simplified)en-US β en_US)--refresh and --skip-existing modesRefresh Mode β Re-translate only existing keys without adding new ones. Perfect for improving translation quality without expanding your key set.
Dry Run Mode β Preview all changes before writing files. See exactly what would be modified without touching disk.
Configurable Concurrency β Control parallel processing speed with adjustable concurrent process limits.
Update your composer dependency to version 4.0:
composer require jayesh/laravel-gemini-translator:^4.0
--dry-run flag to preview changesVersion 4.0 provides production-grade reliability with architectural improvements, security hardening, and powerful new workflows. Whether you're managing a single application or multiple modules, this release offers the tools and safety features needed for enterprise-scale translation management.
This release builds directly on the foundation of the "Enterprise Edition" (v3.7) by focusing on rock-solid reliability, output quality, and cross-platform compatibility. We've eliminated annoying placeholders, fixed critical output bugs, and ensured the tool works flawlessly for Windows and CI/CD users.
TL;DR: The tool is now automation-friendly and diff-friendly. It skips interactive prompts in CI/CD, guarantees stable file sorting, and hardens the AI integration with intelligent fallbacks.
"NEEDS TRANSLATION"!The most requested improvement is here. If the AI fails to return a translation, the system now intelligently falls back to the known en source text or the key itself. Your generated files are always usable and ready for review, not filled with useless placeholders.
The prompt sent to Gemini has been re-engineered with a stricter rule set. This resolves a critical bug where the AI would create nested objects in JSON files. All JSON output is now guaranteed to be flat and valid.
Generated PHP translation files are now sorted recursively. This ensures that not only top-level keys but also all nested array keys are sorted alphabetically, leading to clean, stable, and minimal diffs in your version control.
The tool now detects non-interactive environments (like GitHub Actions, Docker) and automatically proceeds without hanging on prompts. It also includes a dedicated, functional prompt for Windows users, ensuring a smooth experience for everyone.
Please read these notes carefully before upgrading.
enThe --langs option now defaults to en only (previously en,ru,uz) to prevent accidental multi-language runs.
php artisan translations:extract-and-generate --langs=en,ru,uz
The new recursive sorting will likely reorder nested arrays in your existing PHP language files.
showWelcome() method from (v3.7) to (v3.8) for consistency.ksortRecursive() method added and implemented when writing PHP language files.promptForMultiChoice().staticStructureTranslationsFromGemini() now uses the $sourceTextMap instead of generating placeholders.staticTranslateKeysWithGemini() is now much stricter to enforce flat JSON and improve consistency.loadFrameworkTranslations() now safely iterates files and filters by extension.$sourceTextMap to ensure correct fallbacks in fork mode.--langs option in the command signature is now en.This release transforms the tool into an enterprise-grade utility, introducing comprehensive support for modular applications and a complete overhaul of the AI translation engine for superior accuracy and reliability. This is the most significant update yet, addressing core architectural limitations and delivering the features needed for complex, modern Laravel projects.
nwidart/laravel-modules)The tool is now fully aware of modular architectures, with new features and critical fixes for robust handling.
nwidart modules.lang directory within each module (Modules/YourModule/lang/), keeping your translations perfectly organized.lang/ directory. This is offered as an interactive prompt or can be forced with the --consolidate-modules flag.We've completely re-architected the way we interact with the AI, eliminating a whole class of bugs and dramatically improving translation quality.
auth.failed or "Save Changes") directly to Gemini with a new, advanced prompt that instructs the AI on how to interpret them based on Laravel conventions.'welcome' => 'messages.welcome').The logic for identifying and grouping keys has been made far more robust.
Settings module is correctly associated with the Settings module's translation files..php files from sentence-like strings.If the GEMINI_API_KEY is not set, the tool now enters a dedicated Offline Mode, generating placeholder files with the key as the value. This is perfect for initial setup or working without an internet connection.
--contextYou can now use the optional --context flag to provide a short description of your project directly to the AI. This is crucial for applications in domains like finance, healthcare, legal, or any field with specialized vocabulary.
How it works: The command injects your description into the AI prompt, helping it understand the specific meaning of ambiguous words.
Example: Financial Application Without context, the AI might translate "position" as a physical location. With context, it understands it as a financial holding.
# NEW: Provide context for a financial trading platform
php artisan translations:extract-and-generate --context="A SaaS platform for financial trading of stocks. Terms like 'position' and 'security' refer to financial concepts."
This update makes the translator significantly more robust and intelligent, ensuring higher-quality translations and a smoother developer experience.
How can I help you explore Laravel packages today?