Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Shared / LocaleTrait.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Command\Shared\LocaleTrait.
6  */
7
8 namespace Drupal\Console\Command\Shared;
9
10 trait LocaleTrait
11 {
12     /**
13      * Provides debug info for projects in case translation files are not found.
14      *
15      * Translations files are being fetched either from Drupal translation server
16      * and local files or only from the local filesystem depending on the
17      * "Translation source" setting at admin/config/regional/translate/settings.
18      * This method will produce debug information including the respective path(s)
19      * based on this setting.
20      *
21      * Translations for development versions are never fetched, so the debug info
22      * for that is a fixed message.
23      *
24      * @param array $project_info
25      *   An array which is the project information of the source.
26      *
27      * @return string
28      *   The string which contains debug information.
29      */
30     protected function createInfoString($project_info)
31     {
32         $remote_path = isset($project_info->files['remote']->uri) ? $project_info->files['remote']->uri : false;
33         $local_path = isset($project_info->files['local']->uri) ? $project_info->files['local']->uri : false;
34
35         if (strpos($project_info->version, 'dev') !== false) {
36             return $this->trans('commands.locale.translation.status.messages.no-translation-files');
37         }
38         if (locale_translation_use_remote_source() && $remote_path && $local_path) {
39             return sprintf(
40                 $this->trans('commands.locale.translation.status.messages.file-not-found'),
41                 $local_path,
42                 $remote_path
43             );
44         } elseif ($local_path) {
45             return
46                 sprintf(
47                     $this->trans('commands.locale.translation.status.messages.local-file-not-found'),
48                     $local_path
49                 );
50         }
51
52         return $this->trans('commands.locale.translation.status.messages.translation-not-determined');
53     }
54
55     /**
56      * LOCALE_TRANSLATION_REMOTE
57      * and LOCALE_TRANSLATION_LOCAL indicate available new translations,
58      * LOCALE_TRANSLATION_CURRENT indicate that the current translation is them
59      * most recent.
60      */
61     protected function projectsStatus()
62     {
63         $status_report = [];
64         $status = locale_translation_get_status();
65         foreach ($status as $project_id => $project) {
66             foreach ($project as $langcode => $project_info) {
67                 $info = '';
68                 if ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
69                     $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : null;
70                     $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : null;
71                     $local_age = $local->timestamp? format_date($local->timestamp, 'html_date'): '';
72                     $remote_age = $remote->timestamp? format_date($remote->timestamp, 'html_date'): '';
73
74                     if ($local_age >= $remote_age) {
75                         $info = $this->trans('commands.locale.translation.status.messages.translation-project-updated');
76                     } else {
77                         $info = $this->trans('commands.locale.translation.status.messages.translation-project-available');
78                     }
79                 } elseif ($project_info->type == LOCALE_TRANSLATION_CURRENT) {
80                     $info = $this->trans('commands.locale.translation.status.messages.translation-project-updated');
81                 } else {
82                     $local_age = '';
83                     $remote_age = '';
84                     $info = $this->createInfoString($project_info);
85                 }
86
87                 $status_report[$langcode][] = [$project_info->name, $project_info->version, $local_age, $remote_age ,$info ];
88             }
89         }
90
91         return $status_report;
92     }
93 }