X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDevelop%2FTranslationCleanupCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDevelop%2FTranslationCleanupCommand.php;h=9263f4ba4d9d74f5a633d24d0c43a30df7eed9a4;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Develop/TranslationCleanupCommand.php b/vendor/drupal/console/src/Command/Develop/TranslationCleanupCommand.php new file mode 100644 index 000000000..9263f4ba4 --- /dev/null +++ b/vendor/drupal/console/src/Command/Develop/TranslationCleanupCommand.php @@ -0,0 +1,122 @@ +consoleRoot = $consoleRoot; + $this->configurationManager = $configurationManager; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + + protected function configure() + { + $this + ->setName('translation:cleanup') + ->setDescription($this->trans('commands.translation.cleanup.description')) + ->addArgument( + 'language', + InputArgument::OPTIONAL, + $this->trans('commands.translation.cleanup.arguments.language'), + null + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $language = $input->getArgument('language'); + + $languages = $this->configurationManager->getConfiguration()->get('application.languages'); + unset($languages['en']); + + if ($language && !isset($languages[$language])) { + $io->error( + sprintf( + $this->trans('commands.translation.cleanup.messages.invalid-language'), + $language + ) + ); + return 1; + } + + if ($language) { + $languages = [$language => $languages[$language]]; + } + + $this->cleanupTranslations($io, $language, $languages); + + $io->success( + $this->trans('commands.translation.cleanup.messages.success') + ); + } + + protected function cleanupTranslations($io, $language = null, $languages) + { + $finder = new Finder(); + + foreach ($languages as $langCode => $languageName) { + if (file_exists($this->consoleRoot . sprintf(DRUPAL_CONSOLE_LANGUAGE, $langCode))) { + foreach ($finder->files()->name('*.yml')->in($this->consoleRoot . sprintf(DRUPAL_CONSOLE_LANGUAGE, $langCode)) as $file) { + $filename = $file->getBasename('.yml'); + if (!file_exists($this->consoleRoot . sprintf(DRUPAL_CONSOLE_LANGUAGE, 'en') . $filename . '.yml')) { + $io->info( + sprintf( + $this->trans('commands.translation.cleanup.messages.file-deleted'), + $filename, + $languageName + ) + ); + unlink($this->consoleRoot . sprintf(DRUPAL_CONSOLE_LANGUAGE, $langCode). '/' . $filename . '.yml'); + } + } + } + } + } +}