You are here

function i18n_menu_translation_item_overview in Internationalization 7

Callback for menu translation tab.

1 call to i18n_menu_translation_item_overview()
i18n_menu_item_translation_page in i18n_menu/i18n_menu.i18n.inc
Callback for menu item translation tab.

File

i18n_menu/i18n_menu.admin.inc, line 214
Helper functions for menu administration.

Code

function i18n_menu_translation_item_overview($item, $translation_set = NULL) {
  if ($item['i18n_tsid']) {

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

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

      // Existing translation in the translation set: display status.
      $translation_item = menu_link_load($translations[$langcode]['mlid']);
      $title = l($translation_item['link_title'], $translation_item['link_path']);
      $path = 'admin/structure/menu/item/' . $translation_item['mlid'];
      $options[] = l(t('edit'), $path);
      if ($translation_item['mlid'] == $item['mlid']) {
        $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[] = l(t('add translation'), 'admin/structure/menu/manage/' . $item['menu_name'] . '/add', array(
        'query' => array(
          'translation' => $item['mlid'],
          'target' => $langcode,
        ) + drupal_get_destination(),
      ));
    }
    $rows[$langcode] = array(
      'language' => $language_name,
      'title' => $title,
      'operations' => implode(" | ", $options),
    );
  }
  drupal_set_title(t('Translations of menu item %title', array(
    '%title' => $item['link_title'],
  )), PASS_THROUGH);
  $build['translation_overview'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );
  return $build;
}