jonasschen / laravel-lang-monitor
Search for untranslated keys in your Laravel project
Fund package maintenance!
jonasschen
Patreon
bmc.link/jonasschen
Installs: 3 223
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- ext-json: *
- laravel/framework: ^11.44
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
Laravel Lang Monitor
Now UI Version available!
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, asset and view files using the artisan CLI tool:
php artisan vendor:publish --provider="Jonasschen\LaravelLangMonitor\LaravelLangMonitorServiceProvider"
This command will publish the following files:
- config/lang-monitor.php
- public/vendor/lang-monitor/css/lang-monitor.css
- public/vendor/lang-monitor/ico/lang-monitor.ico
- public/vendor/lang-monitor/images/lang_monitor_logo_small.png
- public/vendor/lang-monitor/js/lang-monitor.js
- resources/views/vendor/lang-monitor/monitor.blade.php
Available configurations
- abort_if_directory_doesnt_exist (Default: false)
- Abort if a directory doesn't exist: If any configured directories of the "directories_to_search" array do not exist, the scanning process will be aborted, otherwise only an alert it will be logged in the console;
- abort_if_lang_file_doesnt_exist (Default: false)
- Abort if a lang file doesn't exist: If any configured lang files of the "lang_files" array do not exist, the scanning process will be aborted, otherwise only an alert it will be logged 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 translation keys;
- locale (Default en.utf8)
- Locale: The locale of the main project language. It will be used to perform an improved sorting of the untranslated keys when exporting a result;
- middleware (Default: ['web'])
- Middleware: Middleware stack wrapping all Lang Monitor routes. Adjust to control access to the UI.
- ui_path (Default: lang-monitor)
- UI path: URL path where the Lang Monitor UI will be available. Example: "lang-monitor" → https://your-app.test/lang-monitor;
Usage via browser
You can access the Lang Monitor UI by going to the URL below:
http://your-app.test/lang-monitor
You can customize the URL path by changing the "ui_path" option in the config file "/config/lang-monitor.php".
Usage via prompt
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 a missing translation 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 a missing translation 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 a missing translation 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 a 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
Upgrade guide
From version 2.x to 3.x
- You will need to publish the config file again to publish the new asset and view files;
php artisan vendor:publish --provider="Jonasschen\LaravelLangMonitor\LaravelLangMonitorServiceProvider"
- The "middleware" configuration option has been added, and its default value is "['web']". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";
- The "ui_path" configuration option has been added, and its default value is "lang-monitor". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";
- The "abort_if_directory_doesnt_exists" config option has been renamed to "abort_if_directory_doesnt_exist", and its default value is "false". If you don't manually rename it in your config file, this will be the new behavior;
- The "abort_if_lang_file_doesnt_exists" config option has been renamed to "abort_if_lang_file_doesnt_exist", and its default value is "false". If you don't manually rename it in your config file, this will be the new behavior;
From version 2.0.x to 2.1.x
- The "scan_for_unused_translations" configuration option has been added. Its default value is "false". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";
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 about recent changes.
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.