function drush_locale_update

master locale.d8.drush.inc drush_locale_update()

Imports the available translation updates.

@todo This can be simplified once https://www.drupal.org/node/2631584 lands in Drupal core.

See also

TranslationStatusForm::buildForm()

TranslationStatusForm::prepareUpdateData()

TranslationStatusForm::submitForm()

File

commands/core/locale.d8.drush.inc, line 75
Provides Drush commands related to Interface Translation.

Code

function drush_locale_update() {
  $module_handler = \Drupal::moduleHandler();
  $module_handler->loadInclude('locale', 'fetch.inc');
  $module_handler->loadInclude('locale', 'bulk.inc');

  $langcodes =[];
  foreach (locale_translation_get_status() as $project_id => $project) {
    foreach ($project as $langcode => $project_info) {
      if (!empty($project_info->type) && !in_array($langcode, $langcodes)) {
        $langcodes[] = $langcode;
      }
    }
  }

  if ($passed_langcodes = drush_get_option('langcodes')) {
    $langcodes = array_intersect($langcodes, explode(',', $passed_langcodes));
    // @todo Not selecting any language code in the user interface results in
    //   all translations being updated, so we mimick that behavior here.
  }
  // @todo Restricting by projects is not possible in the user interface and is
  //   broken when attempting to do it in a hook_form_alter() implementation so
  //   we do not allow for it here either.
  $projects =[];

  // Set the translation import options. This determines if existing
  // translations will be overwritten by imported strings.
  $options = _locale_translation_default_update_options();

  // If the status was updated recently we can immediately start fetching the
  // translation updates. If the status is expired we clear it an run a batch to
  // update the status and then fetch the translation updates.
  $last_checked = \Drupal::state()->get('locale.translation_last_checked');
  if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) {
    locale_translation_clear_status();
    $batch = locale_translation_batch_update_build(array(), $langcodes, $options);
    batch_set($batch);
  }
  else {
    // Set a batch to download and import translations.
    $batch = locale_translation_batch_fetch_build($projects, $langcodes, $options);
    batch_set($batch);
    // Set a batch to update configuration as well.
    if ($batch = locale_config_batch_update_components($options, $langcodes)) {
      batch_set($batch);
    }
  }

  drush_backend_batch_process();
}