eii / laravel-locale-generator
A Laravel CLI to extract and translate Blade file strings to JSON language files
1.0.0
2025-08-07 04:25 UTC
Requires
- php: ^8.1
- google/cloud-translate: ^2.0
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
README
A Laravel CLI command to extract __()
strings from Blade files and translate them to JSON language files using Google Cloud Translate or DeepL.
Installation
composer require eii/laravel-locale-generator
Setup
-
Publish Configuration:
php artisan vendor:publish --tag=config
-
Configure Translation Providers:
- Google Cloud Translate:
- Create a Google Cloud service account and download the JSON key file.
- Place the key file in
storage/app/google-credentials.json
or update the path inconfig/locale-generator.php
. - Add to
.env
:GOOGLE_TRANSLATE_KEY_FILE=/path/to/google-credentials.json GOOGLE_PROJECT_ID=your-project-id
- DeepL:
- Obtain a DeepL API key (free tier available).
- Add to
.env
:DEEPL_API_KEY=your-deepl-api-key
- Google Cloud Translate:
Usage
php artisan lang:extract welcome --locales=ja,es,de --translate=google php artisan lang:extract mail.notification --locales=fr,es --translate=deepl
file
: Blade file name (e.g.,welcome
,mail.notification
).--locales
: Comma-separated list of target locales (e.g.,ja,es,de
).--translate
: Translation provider (google
ordeepl
).
Configuration
Edit config/locale-generator.php
to customize:
views_path
: Directory for Blade files (default:resources/views
).google_translate.key_file
: Path to Google Cloud service account JSON key.google_translate.project_id
: Google Cloud project ID.deepl_api_key
: DeepL API key.
Requirements
- PHP 8.1+
- Laravel 9.0, 10.0, or 11.0
- Google Cloud Translate API (for
google
provider) - DeepL API (for
deepl
provider)
License
MIT