i18n_path.module 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module - Path translation
  5. */
  6. /**
  7. * Implements hook_menu()
  8. */
  9. function i18n_path_menu() {
  10. $items['admin/config/regional/i18n_translation/path'] = array(
  11. 'title' => 'Paths',
  12. 'description' => 'Path translation.',
  13. 'page callback' => 'i18n_path_admin_overview',
  14. 'access arguments' => array('administer site configuration'),
  15. 'file' => 'i18n_path.admin.inc',
  16. 'type' => MENU_LOCAL_TASK,
  17. 'weight' => 10,
  18. );
  19. $items['admin/config/regional/i18n_translation/path/list'] = array(
  20. 'title' => 'Paths',
  21. 'type' => MENU_DEFAULT_LOCAL_TASK,
  22. 'weight' => -10,
  23. );
  24. $items['admin/config/regional/i18n_translation/path/add'] = array(
  25. 'title' => 'Add path translation',
  26. 'page callback' => 'drupal_get_form',
  27. 'page arguments' => array('i18n_path_admin_form'),
  28. 'access arguments' => array('administer site configuration'),
  29. 'file' => 'i18n_path.admin.inc',
  30. 'type' => MENU_LOCAL_ACTION,
  31. 'parent' => 'admin/config/regional/i18n_translation',
  32. );
  33. $items['admin/config/regional/i18n_translation/path/edit/%i18n_path_translation_set'] = array(
  34. 'title' => 'Edit path translation',
  35. 'page callback' => 'drupal_get_form',
  36. 'page arguments' => array('i18n_path_admin_form', 6),
  37. 'access arguments' => array('administer site configuration'),
  38. 'file' => 'i18n_path.admin.inc',
  39. 'type' => MENU_LOCAL_TASK,
  40. 'context' => MENU_CONTEXT_INLINE,
  41. );
  42. $items['admin/config/regional/i18n_translation/path/delete/%i18n_path_translation_set'] = array(
  43. 'title' => 'Delete path translation',
  44. 'page callback' => 'drupal_get_form',
  45. 'page arguments' => array('i18n_translation_set_delete_confirm', 6),
  46. 'access arguments' => array('administer site configuration'),
  47. 'file' => 'i18n_path.admin.inc',
  48. 'type' => MENU_LOCAL_TASK,
  49. 'context' => MENU_CONTEXT_INLINE,
  50. );
  51. return $items;
  52. }
  53. /**
  54. * Implements hook_url_outbound_alter()
  55. */
  56. /*
  57. function i18n_path_url_outbound_alter(&$path, &$options, $original_path) {
  58. if (!empty($options['language'])) {
  59. $langcode = $options['language']->language;
  60. $original = $options['alias'] ? drupal_get_normal_path($path, $langcode) : $original_path;
  61. if (($translations = i18n_path_get_translations($path)) && !empty($translations[$langcode])) {
  62. $path = $options['alias'] ? drupal_get_path_alias($translations[$langcode], $langcode) : $translations[$langcode];
  63. }
  64. }
  65. }
  66. */
  67. /**
  68. * Get translations for path
  69. */
  70. function i18n_path_get_translations($path) {
  71. static $translations;
  72. if (!isset($translations)) {
  73. $translations = drupal_static(__FUNCTION__, array());
  74. }
  75. if (!isset($translations[$path])) {
  76. $translations[$path] = db_query('SELECT p.language, p.path FROM {i18n_path} p INNER JOIN {i18n_path} ps ON p.tsid = ps.tsid WHERE ps.path = :path',
  77. array(':path' => $path)
  78. )->fetchAllKeyed();
  79. }
  80. return $translations[$path];
  81. }
  82. /**
  83. * Implements hook_i18n_object_info().
  84. */
  85. function i18n_path_i18n_object_info() {
  86. return array(
  87. 'path' => array(
  88. 'title' => t('Path'),
  89. 'class' => 'i18n_path_object',
  90. 'key' => array('path', 'language'),
  91. 'translation set' => TRUE,
  92. )
  93. );
  94. }
  95. /**
  96. * Implements hook_i18n_translation_set_info()
  97. */
  98. function i18n_path_i18n_translation_set_info() {
  99. return array(
  100. 'path' => array(
  101. 'title' => t('Path'),
  102. 'class' => 'i18n_path_translation_set',
  103. 'table' => 'i18n_path',
  104. 'field' => 'tsid',
  105. 'placeholder' => '%i18n_path_translation_set',
  106. 'edit path' => 'admin/config/regional/i18n_translation/path/edit/%i18n_path_translation_set',
  107. 'delete path' => 'admin/config/regional/i18n_translation/path/delete/%i18n_path_translation_set',
  108. 'list path' => 'admin/config/regional/i18n_translation/path',
  109. ),
  110. );
  111. }
  112. /**
  113. * Implements hook_i18n_translate_path()
  114. */
  115. function i18n_path_i18n_translate_path($path) {
  116. if ($translations = i18n_path_get_translations($path)) {
  117. $result = array();
  118. foreach ($translations as $langcode => $translated) {
  119. $result[$langcode] = array(
  120. 'href' => $translated,
  121. );
  122. }
  123. return $result;
  124. }
  125. }
  126. /**
  127. * Load translation set. Menu loading callback.
  128. */
  129. function i18n_path_translation_set_load($tsid) {
  130. return i18n_translation_set_load($tsid, 'path');
  131. }