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