artryazanov / artisan-translator
A Laravel package to extract Blade translation strings and translate them using AI.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:laravel-package
pkg:composer/artryazanov/artisan-translator
Requires
- php: ^8.2
- google-gemini-php/laravel: ^2.0
- illuminate/console: ^11.0|^12.0
- illuminate/contracts: ^11.0|^12.0
- illuminate/filesystem: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- symfony/finder: ^7.0
Requires (Dev)
- laravel/pint: ^1.24
- mcamara/laravel-localization: ^2.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
Artisan Translator is a Laravel package that helps you:
- extract translation strings from Blade templates like
__('...')and@lang('...')(ignoring already externalized keys such asfile.key), - store them under
resources/lang/{locale}/{root}/...(defaults: localeen, rootblade), - replace literals in Blade with generated keys (e.g.,
__('blade.path.key')), - translate those files into other languages via the Gemini API (
google-gemini-php/laravel).
Installation
Install via Composer:
composer require artryazanov/artisan-translator
Laravel will auto-discover the service provider.
Optionally publish the config:
php artisan vendor:publish --provider="Artryazanov\ArtisanTranslator\ArtisanTranslatorServiceProvider" --tag="config"
Add your GEMINI_API_KEY to your application's .env file.
Configuration (config/artisan-translator.php)
source_language— the source language of Blade literals (default:en).lang_root_path— the root folder underresources/lang/{locale}for generated files (default:blade).ai_request_delay_seconds— minimal interval between consecutive AI requests in seconds (default:2.0). The actual sleep before the next request ismax(0, delay - previous_request_duration). You can override via ENVARTISAN_TRANSLATOR_AI_DELAY.gemini.api_key,gemini.model— Gemini settings (default model:gemma-3-27b-it). Supported models via enum:gemini-2.5-pro,gemini-2.5-flash,gemini-2.5-flash-lite,gemma-3-27b-it. You can override via ENVGEMINI_MODEL.mcamara_localization_support— iftrueandmcamara/laravel-localizationis installed, target languages can be auto-detected.
Commands
translate:extract
Scans resources/views (or a subdirectory) and extracts strings.
Options:
--path=limit scanning to a subdirectory ofresources/views;--dry-runshow what would change without writing files;--forceoverwrite existing keys in lang files.
translate:ai
Translates strings found under resources/lang/{source}/{root} to other languages.
Arguments/options:
source— source language (defaults to config value),--targets=*— list of target languages (can be specified multiple times),--force— overwrite existing translations.
Notes:
- The command respects the configured
ai_request_delay_seconds, waitingmax(0, delay - previous_request_duration)between AI requests. - If
--targetsis not provided andmcamara_localization_support=true, andmcamara/laravel-localizationis installed, targets are taken fromLaravelLocalization::getSupportedLocales().
translations:cleanup
Finds translation keys that are defined in language files but not used in your app code, removes them, and deletes empty language files.
Options:
--dry-runshow unused keys without deleting anything;--forceskip the confirmation prompt.
Configuration:
- Publish the config if needed:
php artisan vendor:publish --provider="Artryazanov\ArtisanTranslator\ArtisanTranslatorServiceProvider" --tag="config"
- Configure scan paths, file extensions, and translation functions in
config/translation-cleaner.php.
Safety note:
- This command is destructive. Always run with
--dry-runfirst and ensure your project is under version control.
Testing
This package ships with unit and feature tests (Pest + Orchestra Testbench):
composer test
License
Unlicense. See LICENSE.md.