translation.pages.inc

  1. 7.x drupal-7.x/modules/translation/translation.pages.inc
  2. 6.x drupal-6.x/modules/translation/translation.pages.inc

User page callbacks for the Translation module.

File

drupal-7.x/modules/translation/translation.pages.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * User page callbacks for the Translation module.
  5. */
  6. /**
  7. * Page callback: Displays a list of a node's translations.
  8. *
  9. * @param $node
  10. * A node object.
  11. *
  12. * @return
  13. * A render array for a page containing a list of content.
  14. *
  15. * @see translation_menu()
  16. */
  17. function translation_node_overview($node) {
  18. include_once DRUPAL_ROOT . '/includes/language.inc';
  19. if ($node->tnid) {
  20. // Already part of a set, grab that set.
  21. $tnid = $node->tnid;
  22. $translations = translation_node_get_translations($node->tnid);
  23. }
  24. else {
  25. // We have no translation source nid, this could be a new set, emulate that.
  26. $tnid = $node->nid;
  27. $translations = array(entity_language('node', $node) => $node);
  28. }
  29. $type = variable_get('translation_language_type', LANGUAGE_TYPE_INTERFACE);
  30. $header = array(t('Language'), t('Title'), t('Status'), t('Operations'));
  31. foreach (language_list() as $langcode => $language) {
  32. $options = array();
  33. $language_name = $language->name;
  34. if (isset($translations[$langcode])) {
  35. // Existing translation in the translation set: display status.
  36. // We load the full node to check whether the user can edit it.
  37. $translation_node = node_load($translations[$langcode]->nid);
  38. $path = 'node/' . $translation_node->nid;
  39. $links = language_negotiation_get_switch_links($type, $path);
  40. $title = empty($links->links[$langcode]['href']) ? l($translation_node->title, $path) : l($translation_node->title, $links->links[$langcode]['href'], $links->links[$langcode]);
  41. if (node_access('update', $translation_node)) {
  42. $text = t('edit');
  43. $path = 'node/' . $translation_node->nid . '/edit';
  44. $links = language_negotiation_get_switch_links($type, $path);
  45. $options[] = empty($links->links[$langcode]['href']) ? l($text, $path) : l($text, $links->links[$langcode]['href'], $links->links[$langcode]);
  46. }
  47. $status = $translation_node->status ? t('Published') : t('Not published');
  48. $status .= $translation_node->translate ? ' - <span class="marker">' . t('outdated') . '</span>' : '';
  49. if ($translation_node->nid == $tnid) {
  50. $language_name = t('<strong>@language_name</strong> (source)', array('@language_name' => $language_name));
  51. }
  52. }
  53. else {
  54. // No such translation in the set yet: help user to create it.
  55. $title = t('n/a');
  56. if (node_access('create', $node)) {
  57. $text = t('add translation');
  58. $path = 'node/add/' . str_replace('_', '-', $node->type);
  59. $links = language_negotiation_get_switch_links($type, $path);
  60. $query = array('query' => array('translation' => $node->nid, 'target' => $langcode));
  61. $options[] = empty($links->links[$langcode]['href']) ? l($text, $path, $query) : l($text, $links->links[$langcode]['href'], array_merge_recursive($links->links[$langcode], $query));
  62. }
  63. $status = t('Not translated');
  64. }
  65. $rows[] = array($language_name, $title, $status, implode(" | ", $options));
  66. }
  67. drupal_set_title(t('Translations of %title', array('%title' => $node->title)), PASS_THROUGH);
  68. $build['translation_node_overview'] = array(
  69. '#theme' => 'table',
  70. '#header' => $header,
  71. '#rows' => $rows,
  72. );
  73. return $build;
  74. }