You are here

function drush_l10n_update in Localization update 7.2

Same name and namespace in other branches
  1. 6 l10n_update.drush.inc \drush_l10n_update()
  2. 7 l10n_update.drush.inc \drush_l10n_update()

Callback for command l10n-update.

File

./l10n_update.drush.inc, line 126
Drush interface to l10n-update functionalities.

Code

function drush_l10n_update() {
  module_load_include('fetch.inc', 'l10n_update');
  $updates = _drush_l10n_update_get_updates();
  if ($updates['projects']) {
    drush_log(dt('Found @count projects to update.', array(
      '@count' => count($updates['projects']),
    )), 'status');

    // Batch update all projects for selected languages.
    $mode = drush_get_option('mode', 'keep');
    $options = _l10n_update_default_update_options();
    switch ($mode) {
      case 'keep':
        $options['overwrite_options'] = array(
          'not_customized' => FALSE,
          'customized' => FALSE,
        );
        break;
      case 'replace':
        $options['overwrite_options'] = array(
          'not_customized' => TRUE,
          'customized' => FALSE,
        );
        break;
      case 'overwrite':
        $options['overwrite_options'] = array(
          'not_customized' => TRUE,
          'customized' => TRUE,
        );
        break;
      default:
        return drush_set_error('L10N_UPDATE_INVALID_MODE', dt('Invalid update mode. Valid options are keep, overwrite.'));
    }
    $languages = array_keys(drush_get_option('languages'));

    // Get translation status of the projects, download and update translations.
    $batch = l10n_update_batch_update_build(array_keys($updates['projects']), $languages, $options);
    drush_log($batch['title'], 'status');
    drush_log($batch['init_message'], 'status');
    batch_set($batch);
    drush_backend_batch_process();
  }
  else {
    drush_log(dt('All project translations up to date'), 'status');
  }
}