Skip to content

Commit

Permalink
Add translatable strings in the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Oct 11, 2023
1 parent b217e4b commit 6d276ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
20 changes: 13 additions & 7 deletions src/Commands/SeoScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SeoScan extends Command
public function handle(): int
{
if (empty(config('seo.models')) && ! config('seo.check_routes')) {
$this->error('No models or routes specified in config/seo.php');
$this->error(__('No models or routes specified in config/seo.php'));

return self::FAILURE;
}
Expand All @@ -51,7 +51,7 @@ public function handle(): int

$startTime = microtime(true);

$this->info('Please wait while we scan your web page(s)...');
$this->info(__('Please wait while we scan your web page(s)...'));
$this->line('');

$this->progress = $this->output->createProgressBar(getCheckCount());
Expand All @@ -73,7 +73,11 @@ public function handle(): int

$totalPages = $this->modelCount + $this->routeCount;

$this->info('Command completed with '.$this->failed.' failed and '.$this->success.' successful checks on '.$totalPages.' pages.');
$this->info(__('Command completed with :failed failed and :success successful checks on :pages pages.', [
'failed' => $this->failed,
'success' => $this->success,
'pages' => $totalPages,
]));

cache()->driver(config('seo.cache.driver'))->tags('seo')->flush();

Expand Down Expand Up @@ -189,7 +193,7 @@ private function calculateScoreForModel(string $model, string $scope = null): vo
$this->progress->finish();

if ($this->failed === 0 && $this->success === 0) {
$this->line('<fg=red>✘ Unfortunately, the url that is used is not correct. Please try again with a different url.</>');
$this->line('<fg=red>✘ ' . __('Unfortunately, the url that is used is not correct. Please try again with a different url') . '</>');

return self::FAILURE;
}
Expand Down Expand Up @@ -230,17 +234,19 @@ private function logResultToConsole(SeoScore $seo, string $url): void
$this->line('');
$this->line('');
$this->line('-----------------------------------------------------------------------------------------------------------------------------------');
$this->line('> '.$url.' | <fg=green>'.$seo->getSuccessfulChecks()->count().' passed</> <fg=red>'.($seo->getFailedChecks()->count().' failed</>'));
$this->line('> '.$url.' | <fg=green>'.$seo->getSuccessfulChecks()->count().' ' . __('passed') .'</> <fg=red>'.($seo->getFailedChecks()->count().' '. __('failed') . '</>'));
$this->line('-----------------------------------------------------------------------------------------------------------------------------------');
$this->line('');

$seo->getAllChecks()->each(function ($checks, $type) {
$checks->each(function ($check) use ($type) {
if ($type == 'failed') {
$this->line('<fg=red>✘ '.$check->title.' failed.</>');
$this->line('<fg=red>✘ '.$check->title.' ' . __('failed') . '.</>');

if (property_exists($check, 'failureReason')) {
$this->line($check->failureReason.' Estimated time to fix: '.$check->timeToFix.' minute(s).');
$this->line($check->failureReason.' ' . __('Estimated time to fix: :time minute(s)', [
'time' => $check->timeToFix,
]));

$this->line('');
}
Expand Down
17 changes: 11 additions & 6 deletions src/Commands/SeoScanUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SeoScanUrl extends Command

public function handle(): int
{
$this->info('Please wait while we scan your web page...');
$this->info(__('Please wait while we scan your web page...'));
$this->line('');

$progress = $this->output->createProgressBar(getCheckCount());
Expand All @@ -26,26 +26,28 @@ public function handle(): int
$this->line('');
$this->line('');
$this->line('-----------------------------------------------------------------------------------------------------------------------------------');
$this->line('> '.$this->argument('url').' | <fg=green>'.$score->getSuccessfulChecks()->count().' passed</> <fg=red>'.($score->getFailedChecks()->count().' failed</>'));
$this->line('> '.$this->argument('url').' | <fg=green>'.$score->getSuccessfulChecks()->count().' ' . __('passed') .'</> <fg=red>'.($score->getFailedChecks()->count().' '. __('failed') . '</>'));
$this->line('-----------------------------------------------------------------------------------------------------------------------------------');
$this->line('');

// If successful and failed checks are empty, we can assume that the
// visit page threw an exception. In that case, we don't want to
// show the checks. But show the exception message instead.
if ($score->getSuccessfulChecks()->isEmpty() && $score->getFailedChecks()->isEmpty()) {
$this->line('<fg=red>✘ Unfortunately, the url you entered is not correct. Please try again with a different url.</>');
$this->line('<fg=red>✘ ' . __('Unfortunately, the url that is used is not correct. Please try again with a different url') . '</>');

return self::FAILURE;
}

$score->getAllChecks()->each(function ($checks, $type) {
$checks->each(function ($check) use ($type) {
if ($type == 'failed') {
$this->line('<fg=red>✘ '.$check->title.' failed.</>');
$this->line('<fg=red>✘ '.$check->title.' ' . __('failed') . '.</>');

if (property_exists($check, 'failureReason')) {
$this->line($check->failureReason.' Estimated time to fix: '.$check->timeToFix.' minute(s).');
$this->line($check->failureReason.' ' . __('Estimated time to fix: :time minute(s)', [
'time' => $check->timeToFix,
]));

$this->line('');
}
Expand All @@ -59,7 +61,10 @@ public function handle(): int

$totalChecks = $score->getFailedChecks()->count() + $score->getSuccessfulChecks()->count();

$this->info('Completed '.$totalChecks.' out of '.getCheckCount().' checks.');
$this->info(__('Completed :checks out of :total checks', [
'checks' => $totalChecks,
'total' => getCheckCount(),
]));
$this->line('');

cache()->driver(config('seo.cache.driver'))->tags('seo')->flush();
Expand Down

0 comments on commit 6d276ca

Please sign in to comment.