Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dmason30 committed Oct 6, 2023
1 parent 7d01f30 commit b27f8cc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
54 changes: 44 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
# Checks your code for unused laravel language keys
# Laravel Translation Linter

[![Latest Version on Packagist](https://img.shields.io/packagist/v/fidum/laravel-translation-linter.svg?style=for-the-badge)](https://packagist.org/packages/fidum/laravel-translation-linter)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/fidum/laravel-translation-linter/run-tests.yml?branch=main&label=tests&style=for-the-badge)](https://github.com/fidum/laravel-translation-linter/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/fidum/laravel-translation-linter/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=for-the-badge)](https://github.com/fidum/laravel-translation-linter/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/fidum/laravel-translation-linter.svg?style=for-the-badge)](https://packagist.org/packages/fidum/laravel-translation-linter)
[![Twitter Follow](https://img.shields.io/badge/follow-%40danmasonmp-1DA1F2?logo=twitter&style=for-the-badge)](https://twitter.com/danmasonmp)

This package provides commands to help you keep your translations organized.

Shoutout to Hexadog for their package [laravel-translation-manager](https://github.com/hexadog/laravel-translation-manager)
which was used as the foundation for this package.

Here is the feature list / roadmap for this package:

- [x] Supports JSON and PHP translation files
- You can enable / disable file types in the config
- You can add your own custom file readers
- [x] Supports multiple locales
- [x] Supports parsing many code types
- Default: php, js and vue
- You can add more file extensions in the config
- [x] [Unused Command](#unused-command)
- [ ] Missing Command
- [ ] Orphaned Command
- [ ] Lint Command
- This would run all of the other commands in a single command.

## Installation

You can install the package via composer:
Expand All @@ -20,18 +40,32 @@ You can publish the config file with:
php artisan vendor:publish --tag="laravel-translation-linter-config"
```

This is the contents of the published config file:
[Click here to see the contents of the config file](config/translation-linter.php).

```php
return [
];
```
You should read through the config, which serves as additional documentation and make changes as needed.

## 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:** Default laravel language files are ignored by default.
You can change the filters used in the [config file](config/translation-linter.php).

```sh
$ php artisan translation:unused

## Usage
ERROR 5 unused translations found.

```php
$laravelTranslationLinter = new Fidum\LaravelTranslationLinter();
echo $laravelTranslationLinter->echoPhrase('Hello, Fidum!');
+--------+-----------+------------------------------------+----------------------------------------------------+
| Locale | Namespace | 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 |
+--------+-----------+------------------------------------+----------------------------------------------------+
```

## Testing
Expand Down
2 changes: 1 addition & 1 deletion config/translation-linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
*/
'filters' => [
\Fidum\LaravelTranslationLinter\Filters\DefaultLanguageFilesFilter::class,
\Fidum\LaravelTranslationLinter\Filters\IgnoreNamespacedKeysFilter::class,
// \Fidum\LaravelTranslationLinter\Filters\IgnoreNamespacedKeysFilter::class,
],
],
];

0 comments on commit b27f8cc

Please sign in to comment.