-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
ebf5fcf
commit 1b3e080
Showing
5 changed files
with
122 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace PHPUnuhi\Commands\Core; | ||
|
||
use PHPUnuhi\Bundles\Storage\StorageFactory; | ||
use PHPUnuhi\Configuration\ConfigurationLoader; | ||
use PHPUnuhi\Exceptions\ConfigurationException; | ||
use PHPUnuhi\Services\Loaders\Xml\XmlLoader; | ||
use PHPUnuhi\Traits\CommandTrait; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class FixMessCommand extends Command | ||
{ | ||
use CommandTrait; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('fix:mess') | ||
->setDescription('Fixes the mess in your translations by removing those unused keys.') | ||
->addOption('configuration', null, InputOption::VALUE_REQUIRED, '', '') | ||
->addOption('set', null, InputOption::VALUE_REQUIRED, '', ''); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @throws ConfigurationException | ||
* @return int | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$io->title('PHPUnuhi Fix Mess'); | ||
$this->showHeader(); | ||
|
||
# ----------------------------------------------------------------- | ||
|
||
$configFile = $this->getConfigFile($input); | ||
$setName = $this->getConfigStringValue('set', $input); | ||
|
||
# ----------------------------------------------------------------- | ||
|
||
$configLoader = new ConfigurationLoader(new XmlLoader()); | ||
$config = $configLoader->load($configFile); | ||
|
||
|
||
$countRemoved = 0; | ||
|
||
foreach ($config->getTranslationSets() as $set) { | ||
if ($setName !== '' && $setName !== '0' && $setName !== $set->getName()) { | ||
continue; | ||
} | ||
|
||
$io->section('Fixing Translation Set: ' . $set->getName()); | ||
|
||
foreach ($set->getInvalidTranslationsIDs() as $currentID) { | ||
foreach ($set->getLocales() as $locale) { | ||
$locale->removeTranslation($currentID); | ||
$io->writeln(' [-] removed translation: [' . $locale->getName() . '] ' . $currentID); | ||
$countRemoved++; | ||
} | ||
} | ||
|
||
$io->block('saving translations of this set...'); | ||
|
||
$storageSaver = StorageFactory::getInstance()->getStorage($set); | ||
|
||
$storageSaver->saveTranslationSet($set); | ||
} | ||
|
||
$io->success($countRemoved . ' translations have been created!'); | ||
return 0; | ||
} | ||
} |
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