You are here

function lingotek_form_bulk_sync in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.3 lingotek.sync.inc \lingotek_form_bulk_sync()
  2. 7.4 lingotek.sync.inc \lingotek_form_bulk_sync()
1 string reference to 'lingotek_form_bulk_sync'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.sync.inc, line 208
Sync and management

Code

function lingotek_form_bulk_sync($form, $form_state) {
  global $base_url;
  module_load_include('admin.inc', 'lingotek');
  $submit_functions = array(
    'lingotek_form_bulk_sync_submit',
  );
  $report = LingotekSync::getReport();
  $upload_count_total = isset($report['upload_config_count']) ? $report['upload_config_count'] : 0;

  // Upload
  $form['upload'] = array(
    '#type' => 'fieldset',
    '#title' => t('Upload config for translation'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#group' => 'administrative_settings',
    '#prefix' => '<div id="upload_wrapper">',
    '#suffix' => '</div>',
  );
  if (variable_get('lingotek_translate_config') && $upload_count_total > 0) {

    // pre-build include/exclude messages based on enabled config types
    $config_types = array(
      'lingotek_translate_config_builtins' => t('Include built-in interface data'),
      'lingotek_translate_config_blocks' => t('blocks'),
      'lingotek_translate_config_menus' => t('menus'),
      'lingotek_translate_config_views' => t('views'),
      'lingotek_translate_config_taxonomies' => t('taxonomy vocabularies & terms'),
      'lingotek_translate_config_fields' => t('field labels'),
      'lingotek_translate_config_misc' => t('other miscellaneous strings'),
    );
    $config_types_included = array();
    $config_types_excluded = array();
    foreach ($config_types as $k => $v) {
      if (variable_get($k, 0)) {
        $config_types_included[$k] = $v;
      }
      else {
        $config_types_excluded[$k] = $v;
      }
    }
    $cf_included_str = implode(', ', $config_types_included);
    if (count($config_types_included) > 1) {
      $cf_included_str = substr_replace($cf_included_str, ' ' . t('and') . ' ' . substr($cf_included_str, strrpos($cf_included_str, ', ') + 2), strrpos($cf_included_str, ', '));
    }
    $cf_excluded_str = implode(', ', $config_types_excluded);
    if (count($config_types_excluded) > 1) {
      $cf_excluded_str = substr_replace($cf_excluded_str, ' ' . t('and') . ' ' . substr($cf_excluded_str, strrpos($cf_excluded_str, ', ') + 2), strrpos($cf_excluded_str, ', '));
    }
    $form['upload']['upload_config_json'] = array(
      '#type' => 'hidden',
      '#value' => json_encode($report['upload_config']),
    );
    $form['upload']['upload_config'] = array(
      '#type' => 'checkbox',
      '#title' => $cf_included_str . ' (<span id="upload-config-total">' . $report['upload_config_count'] . ' ' . format_plural($report['upload_config_count'], 'set', 'sets') . ' ' . t('of additions/changes') . '</span>)',
      '#default_value' => $report['upload_config_count'] == 0 ? 0 : 1,
      '#disabled' => $report['upload_config_count'] == 0,
    );
    $additional_desc = '';
    if (count($config_types_excluded)) {
      $additional_desc .= t('(You can also enable translation for') . ' ' . $cf_excluded_str . ' ' . t('within') . ' ' . t('Translation Configuration in') . ' ' . l(t('Lingotek Settings'), 'admin/settings/lingotek/settings') . ')<br/>';
    }
    if (variable_get('lingotek_use_translation_from_drupal')) {
      $modules = lingotek_admin_get_enabled_modules();
      $updates = lingotek_check_for_l10n_translations($modules);
      if (!empty($updates)) {
        $additional_desc .= format_plural(count($updates), 'You have 1 pending localization import from Drupal included in this step.', 'You have @count pending localization imports from Drupal included in this step.');
      }
    }
    if ($additional_desc) {
      $form['upload']['upload_config']['#description'] = $additional_desc;
    }
  }
  else {
    $form['upload']['none'] = array(
      '#markup' => t('There are currently no new/modified items to be uploaded.'),
    );
  }

  // Download
  $form['download'] = array(
    '#type' => 'fieldset',
    '#title' => t('Download config translations'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#group' => 'vertical_tab',
  );
  $form['download']['download_targets_workflow_complete_json'] = array(
    '#type' => 'hidden',
    '#value' => json_encode($report['download_targets_workflow_complete']),
  );
  $form['download']['download_targets_workflow_incomplete_json'] = array(
    '#type' => 'hidden',
    '#value' => json_encode($report['download_targets_workflow_incomplete']),
  );
  $download_count_total = $report['download_targets_workflow_complete_count'] + (isset($report['download_targets_workflow_incomplete_count']) ? $report['download_targets_workflow_incomplete_count'] : 0);
  $available_targets = Lingotek::getLanguages();
  $options_complete = array();

  // locale => label
  $options_incomplete = array();
  foreach ($available_targets as $target) {
    $label = $target->name . ' / ' . $target->native . ' (' . $target->lingotek_locale . ')';
    $locale_complete_count = 0;
    foreach ($report['download_targets_workflow_complete'] as $download_target) {
      if ($target->lingotek_locale == $download_target['locale']) {
        $locale_complete_count++;
      }
    }
    $locale_incomplete_count = 0;
    foreach ($report['download_targets_workflow_incomplete'] as $download_target) {
      if ($target->lingotek_locale == $download_target['locale']) {
        $locale_incomplete_count++;
      }
    }
    if ($locale_complete_count > 0) {
      $row = array(
        array(
          'data' => $label,
          'width' => '20%',
        ),
        array(
          'data' => $locale_complete_count,
          'width' => '80%',
        ),
      );
      $options_complete[$target->lingotek_locale] = $row;
    }
    if ($locale_incomplete_count > 0) {
      $row = array(
        array(
          'data' => $label,
          'width' => '20%',
        ),
        array(
          'data' => $locale_incomplete_count,
          'width' => '80%',
        ),
      );
      $options_incomplete[$target->lingotek_locale] = $row;
    }
  }
  if (empty($options_complete) && empty($options_incomplete)) {
    $form['download']['none'] = array(
      '#markup' => t('There are currently no pending translations to be downloaded.'),
    );
  }
  if (!empty($options_complete)) {
    $form['download']['download_locales_complete'] = array(
      '#type' => 'tableselect',
      '#prefix' => t('Completed Translations'),
      '#header' => array(
        t('Language'),
        t('Translations'),
      ),
      '#options' => $options_complete,
      '#default_value' => array_fill_keys(array_keys($options_complete), 1),
    );
  }
  if (!empty($options_incomplete)) {

    /* $form['download']['download_locales_incomplete_check'] = array(
       '#type' => 'checkbox',
       '#title' => t('Download Incomplete Translations'),
       '#default_value' => 0,
       ); */
    $form['download']['download_locales_incomplete'] = array(
      '#type' => 'tableselect',
      '#prefix' => t('Incomplete Translations'),
      '#header' => array(
        t('Language'),
        t('Translations'),
      ),
      '#options' => $options_incomplete,
      '#default_value' => array_fill_keys(array_keys($options_complete), 0),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Sync'),
    '#disabled' => $upload_count_total == 0 && $download_count_total == 0,
    '#submit' => $submit_functions,
  );
  $form['force_download'] = array(
    '#type' => 'submit',
    '#value' => t('Force Download All'),
    '#submit' => $submit_functions,
  );
  return $form;
}