First, create a language file in your base language (typically en). For this example, we’ll create a simple authentication messages file:
lang/en/auth.php
<?phpreturn [ 'failed' => 'These credentials do not match our records.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',];
Now you’re ready to translate your language files. Run the translate command:
php artisan translate
You’ll see output similar to this:
AI TranslatorSource: enLanguages: de, es, frDomains: authTranslating from en to de: auth3 missing keys found: failed, password, throttle ┌ Translating in 1 chunks... (attempt #1 of 3) ──────────────┐ │ ████████████████████████████████████████████████████ 100% │ └──────────────────────────────────────────────────────────────┘Generated translations for auth from en to de:failed: "Diese Zugangsdaten stimmen nicht mit unseren Unterlagen überein."password: "Das angegebene Passwort ist falsch."throttle: "Zu viele Anmeldeversuche. Bitte versuchen Sie es in :seconds Sekunden erneut."Writing translations for auth from en to de
The package will:
Detect all languages in your lang directory
Find missing translations for each language
Use AI to generate contextually appropriate translations
The package creates new language files for each target language:
lang/de/auth.php
<?phpreturn [ 'failed' => 'Diese Zugangsdaten stimmen nicht mit unseren Unterlagen überein.', 'password' => 'Das angegebene Passwort ist falsch.', 'throttle' => 'Zu viele Anmeldeversuche. Bitte versuchen Sie es in :seconds Sekunden erneut.',];
Notice how the AI preserves the :seconds placeholder in the translation. The LLM is context-aware and understands Laravel’s translation placeholders.
When you add new keys to your base language file, simply run the translate command again:
lang/en/auth.php
<?phpreturn [ 'failed' => 'These credentials do not match our records.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 'locked' => 'Your account has been locked.', // New key];
php artisan translate
The package will detect the missing locked key and translate only that key:
Translating from en to de: auth1 missing keys found: lockedGenerated translations for auth from en to de:locked: "Ihr Konto wurde gesperrt."
The package only translates missing keys by default. Existing translations are preserved to maintain consistency and avoid unnecessary API calls.