Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / locale.d8.drush.inc
1 <?php
2
3 /**
4  * @file
5  * Provides Drush commands related to Interface Translation.
6  */
7
8 /**
9  * Implementation of hook_drush_help().
10  */
11 function locale_drush_help($section) {
12   switch ($section) {
13     case 'meta:locale:title':
14       return dt('Interface translation');
15     case 'meta:locale:summary':
16       return dt('Interact with the interface translation system.');
17   }
18 }
19
20 /**
21  * Implementation of hook_drush_command().
22  */
23 function locale_drush_command() {
24   $items['locale-check'] = [
25     'description' => 'Checks for available translation updates.',
26     'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
27   ];
28   $items['locale-update'] = [
29     'description' => 'Updates the available translations.',
30     'options' => [
31       'langcodes' => 'A comma-separated list of language codes to update. If omitted, all translations will be updated.'
32     ],
33     'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
34   ];
35   // @todo Implement proper export and import commands.
36   return $items;
37 }
38
39 /**
40  * Checks for available translation updates.
41  *
42  * @see \Drupal\locale\Controller\LocaleController::checkTranslation()
43  *
44  * @todo This can be simplified once https://www.drupal.org/node/2631584 lands
45  *   in Drupal core.
46  */
47 function drush_locale_check() {
48   \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
49
50   // Check translation status of all translatable project in all languages.
51   // First we clear the cached list of projects. Although not strictly
52   // necessary, this is helpful in case the project list is out of sync.
53   locale_translation_flush_projects();
54   locale_translation_check_projects();
55
56   // Execute a batch if required. A batch is only used when remote files
57   // are checked.
58   if (batch_get()) {
59     drush_backend_batch_process();
60   }
61 }
62
63 /**
64  * Imports the available translation updates.
65  *
66  * @see TranslationStatusForm::buildForm()
67  * @see TranslationStatusForm::prepareUpdateData()
68  * @see TranslationStatusForm::submitForm()
69  *
70  * @todo This can be simplified once https://www.drupal.org/node/2631584 lands
71  *   in Drupal core.
72  */
73 function drush_locale_update() {
74   $module_handler = \Drupal::moduleHandler();
75   $module_handler->loadInclude('locale', 'fetch.inc');
76   $module_handler->loadInclude('locale', 'bulk.inc');
77
78   $langcodes = [];
79   foreach (locale_translation_get_status() as $project_id => $project) {
80     foreach ($project as $langcode => $project_info) {
81       if (!empty($project_info->type)) {
82         $langcodes[] = $langcode;
83       }
84     }
85   }
86
87   if ($passed_langcodes = drush_get_option('langcodes')) {
88     $langcodes = array_intersect($langcodes, explode(',', $passed_langcodes));
89     // @todo Not selecting any language code in the user interface results in
90     //   all translations being updated, so we mimick that behavior here.
91   }
92   // Deduplicate the list of langcodes since each project may have added the
93   // same language several times.
94   $langcodes = array_unique($langcodes);
95
96   // @todo Restricting by projects is not possible in the user interface and is
97   //   broken when attempting to do it in a hook_form_alter() implementation so
98   //   we do not allow for it here either.
99   $projects = [];
100
101   // Set the translation import options. This determines if existing
102   // translations will be overwritten by imported strings.
103   $options = _locale_translation_default_update_options();
104
105   // If the status was updated recently we can immediately start fetching the
106   // translation updates. If the status is expired we clear it an run a batch to
107   // update the status and then fetch the translation updates.
108   $last_checked = \Drupal::state()->get('locale.translation_last_checked');
109   if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
110     locale_translation_clear_status();
111     $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
112     batch_set($batch);
113   }
114   else {
115     // Set a batch to download and import translations.
116     $batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
117     batch_set($batch);
118     // Set a batch to update configuration as well.
119     if ($batch = locale_config_batch_update_components($options, $langcodes)) {
120       batch_set($batch);
121     }
122   }
123
124   drush_backend_batch_process();
125 }