jonasschen / laravel-lang-monitor
Search for untranslated keys in your Laravel project
Fund package maintenance!
jonasschen
Patreon
bmc.link/jonasschen
Installs: 1 329
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-json: *
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
Automatically search for keys or phrases in your project that have no translations.
Using Laravel Lang Monitor you can get all missing translations.
Installation
You can install the package via composer:
composer require jonasschen/laravel-lang-monitor --dev
Publish the config file using the artisan CLI tool:
php artisan vendor:publish --provider="Jonasschen\LaravelLangMonitor\LaravelLangMonitorServiceProvider"
Available configurations
- abort_if_directory_doesnt_exists (Default: false)
- Abort if directory doesn't exists: If any of the configured directories of the "directories_to_search" array does not exist, the scanning process will be aborted, otherwise only an alert it will be logged an in the console;
- abort_if_lang_file_doesnt_exists (Default: false)
- Abort if lang file doesn't exists: If any of the configured lang files of the "lang_files" array does not exist, the scanning process will be aborted, otherwise only an alert it will be logged an in the console;
- scan_for_unused_translations (Default: true)
- If enabled, will check if all key translations are in use and log unused keys
- directories_to_search (Default: ['app', 'resources/views'])
- Directories to search: A list of directories where the package will perform the scanning process;
- extensions_to_search (Default: ['php', 'js'])
- Extensions to search: A list of file extensions that the package will consider to perform the scanning process;
- lang_files (Default: ['resources/lang/en.json'])
- Lang files: A list of lang files where the package will try to search the translations keys;
- locale Default(en.utf8)
- Locale: The locale of main project language. It will be used to perform a improved sorting of the untranslated keys when exporting result;
Usage
Use the command below, it is that easy!
php artisan lang_monitor:scan
Output example with missing translations
Key not found: [Nova senha] - Used in file [resources/views/auth/changepassword.blade.php:20]
Key not found: [Confirmar senha] - Used in file [resources/views/auth/changepassword.blade.php:22]
****************************************
* LARAVEL LANG MONITOR REPORT *
****************************************
* Found keys: 13564 *
* Untranslated keys: 37 *
* Unique untranslated keys: 30 *
* Unused translations: 1474 *
****************************************
Output example without missing translations
********************************************************
* Great! All translations are working fine. *
********************************************************
Export untranslated keys to JSON file format
You can export missing translations result for a file in a JSON format. use the --export_missed_json_file option like this:
php artisan lang_monitor:scan --export_missed_json_file=storage/logs/untranslateds.json
Export untranslated keys to PHP file format
You can export missing translations result for a file in a PHP format. use the --export_missed_php_file option like this:
php artisan lang_monitor:scan --export_missed_php_file=storage/logs/untranslateds.php
Export untranslated keys to text file format
You can export missing translations result for a file in a text format. use the --export_missed_text_file option like this:
php artisan lang_monitor:scan --export_missed_txt_file=storage/logs/untranslateds.txt
Export unused keys to JSON file format
You can export unused keys result for a file in a JSON format. use the --export_unused_json_file option like this:
php artisan lang_monitor:scan --export_unused_json_file=storage/logs/unuseds.json
Export unused keys to PHP file format
You can export unused keys result for a file in a PHP format. use the --export_unused_php_file option like this:
php artisan lang_monitor:scan --export_unused_php_file=storage/logs/unuseds.php
Export unused keys to text file format
You can export unused keys result for a file in a text format. use the --export_unused_text_file option like this:
php artisan lang_monitor:scan --export_unused_txt_file=storage/logs/unuseds.txt
Translation function support
This package supports @lang(), __() and trans() functions.
Lang file format support
This package supports .php files and .json files formats.
Consider Sponsoring
Help me maintain this project, please consider looking at the FUNDING file for more info.
BTC
ETH
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email jonasschen@gmail.com instead of using the issue tracker. Please do not email any questions, open an issue if you have a question.
Credits
License
The MIT License (MIT). Please see License File for more information.