You are here

function lingotek_bulk_grid_parse_config_data in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.config.inc \lingotek_bulk_grid_parse_config_data()
1 call to lingotek_bulk_grid_parse_config_data()
lingotek_config_get_rows in ./lingotek.config.inc

File

./lingotek.config.inc, line 235
Config grid form elements

Code

function lingotek_bulk_grid_parse_config_data($table_data_raw, $entity_type) {
  $lingotek_languages = Lingotek::getLanguages();
  $lids = array_keys($table_data_raw);
  $existing_translations = !empty($lids) ? lingotek_config_add_existing_translations($lids, $lingotek_languages) : array();
  $languages = language_list();
  $global_profile = lingotek_get_global_profile();
  $non_lingotek_config_translations = lingotek_get_locked_config_translations($lids);
  $table_data = array();
  foreach ($table_data_raw as $row) {
    $lid = $row->{'lid'};
    $row->lingotek = $global_profile;
    $row->lingotek['profile'] = 1;
    $row->language = 'en';
    $locale_statuses = lingotek_build_locales_statuses($row, FALSE);
    $item_is_current = LingotekConfigSet::isLidCurrent($lid);
    $item_has_translations = array_key_exists($lid, $existing_translations);
    $source_was_edited = $row->source_edited && $item_is_current !== FALSE ? explode(',', $row->source_edited) : array();
    $item_belongs_to_set = !empty($locale_statuses);
    if ($source_was_edited) {
      $row->upload_status = LingotekSync::STATUS_EDITED;
      foreach ($source_was_edited as $key => $lang) {
        $locale = Lingotek::convertDrupal2Lingotek($lang);
        $locale_statuses[$locale] = 'edited';
      }
    }
    $not_uploaded_to_lingotek = !$item_has_translations && $item_is_current;
    ksort($locale_statuses);
    if ($item_belongs_to_set) {
      if ($not_uploaded_to_lingotek) {
        unset($locale_statuses);
        $locale_statuses = array();
        $row->upload_status = NULL;
      }
    }
    elseif ($item_has_translations) {

      // No translations in locales + translations in locales_target = Untracked.
      foreach ($existing_translations[$lid] as $existing_locale) {
        $locale_statuses[$existing_locale] = 'untracked';
      }
    }
    $escaped_source = htmlentities($row->{'source'});
    $source_text = lingotek_truncate_grid_text($escaped_source, 55);
    $translation_icons = lingotek_lang_icons($entity_type, $languages, $lid, $locale_statuses, FALSE, $row->language, FALSE, FALSE, $non_lingotek_config_translations);

    // show translation statuses
    $target_icons_str = implode('', array_values($translation_icons));
    $icon = lingotek_source_uploaded_icon($row);
    $source_uploaded = lingotek_render_source($entity_type, $row, $icon, $languages, 'language');
    $set_id = LingotekConfigSet::getSetId($lid, FALSE);
    $set_name = $set_id !== FALSE ? LingotekConfigSet::getTitleBySetId($set_id) : t('N/A');
    $data = array(
      'lid' => $lid ?: t('??'),
      'source' => '<a class="tooltips">' . $source_text . '<span>' . $escaped_source . '</span></a>',
      'source_uploaded' => $source_uploaded,
      'location' => $row->{'location'},
      'context' => $row->{'context'},
      'textgroup' => $row->{'textgroup'} == 'default' ? 'built-in interface' : $row->{'textgroup'},
      'translations' => $target_icons_str,
      'doc_id' => $row->document_id ? $row->document_id : t('N/A'),
      'set_name' => '<span class="set_name">' . $set_name . '</span>',
    );
    $table_data[$lid] = $data;
  }
  return $table_data;
}