eii / laravel-ai-locale-generator
AI powered localization generator for Laravel
Package info
github.com/amit-eiitech/laravel-ai-locale-generator
pkg:composer/eii/laravel-ai-locale-generator
dev-main
2026-03-27 08:53 UTC
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2026-03-27 08:56:06 UTC
README
AI-powered localization generator for Laravel applications.
Automatically extracts texts from Blade files, generates locale keys, optionally translates to multiple languages, and safely updates your Blade files.
Features
- Extract texts from Blade files and generate locale keys
- AI-assisted key generation (OpenAI)
- Translation support (Google Translate & DeepL)
- Multi-language locale PHP files (
resources/lang/en/*.php,ja,es, etc.) - Safe Blade rewriting with optional backup
- Dot notation support (
welcome,auth.login) for Blade files - Fully configurable via
config/ai-locale-generator.php - CLI commands for automated workflows
Installation
composer require eii/laravel-ai-locale-generator
Publish the config file:
php artisan vendor:publish --tag=ai-locale-generator-config
Update your .env with API keys:
OPENAI_API_KEY=sk-xxx GOOGLE_TRANSLATE_API_KEY=xxx DEEPL_API_KEY=xxx
Configuration
config/ai-locale-generator.php:
return [ 'provider' => 'openai', 'api_key' => env('OPENAI_API_KEY'), 'model' => 'gpt-4o-mini', 'translator' => 'google', // options: 'google', 'deepl' 'google_api_key' => env('GOOGLE_TRANSLATE_API_KEY'), 'deepl_api_key' => env('DEEPL_API_KEY'), 'backup' => true, // default: backup Blade files before applying ];
Commands
1. Generate Locale Files
php artisan locale:generate <blade_file> [--lang=ja,es]
- Extracts texts from the Blade file
- Creates source language file
resources/lang/en/<blade>.phpautomatically - Translates to languages specified in
--lang(optional) - Example:
php artisan locale:generate welcome --lang=ja,es
2. Apply Keys to Blade
php artisan locale:apply <blade_file> [--backup|--no-backup]
- Replaces original texts with locale keys
- Uses
APP_LOCALEas source language - Optional backup (
.bak) before rewriting - Example:
php artisan locale:apply welcome auth.login --backup
Usage Notes
- Source language is always your
APP_LOCALE(.env). - Translation languages are optional.
- Currently does not handle dynamic variables in texts (e.g.,
:count). Planned for future release. - Supports both single and double-quoted Blade translations.
Example Workflow
- Generate keys & translations:
php artisan locale:generate welcome --lang=ja,es
- Manually edit translations if needed:
// resources/lang/ja/welcome.php 'welcome_message' => 'ようこそ',
- Apply keys to Blade:
php artisan locale:apply welcome
- Now your Blade file uses:
{{ __('welcome.welcome_message') }}
Requirements
- PHP 8.1+
- Laravel 9.0, 10.0, 11.0, 12.0
- Google Translate API V2 (for
googleprovider) - DeepL API (for
deeplprovider)
License
This package is open-sourced software licensed under the MIT license.