diff --git a/composer.json b/composer.json index 34a31c3d3..f3fa8f48c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "drupal/console", "description": "The Drupal Console is a CLI tool to generate boilerplate code, interact and debug Drupal 8.", - "keywords": ["Drupal", "Console", "Development", "Symfony"], + "keywords": ["Drupal", "Console", "Developmdrent", "Symfony"], "homepage": "http://drupalconsole.com/", "type": "project", "license": "GPL-2.0+", @@ -39,7 +39,7 @@ "php": "^5.5.9 || ^7.0", "alchemy/zippy": "0.3.5", "composer/installers": "~1.0", - "drupal/console-core" : "^1.0", + "drupal/console-core" : "*", "symfony/css-selector": "~2.8", "symfony/debug": "~2.6|~2.8", "symfony/dom-crawler": "~2.7|~2.8", diff --git a/config/services/drupal-console/develop.yml b/config/services/drupal-console/develop.yml index 6b931c5aa..3076e547c 100644 --- a/config/services/drupal-console/develop.yml +++ b/config/services/drupal-console/develop.yml @@ -19,17 +19,21 @@ services: - { name: drupal.command } console.translation_cleanup: class: Drupal\Console\Command\Develop\TranslationCleanupCommand + arguments: ['@console.root', '@console.configuration_manager'] tags: - { name: drupal.command } console.translation_pending: class: Drupal\Console\Command\Develop\TranslationPendingCommand + arguments: ['@console.root', '@console.configuration_manager', '@console.nested_array'] tags: - { name: drupal.command } console.translation_stats: class: Drupal\Console\Command\Develop\TranslationStatsCommand + arguments: ['@console.root', '@console.configuration_manager', '@console.renderer', '@console.nested_array'] tags: - { name: drupal.command } console.translation_sync: class: Drupal\Console\Command\Develop\TranslationSyncCommand + arguments: ['@console.root', '@console.configuration_manager'] tags: - { name: drupal.command } diff --git a/src/Command/Develop/TranslationCleanupCommand.php b/src/Command/Develop/TranslationCleanupCommand.php index 78cd82dfc..938af4bf2 100644 --- a/src/Command/Develop/TranslationCleanupCommand.php +++ b/src/Command/Develop/TranslationCleanupCommand.php @@ -16,16 +16,35 @@ use Symfony\Component\Console\Command\Command; use Drupal\Console\Style\DrupalStyle; use Drupal\Console\Command\Shared\CommandTrait; +use Drupal\Console\Utils\ConfigurationManager; class TranslationCleanupCommand extends Command { use CommandTrait; + /** + * @var string + */ + protected $consoleRoot; + + /** + * @var ConfigurationManager + */ + protected $configurationManager; + /** * TranslationCleanupCommand constructor. + * + * @param $consoleRoot + * @param configurationManager $configurationManager + * */ - public function __construct() - { + public function __construct( + $consoleRoot, + ConfigurationManager $configurationManager + ) { + $this->consoleRoot = $consoleRoot; + $this->configurationManager = $configurationManager; parent::__construct(); } @@ -55,10 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $language = $input->getArgument('language'); - $application = $this->getApplication(); - $appRoot = $application->getDirectoryRoot(); - - $languages = $application->getConfig()->get('application.languages'); + $languages = $this->configurationManager->getConfiguration()->get('application.languages'); unset($languages['en']); if ($language && !isset($languages[$language])) { @@ -75,31 +91,33 @@ protected function execute(InputInterface $input, OutputInterface $output) $languages = [$language => $languages[$language]]; } - $this->cleanupTranslations($io, $language, $languages, $appRoot); + $this->cleanupTranslations($io, $language, $languages); $io->success( $this->trans('commands.translation.cleanup.messages.success') ); } - protected function cleanupTranslations($io, $language = null, $languages, $appRoot) + protected function cleanupTranslations($io, $language = null, $languages) { $finder = new Finder(); foreach ($languages as $langCode => $languageName) { - foreach ($finder->files()->name('*.yml')->in($appRoot . 'config/translations/' . $langCode) as $file) { - $filename = $file->getBasename('.yml'); - if (!file_exists($appRoot . 'config/translations/en/' . $filename . '.yml')) { - $io->info( - sprintf( - $this->trans('commands.translation.cleanup.messages.file-deleted'), - $filename, - $languageName - ) - ); - unlink($appRoot . 'config/translations/' . $langCode. '/' . $filename . '.yml'); - } - } - } + 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'); + } + } + } + } } } diff --git a/src/Command/Develop/TranslationPendingCommand.php b/src/Command/Develop/TranslationPendingCommand.php index 8b93a1f26..559c7f079 100644 --- a/src/Command/Develop/TranslationPendingCommand.php +++ b/src/Command/Develop/TranslationPendingCommand.php @@ -18,20 +18,50 @@ use Symfony\Component\Console\Command\Command; use Drupal\Console\Style\DrupalStyle; use Drupal\Console\Command\Shared\CommandTrait; +use Drupal\Console\Utils\ConfigurationManager; +use Drupal\Console\Utils\NestedArray; class TranslationPendingCommand extends Command { use TranslationTrait; use CommandTrait; + /** + * @var string + */ + protected $consoleRoot; + + /** + * @var ConfigurationManager + */ + protected $configurationManager; + + /** + * @var NestedArray + */ + protected $nestedArray; + + /** * TranslationPendingCommand constructor. + * + * @param $consoleRoot + * @param $configurationManager + * @param NestedArray $nestedArray + * */ - public function __construct() - { + public function __construct( + $consoleRoot, + ConfigurationManager $configurationManager, + NestedArray $nestedArray + ) { + $this->consoleRoot = $consoleRoot; + $this->configurationManager = $configurationManager; + $this->nestedArray = $nestedArray; parent::__construct(); } + /** * {@inheritdoc} */ @@ -65,10 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $language = $input->getArgument('language'); $file = $input->getOption('file'); - $application = $this->getApplication(); - $appRoot = $application->getDirectoryRoot(); - - $languages = $application->getConfig()->get('application.languages'); + $languages = $this->configurationManager->getConfiguration()->get('application.languages'); unset($languages['en']); if ($language && !isset($languages[$language])) { @@ -85,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $languages = [$language => $languages[$language]]; } - $pendingTranslations = $this->determinePendingTranslation($io, $language, $languages, $file, $appRoot); + $pendingTranslations = $this->determinePendingTranslation($io, $language, $languages, $file); if ($file) { $io->success( @@ -107,14 +134,17 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - protected function determinePendingTranslation($io, $language = null, $languages, $fileFilter, $appRoot) + protected function determinePendingTranslation($io, $language = null, $languages, $fileFilter) { - $nestedArray = $this->getNestedArrayHelper(); $englishFilesFinder = new Finder(); $yaml = new Parser(); $statistics = []; - $englishDirectory = $appRoot . 'config/translations/en'; + $englishDirectory = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + 'en' + ); $englishFiles = $englishFilesFinder->files()->name('*.yml')->in($englishDirectory); @@ -135,7 +165,11 @@ protected function determinePendingTranslation($io, $language = null, $languages } foreach ($languages as $langCode => $languageName) { - $languageDir = $appRoot . 'config/translations/' . $langCode; + $languageDir = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + $langCode + ); if (isset($language) && $langCode != $language) { continue; } @@ -159,12 +193,12 @@ protected function determinePendingTranslation($io, $language = null, $languages } $diffStatistics = ['total' => 0, 'equal' => 0, 'diff' => 0]; - $diff = $nestedArray->arrayDiff($englishFileParsed, $resourceTranslatedParsed, true, $diffStatistics); + $diff = $this->nestedArray->arrayDiff($englishFileParsed, $resourceTranslatedParsed, true, $diffStatistics); if (!empty($diff)) { $diffFlatten = array(); $keyFlatten = ''; - $nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); + $this->nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); $tableHeader = [ $this->trans('commands.yaml.diff.messages.key'), diff --git a/src/Command/Develop/TranslationStatsCommand.php b/src/Command/Develop/TranslationStatsCommand.php index 377b63ff1..b26ed6f4c 100644 --- a/src/Command/Develop/TranslationStatsCommand.php +++ b/src/Command/Develop/TranslationStatsCommand.php @@ -18,17 +18,53 @@ use Symfony\Component\Console\Command\Command; use Drupal\Console\Style\DrupalStyle; use Drupal\Console\Command\Shared\CommandTrait; +use Drupal\Console\Utils\ConfigurationManager; +use Drupal\Console\Utils\TwigRenderer; +use Drupal\Console\Utils\NestedArray; class TranslationStatsCommand extends Command { use TranslationTrait; use CommandTrait; + /** + * @var string + */ + protected $consoleRoot; + + /** + * @var ConfigurationManager + */ + protected $configurationManager; + + /** + * @var TwigRenderer $renderer + */ + protected $renderer; + + /** + * @var NestedArray + */ + protected $nestedArray; + /** * TranslationStatsCommand constructor. + * + * @param $appRoot + * @param ConfigurationManager $configurationManager + * @param TwigRenderer $renderer + * @param NestedArray $nestedArray */ - public function __construct() - { + public function __construct( + $consoleRoot, + ConfigurationManager $configurationManager, + TwigRenderer $renderer, + NestedArray $nestedArray + ) { + $this->consoleRoot = $consoleRoot; + $this->configurationManager = $configurationManager; + $this->renderer = $renderer; + $this->nestedArray = $nestedArray; parent::__construct(); } @@ -66,10 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $language = $input->getArgument('language'); $format = $input->getOption('format'); - $application = $this->getApplication(); - $appRoot = $application->getDirectoryRoot(); - - $languages = $application->getConfig()->get('application.languages'); + $languages = $this->configurationManager->getConfiguration()->get('application.languages'); unset($languages['en']); if ($language && !isset($languages[$language])) { @@ -86,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $languages = [$language => $languages[$language]]; } - $stats = $this->calculateStats($io, $language, $languages, $appRoot); + $stats = $this->calculateStats($io, $language, $languages); if ($format == 'table') { $tableHeaders = [ @@ -106,22 +139,26 @@ protected function execute(InputInterface $input, OutputInterface $output) $arguments['languages'] = $stats; $io->writeln( - $this->getRenderHelper()->render( - 'core/translation/stats.md.twig', - $arguments - ) + $this->renderFile( + 'core/translation/stats.md.twig', + null, + $arguments + ) ); } } - protected function calculateStats($io, $language = null, $languages, $appRoot) + protected function calculateStats($io, $language = null, $languages) { - $nestedArray = $this->getNestedArrayHelper(); $englishFilesFinder = new Finder(); $yaml = new Parser(); $statistics = []; - $englishDirectory = $appRoot . 'config/translations/en'; + $englishDirectory = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + 'en' + ); $englishFiles = $englishFilesFinder->files()->name('*.yml')->in($englishDirectory); @@ -137,7 +174,15 @@ protected function calculateStats($io, $language = null, $languages, $appRoot) } foreach ($languages as $langCode => $languageName) { - $languageDir = $appRoot . 'config/translations/' . $langCode; + $languageDir = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + $langCode + ); + //don't show that language if that repo isn't present + if (!file_exists($languageDir)) { + continue; + } if (isset($language) && $langCode != $language) { continue; } @@ -160,13 +205,13 @@ protected function calculateStats($io, $language = null, $languages, $appRoot) } $diffStatistics = ['total' => 0, 'equal' => 0, 'diff' => 0]; - $diff = $nestedArray->arrayDiff($englishFileParsed, $resourceTranslatedParsed, true, $diffStatistics); + $diff = $this->nestedArray->arrayDiff($englishFileParsed, $resourceTranslatedParsed, true, $diffStatistics); $yamlKeys = 0; if (!empty($diff)) { $diffFlatten = array(); $keyFlatten = ''; - $nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); + $this->nestedArray->yamlFlattenArray($diff, $diffFlatten, $keyFlatten); // Determine how many yaml keys were returned as values foreach ($diffFlatten as $yamlKey => $yamlValue) { diff --git a/src/Command/Develop/TranslationSyncCommand.php b/src/Command/Develop/TranslationSyncCommand.php index acd0e5b2e..1a87e6cdd 100644 --- a/src/Command/Develop/TranslationSyncCommand.php +++ b/src/Command/Develop/TranslationSyncCommand.php @@ -17,16 +17,35 @@ use Symfony\Component\Console\Command\Command; use Drupal\Console\Style\DrupalStyle; use Drupal\Console\Command\Shared\CommandTrait; +use Drupal\Console\Utils\ConfigurationManager; class TranslationSyncCommand extends Command { use CommandTrait; + /** + * @var string + */ + protected $consoleRoot; + + /** + * @var ConfigurationManager + */ + protected $configurationManager; + /** * TranslationSyncCommand constructor. + * + * @param $consoleRoot + * @param configurationManager $configurationManager + * */ - public function __construct() - { + public function __construct( + $consoleRoot, + ConfigurationManager $configurationManager + ) { + $this->consoleRoot = $consoleRoot; + $this->configurationManager = $configurationManager; parent::__construct(); } @@ -62,11 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $language = $input->getArgument('language'); $file = $input->getOption('file'); - - $application = $this->getApplication(); - $appRoot = $application->getDirectoryRoot(); - - $languages = $application->getConfig()->get('application.languages'); + $languages = $this->configurationManager->getConfiguration()->get('application.languages'); unset($languages['en']); if ($language && !isset($languages[$language])) { @@ -83,18 +98,22 @@ protected function execute(InputInterface $input, OutputInterface $output) $languages = [$language => $languages[$language]]; } - $this->syncTranslations($io, $language, $languages, $file, $appRoot); + $this->syncTranslations($io, $language, $languages, $file); $io->success($this->trans('commands.translation.sync.messages.sync-finished')); } - protected function syncTranslations($io, $language = null, $languages, $file, $appRoot) + protected function syncTranslations($io, $language = null, $languages, $file) { $englishFilesFinder = new Finder(); $yaml = new Parser(); $dumper = new Dumper(); - $englishDirectory = $appRoot . 'config/translations/en'; + $englishDirectory = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + 'en' + ); if ($file) { $englishFiles = $englishFilesFinder->files()->name($file)->in($englishDirectory); @@ -115,7 +134,11 @@ protected function syncTranslations($io, $language = null, $languages, $file, $a } foreach ($languages as $langCode => $languageName) { - $languageDir = $appRoot . 'config/translations/' . $langCode; + $languageDir = $this->consoleRoot . + sprintf( + DRUPAL_CONSOLE_LANGUAGE, + $langCode + ); if (isset($language) && $langCode != $language) { continue; }