eg-mohamed / laravelmissingtranslations
Scan Laravel project files and append missing translation keys to JSON locale files
Package info
github.com/EG-Mohamed/laravel-missing-translations
pkg:composer/eg-mohamed/laravelmissingtranslations
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
README
A Laravel dev-tool that scans your project for translation function calls and appends any missing keys to your JSON locale files. No more manually hunting for untranslated strings.
Supports __(), trans(), trans_choice(), @lang(), @choice(), and Lang::get/has/choice().
Installation
Install as a dev dependency:
composer require eg-mohamed/laravelmissingtranslations --dev
Publish the config file:
php artisan vendor:publish --tag="laravelmissingtranslations-config"
Configuration
// config/laravelmissingtranslations.php return [ // Directories to scan 'paths' => [app_path(), resource_path('views')], // File extensions to include 'extensions' => ['php', 'blade.php'], // Directories to exclude from scanning 'exclude_paths' => [], // Sort keys alphabetically in the JSON output 'sort_keys' => true, // Skip dotted keys like 'auth.failed' (PHP array-based translations) 'exclude_dot_keys' => false, // Translation functions to detect 'include_functions' => ['__', 'trans', 'trans_choice', '@lang', '@choice', 'Lang::get', 'Lang::has', 'Lang::choice'], // Regex patterns for keys to skip 'exclude_patterns' => [], // Flags passed to json_encode when writing locale files 'json_flags' => JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE, ];
Usage
Scan and write missing keys
php artisan missing-translations en
This scans your project, compares found keys against lang/en.json, and appends any missing ones with an empty string value.
If no locale argument is provided and --all is not used, the command falls back to config('app.locale') automatically:
php artisan missing-translations
Preview without writing
php artisan missing-translations en --dry-run
Displays a table of missing keys without modifying any files. Also shows summary statistics:
Keys scanned: 42 | Existing: 38 | Missing: 4
Dry run mode: no changes written.
Process all existing locale files at once
php artisan missing-translations --all
Runs the scan against every lang/*.json file found in your project. If no JSON files exist, a helpful message is shown instead of a generic error.
Remove unused keys
php artisan missing-translations en --remove-unused
Finds keys that exist in lang/en.json but are no longer referenced in any scanned file, displays them, and removes them. Combine with --dry-run to preview without making changes:
php artisan missing-translations en --remove-unused --dry-run
JSON output for CI pipelines
php artisan missing-translations en --json
Outputs results as JSON to stdout instead of the table format. Useful for CI pipelines — e.g. fail a build if missing translations count > 0:
{
"locale": "en",
"existing_count": 38,
"missing_count": 4,
"missing_keys": [
"New Key One",
"New Key Two"
]
}
With --remove-unused:
{
"locale": "en",
"existing_count": 38,
"missing_count": 4,
"missing_keys": ["New Key One"],
"unused_count": 2,
"unused_keys": ["Old Key", "Stale Key"]
}
How it works
- Uses Symfony Finder to crawl configured
pathsfor files matching configuredextensions - Extracts translation keys via regex from all supported function calls
- Diffs found keys against the existing locale JSON file
- Appends missing keys with an empty string value, leaving existing translations untouched
- Re-running the command is safe — no duplicates are ever added
- File writes use
LOCK_EXto prevent corruption from concurrent runs
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.