Skip to content

Commit

Permalink
Merge pull request filamentphp#14906 from dmitry-udod/enhancement-14825
Browse files Browse the repository at this point in the history
Convert the CheckTranslationsCommand to use the new Laravel command components & Laravel Prompts
  • Loading branch information
danharrin authored Nov 29, 2024
2 parents 7267a92 + b73e038 commit c7a4958
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
5 changes: 3 additions & 2 deletions docs-assets/app/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Psr\Log\LogLevel;
use Throwable;

class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
* @var array<class-string<Throwable>, LogLevel::*>
*/
protected $levels = [
//
Expand All @@ -19,7 +20,7 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
* @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RedirectIfAuthenticated
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next, string ...$guards): Response
{
Expand Down
3 changes: 1 addition & 2 deletions packages/infolists/src/Concerns/InteractsWithInfolists.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Infolists\Components\Actions\Action;
Expand Down Expand Up @@ -350,7 +349,7 @@ protected function makeInfolist(): Infolist
}

/**
* @return array<string, Forms\Form>
* @return array<string, Form>
*/
protected function getInteractsWithInfolistsForms(): array
{
Expand Down
38 changes: 15 additions & 23 deletions packages/support/src/Commands/CheckTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Filament\Support\Commands;

use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
Expand All @@ -11,8 +12,12 @@
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Finder\SplFileInfo;

use function Laravel\Prompts\info;
use function Laravel\Prompts\table;
use function Laravel\Prompts\warning;

#[AsCommand(name: 'filament:check-translations')]
class CheckTranslationsCommand extends Command
class CheckTranslationsCommand extends Command implements PromptsForMissingInput
{
protected $signature = 'filament:check-translations
{locales* : The locales to check.}
Expand Down Expand Up @@ -71,29 +76,21 @@ protected function scan(string $package): void
$path = implode(DIRECTORY_SEPARATOR, [$localeRootDirectory, $locale]);

if ($missingFiles->count() > 0 && $removedFiles->count() > 0) {
$this->warn("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . " and {$removedFiles->count()} removed translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");

$this->newLine();
warning("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . " and {$removedFiles->count()} removed translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
} elseif ($missingFiles->count() > 0) {
$this->warn("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");

$this->newLine();
warning("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
} elseif ($removedFiles->count() > 0) {
$this->warn("[!] Package filament/{$package} has {$removedFiles->count()} removed translation " . Str::plural('file', $removedFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");

$this->newLine();
warning("[!] Package filament/{$package} has {$removedFiles->count()} removed translation " . Str::plural('file', $removedFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
}

if ($missingFiles->count() > 0 || $removedFiles->count() > 0) {
$this->table(
table(
[$path, ''],
array_merge(
array_map(fn (string $file): array => [$file, 'Missing'], $missingFiles->toArray()),
array_map(fn (string $file): array => [$file, 'Removed'], $removedFiles->toArray()),
),
);

$this->newLine();
}

collect($files)
Expand Down Expand Up @@ -124,29 +121,24 @@ protected function scan(string $package): void
$locale = locale_get_display_name($locale, 'en');

if ($missingKeysCount == 0 && $removedKeysCount == 0) {
$this->info("[✓] Package filament/{$package} has no missing or removed translation keys for {$locale}!\n");

$this->newLine();
info("[✓] Package filament/{$package} has no missing or removed translation keys for {$locale}!\n");
} elseif ($missingKeysCount > 0 && $removedKeysCount > 0) {
$this->warn("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " and {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
warning("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " and {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
} elseif ($missingKeysCount > 0) {
$this->warn("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " for {$locale}.\n");
warning("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " for {$locale}.\n");
} elseif ($removedKeysCount > 0) {
$this->warn("[!] Package filament/{$package} has {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
warning("[!] Package filament/{$package} has {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
}
})
->filter(static fn ($keys): bool => count($keys['missing']) || count($keys['removed']))
->each(function ($keys, string $file) {
$this->table(
table(
[$file, ''],
[
...array_map(fn (string $key): array => [$key, 'Missing'], $keys['missing']),
...array_map(fn (string $key): array => [$key, 'Removed'], $keys['removed']),
],
'box',
);

$this->newLine();
});
});
}
Expand Down

0 comments on commit c7a4958

Please sign in to comment.