fidum / laravel-translation-linter
Commands to help you keep your laravel translations organized.
Fund package maintenance!
dmason30
Installs: 6 995
Dependents: 0
Suggesters: 0
Security: 0
Stars: 23
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.13
- nunomaduro/collision: ^7.8|^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.8|^9.0
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
This package provides commands to help you keep your translations organized.
Shoutout to Hexadog for their package laravel-translation-manager which was used as the foundation for this package.
Installation
You can install the package via composer:
composer require --dev fidum/laravel-translation-linter
You can publish the config file with:
php artisan vendor:publish --tag="translation-linter-config"
Click here to see the contents of the config file.
You should read through the config, which serves as additional documentation and make changes as needed.
Missing Command
This reads through all your code and finds all your language function usage. Then attempts to find matches in your language files and will output any keys in your code that do not exist as a language key.
$ php artisan translation:missing ERROR 3 missing translations found. +--------+--------------------------------+---------------------+ | Locale | Key | File | +--------+--------------------------------+---------------------+ | en | Missing PHP Class | app/ExampleJson.php | | en | Only Missing English PHP Class | app/ExampleJson.php | | de | Missing PHP Class | app/ExampleJson.php | +--------+--------------------------------+---------------------+
You can generate a baseline file which will be used to ignore specific keys with the
--generate-baseline
or -b
command options:
$ php artisan translation:missing --generate-baseline
INFO Baseline file written with 49 translation keys.
$ php artisan translation:missing
INFO No missing translations found!
Unused Command
This reads through all your code and finds all your language function usage. Then attempts to find matches in your language files and will output any language keys that are not being used in your code.
Note: Some language keys are filtered out by default, you can change the filters used in the config file.
$ php artisan translation:unused ERROR 5 unused translations found. +--------+----------------------+-----------------------------------------------+ | Locale | Key | Value | +--------+----------------------+-----------------------------------------------+ | en | Unused PHP Class | I am unused in php class | | en | Unused Blade File | I am unused in blade | | en | Unused Vue Component | I am unused in vue component | | en | example.unused | I am unused in php class | | de | example.unused | Ich werde in einer PHP-Klasse nicht verwendet | +--------+----------------------+-----------------------------------------------+
You can generate a baseline file which will be used to ignore specific keys with the
--generate-baseline
or -b
command options:
$ php artisan translation:unused --generate-baseline
INFO Baseline file written with 5 unused translation keys.
$ php artisan translation:unused
INFO No unused translations found!
Testing
composer test
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.