-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Coderello\LaravelNovaLang\Commands; | ||
|
||
class NovaLangCleanup extends AbstractDevCommand | ||
{ | ||
protected const MISSING_TEXT = '<MISSING>'; | ||
protected const REMOVED_MISSING_KEYS = '%d missing or blank translation keys for "%s" locale were removed.'; | ||
protected const NO_MISSING_KEYS = '"%s" locale has no missing or blank translation keys.'; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'cleanup | ||
{locales? : Comma-separated list of languages} | ||
{--all : Output all languages}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Remove missing or blank keys from Nova language files.'; | ||
|
||
/** | ||
* Handle the command for a given locale. | ||
* | ||
* @param string $locale | ||
* @return void | ||
*/ | ||
protected function handleLocale(string $locale): void | ||
{ | ||
$inputFile = $this->directoryFrom("$locale.json"); | ||
|
||
if (! $this->availableLocales->contains($locale)) { | ||
$this->warn(sprintf(static::LOCALE_FILE_DOES_NOT_EXIST, $locale)); | ||
|
||
return; | ||
} | ||
|
||
$inputKeys = $this->loadJson($inputFile); | ||
|
||
$outputKeys = array_filter($inputKeys, fn ($text) => ! empty(trim($text)) && $text !== static::MISSING_TEXT); | ||
|
||
$missingKeys = count($inputKeys) - count($outputKeys); | ||
|
||
$outputFile = $inputFile; | ||
|
||
if ($missingKeys > 0) { | ||
$this->saveJson($outputFile, $outputKeys); | ||
|
||
$this->info(sprintf(static::REMOVED_MISSING_KEYS, $missingKeys, $locale, $outputFile)); | ||
} else { | ||
$this->info(sprintf(static::NO_MISSING_KEYS, $locale)); | ||
} | ||
} | ||
|
||
protected function afterHandle() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters