5 * Provides Drush commands related to Interface Translation.
9 * Implementation of hook_drush_help().
11 function locale_drush_help($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.');
21 * Implementation of hook_drush_command().
23 function locale_drush_command() {
24 $items['locale-check'] = [
25 'description' => 'Checks for available translation updates.',
26 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
28 $items['locale-update'] = [
29 'description' => 'Updates the available translations.',
31 'langcodes' => 'A comma-separated list of language codes to update. If omitted, all translations will be updated.'
33 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
35 // @todo Implement proper export and import commands.
40 * Checks for available translation updates.
42 * @see \Drupal\locale\Controller\LocaleController::checkTranslation()
44 * @todo This can be simplified once https://www.drupal.org/node/2631584 lands
47 function drush_locale_check() {
48 \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
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();
56 // Execute a batch if required. A batch is only used when remote files
59 drush_backend_batch_process();
64 * Imports the available translation updates.
66 * @see TranslationStatusForm::buildForm()
67 * @see TranslationStatusForm::prepareUpdateData()
68 * @see TranslationStatusForm::submitForm()
70 * @todo This can be simplified once https://www.drupal.org/node/2631584 lands
73 function drush_locale_update() {
74 $module_handler = \Drupal::moduleHandler();
75 $module_handler->loadInclude('locale', 'fetch.inc');
76 $module_handler->loadInclude('locale', 'bulk.inc');
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;
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.
92 // @todo Restricting by projects is not possible in the user interface and is
93 // broken when attempting to do it in a hook_form_alter() implementation so
94 // we do not allow for it here either.
97 // Set the translation import options. This determines if existing
98 // translations will be overwritten by imported strings.
99 $options = _locale_translation_default_update_options();
101 // If the status was updated recently we can immediately start fetching the
102 // translation updates. If the status is expired we clear it an run a batch to
103 // update the status and then fetch the translation updates.
104 $last_checked = \Drupal::state()->get('locale.translation_last_checked');
105 if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
106 locale_translation_clear_status();
107 $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
111 // Set a batch to download and import translations.
112 $batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
114 // Set a batch to update configuration as well.
115 if ($batch = locale_config_batch_update_components($options, $langcodes)) {
120 drush_backend_batch_process();