fidum/laravel-translation-linter

Commands to help you keep your laravel translations organized.

2.0.3 2024-03-05 18:53 UTC

This package is auto-updated.

Last update: 2024-11-08 20:18:34 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Twitter Follow

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.