A Laravel package that provides three Artisan commands to fully automate your translation workflow:
| Command | What it does |
|---|---|
localization:extract |
Scans all Blade files for __() / @lang() calls and extracts keys to a JSON file. Optionally auto-translates via Google Translate. |
localization:wrap |
Scans all Blade files and wraps un-translated static text with __() automatically. |
localization:sort |
Sorts any translation JSON file alphabetically by key. |
- PHP 8.1+
- Laravel 10, 11, or 12
- Internet connection (for
localization:extractwith a target language)
composer require smmahfujurrahman/localizationLaravel auto-discovers the service provider. No manual registration needed.
php artisan vendor:publish --tag=localization-configThis creates config/localization.php where you can customise all paths and settings:
return [
// Directory scanned by localization:wrap (default: resources/views)
'views_path' => resource_path('views'),
// Directory used by localization:extract and localization:sort
// null = auto-detect (/lang on Laravel 9+, /resources/lang on older)
'lang_path' => null,
// Microsecond delay between Google Translate API calls (default: 100ms)
'translate_delay' => 100000,
// Backup directory prefix for localization:wrap (null = auto-generate)
'backup_path' => null,
// Filename for the empty key template (no language argument)
'template_filename' => 'template_empty.json',
// Source language for Google Translate (null = auto-detect)
'source_language' => 'en',
];Scan all Blade views and extract every __('...') and @lang('...') key into a JSON file.
# Create an empty template (lang/template_empty.json)
php artisan localization:extract
# Auto-translate to French (creates lang/fr.json)
php artisan localization:extract fr
# Auto-translate to Arabic
php artisan localization:extract ar
# Auto-translate to Bengali
php artisan localization:extract bn
# Auto-translate to German
php artisan localization:extract deSmart re-run: If a target language file already exists, keys that already have a translation are preserved — only new/missing keys are translated. You can re-run safely without overwriting manual edits.
Automatically find static English text in your Blade files and wrap it with __().
# Always preview first!
php artisan localization:wrap --dry-run
# Apply changes to all Blade files
php artisan localization:wrapA timestamped backup of your views directory is created automatically before any files are modified.
Handles 21 patterns including:
- Simple tag text:
<p>Dashboard</p>→<p>{{ __('Dashboard') }}</p> - Dynamic variables:
<span>{{ $type }} Management</span>→<span>{{ __(':type Management', ['type' => $type]) }}</span> - HTML attributes:
placeholder,title,alt,label - Fallback values:
{{ $var ?? 'Default' }}→{{ $var ?? __('Default') }} - Button text, long paragraphs, emoji text, and more
Sort any JSON translation file alphabetically by key for easier management.
php artisan localization:sort ar.json
php artisan localization:sort fr.json
php artisan localization:sort en.json# Step 1: Wrap any un-translated text in your Blade files (dry run first)
php artisan localization:wrap --dry-run
php artisan localization:wrap
# Step 2: Extract all translation keys
php artisan localization:extract
# Step 3: Auto-translate to your target languages
php artisan localization:extract ar
php artisan localization:extract fr
php artisan localization:extract bn
# Step 4: Sort the files for easier management
php artisan localization:sort ar.json
php artisan localization:sort fr.jsonThis project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- 📧 Email: mahfujur.dev@gmail.com