You are here

function i18n_taxonomy_translation_term_overview in Internationalization 7

Callback for term translation tab.

1 call to i18n_taxonomy_translation_term_overview()
i18n_taxonomy_term_translation_page in i18n_taxonomy/i18n_taxonomy.i18n.inc
Callback for term translation tab.

File

i18n_taxonomy/i18n_taxonomy.admin.inc, line 177
Helper functions for taxonomy administration.

Code

function i18n_taxonomy_translation_term_overview($term) {
  if ($term->i18n_tsid) {

    // Already part of a set, grab that set.
    $i18n_tsid = $term->i18n_tsid;
    $translation_set = i18n_translation_set_load($term->i18n_tsid);
    $translation_set
      ->get_translations();
    $translations = $translation_set
      ->get_translations();
  }
  else {

    // We have no translation source nid, this could be a new set, emulate that.
    $i18n_tsid = $term->tid;
    $translations = array(
      $term->language => $term,
    );
  }
  $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
  $header = array(
    t('Language'),
    t('Title'),
    t('Operations'),
  );
  foreach (i18n_language_list() as $langcode => $language_name) {
    $options = array();
    if (isset($translations[$langcode])) {

      // Existing translation in the translation set: display status.
      // We load the full node to check whether the user can edit it.
      $translation_term = taxonomy_term_load($translations[$langcode]->tid);
      $path = 'taxonomy/term/' . $translation_term->tid;
      $title = l($translation_term->name, $path);
      $options['edit'] = array(
        '#type' => 'link',
        '#title' => t('edit'),
        '#href' => $path . '/edit',
        '#options' => array(
          'query' => drupal_get_destination(),
        ),
      );
      if ($translation_term->tid == $i18n_tsid) {
        $language_name = t('<strong>@language_name</strong> (source)', array(
          '@language_name' => $language_name,
        ));
      }
    }
    else {

      // No such translation in the set yet: help user to create it.
      $title = t('n/a');
      $options['add'] = array(
        '#type' => 'link',
        '#title' => t('add translation'),
        '#href' => 'admin/structure/taxonomy/' . $term->vocabulary_machine_name . '/add',
        '#options' => array(
          'query' => array(
            'translation' => $term->tid,
            'target' => $langcode,
          ) + drupal_get_destination(),
        ),
      );
    }
    $rows[$langcode] = array(
      'language' => $language_name,
      'title' => $title,
      'operations' => array(
        'data' => $options,
      ),
    );
  }
  drupal_set_title(t('Translations of term %title', array(
    '%title' => $term->name,
  )), PASS_THROUGH);
  $build['translation_overview'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}