Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Locale / TranslationStatusCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\MigrateDebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Locale;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Style\DrupalStyle;
15 use Drupal\Console\Command\Shared\LocaleTrait;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Utils\Site;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Annotations\DrupalCommand;
20
21 /**
22  * @DrupalCommand(
23  *     extension = "locale",
24  *     extensionType = "module"
25  * )
26  */
27 class TranslationStatusCommand extends Command
28 {
29     use CommandTrait;
30     use LocaleTrait;
31
32     /**
33       * @var Site
34       */
35     protected $site;
36
37      /**
38       * @var Manager
39       */
40     protected $extensionManager;
41
42     /**
43      * TranslationStatusCommand constructor.
44      *
45      * @param Site    $site
46      * @param Manager $extensionManager
47      */
48     public function __construct(
49         Site $site,
50         Manager $extensionManager
51     ) {
52         $this->site = $site;
53         $this->extensionManager = $extensionManager;
54         parent::__construct();
55     }
56
57     protected function configure()
58     {
59         $this
60             ->setName('locale:translation:status')
61             ->setDescription($this->trans('commands.locale.translation.status.description'))
62             ->addArgument(
63                 'language',
64                 InputArgument::OPTIONAL,
65                 $this->trans('commands.locale.translation.status.arguments.language')
66             );
67     }
68
69     protected function execute(InputInterface $input, OutputInterface $output)
70     {
71         $io = new DrupalStyle($input, $output);
72         $language = $input->getArgument('language');
73         $tableHeader = [
74             $this->trans('commands.locale.translation.status.messages.project'),
75             $this->trans('commands.locale.translation.status.messages.version'),
76             $this->trans('commands.locale.translation.status.messages.local-age'),
77             $this->trans('commands.locale.translation.status.messages.remote-age'),
78             $this->trans('commands.locale.translation.status.messages.info'),
79         ];
80
81         $locale = $this->extensionManager->getModule('locale');
82         $this->site->loadLegacyFile($locale->getPath(true) . '/locale.compare.inc');
83
84         $languages = locale_translatable_language_list();
85         $status = locale_translation_get_status();
86
87         if (!$languages) {
88             $io->info($this->trans('commands.locale.translation.status.messages.no-languages'));
89             return 1;
90         }
91
92         if (empty($status)) {
93             $io->info($this->trans('commands.locale.translation.status.messages.no-translations'));
94             return 1;
95         }
96
97         if ($languages) {
98             $projectsStatus = $this->projectsStatus();
99
100             foreach ($projectsStatus as $langcode => $rows) {
101                 $tableRows = [];
102                 if ($language !='' && !($language == $langcode || strtolower($language) == strtolower($languages[$langcode]->getName()))) {
103                     continue;
104                 }
105                 $io->info($languages[$langcode]->getName());
106                 foreach ($rows as $row) {
107                     if ($row[0] == 'drupal') {
108                         $row[0] = $this->trans('commands.common.messages.drupal-core');
109                     }
110                     $tableRows[] = $row;
111                 }
112                 $io->table($tableHeader, $tableRows, 'compact');
113             }
114         }
115
116         return 0;
117     }
118 }