Skip to content

Commit

Permalink
Update FindAndAddLanguageKeysCommand.php
Browse files Browse the repository at this point in the history
  • Loading branch information
wimurk authored Apr 15, 2022
1 parent b217daf commit dbb67d1
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/Commands/FindAndAddLanguageKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,43 @@ public function __construct(GoogleTranslate $googleTranslate)
}

/**
*
* @return void
*/
public function handle()
public function handle() : int
{
if(!$this->option('locales')){
return $this->info('The --locales option is required! Use as --locales=nl,en,de');
$this->info('The --locales option is required! Use as --locales=nl,en,de');
return 0;
}

$this->locales = explode(',', $this->option('locales'));

$this->getTranslationFiles();
$alreadyTranslated = $this->loadAllSavedTranslations();
$translationsKeys = $this->findKeysInFiles();
$this->translateAndSaveNewKeys($translationsKeys, $alreadyTranslated);
$this->info("Finished");

return 1;
}

/**
* @return void
*/
private function getTranslationFiles() : void
{
if($this->option('locales') !== 'all'){
$this->locales = explode(',', $this->option('locales'));
return;
}

$files = Storage::disk('localeFinder')->files();

foreach($files as $file){
if(Str::endsWith($file, '.json')){
$this->locales[] = Str::before($file, '.json');
}
}

}

/**
Expand Down

0 comments on commit dbb67d1

Please sign in to comment.