i18n_menu.i18n.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) hooks
  5. */
  6. /**
  7. * Implements hook_i18n_object_info().
  8. */
  9. function i18n_menu_i18n_object_info() {
  10. $info['menu'] = array(
  11. 'title' => t('Menu'),
  12. 'key' => 'menu_name',
  13. 'load callback' => 'menu_load',
  14. 'base path' => 'admin/structure/menu/manage',
  15. 'placeholders' => array(
  16. '%menu' => 'menu_name',
  17. ),
  18. 'edit path' => 'admin/structure/menu/manage/%menu/edit',
  19. // Auto-generate translate tab.
  20. 'translate tab' => 'admin/structure/menu/manage/%menu/translate',
  21. // We can easily list all these objects
  22. 'list callback' => 'menu_load_all',
  23. // Metadata for string translation
  24. 'string translation' => array(
  25. 'textgroup' => 'menu',
  26. 'type' => 'menu',
  27. 'properties' => array(
  28. 'title' => t('Title'),
  29. 'description' => t('Description'),
  30. ),
  31. ),
  32. 'translation container' => array(
  33. 'name' => t('menu'),
  34. 'item type' => 'menu_link',
  35. 'item name' => t('menu items'),
  36. 'options' => array(I18N_MODE_NONE, I18N_MODE_MULTIPLE, I18N_MODE_LANGUAGE),
  37. ),
  38. );
  39. $info['menu_link'] = array(
  40. 'title' => t('Menu link'),
  41. 'class' => 'i18n_menu_link',
  42. 'key' => 'mlid',
  43. 'load callback' => 'menu_link_load',
  44. 'base path' => 'admin/structure/menu/item',
  45. 'edit path' => 'admin/structure/menu/item/%menu_link/edit',
  46. // Auto-generate translate tab
  47. 'translate tab' => 'admin/structure/menu/item/%menu_link/translate',
  48. 'placeholders' => array(
  49. '%menu_link' => 'mlid',
  50. '%menu' => 'menu_name',
  51. ),
  52. 'string translation' => array(
  53. 'textgroup' => 'menu',
  54. 'type' => 'item',
  55. 'properties' => array(
  56. 'title' => array(
  57. 'title' => t('Title'),
  58. 'field' => 'link_title',
  59. ),
  60. 'description' => array(
  61. 'title' => t('Description'),
  62. 'field' => 'options.attributes.title',
  63. ),
  64. ),
  65. ),
  66. 'translation set' => TRUE,
  67. );
  68. return $info;
  69. }
  70. /**
  71. * Implements hook_i18n_translation_set_info()
  72. */
  73. function i18n_menu_i18n_translation_set_info() {
  74. $info['menu_link'] = array(
  75. 'title' => t('Menu link'),
  76. 'class' => 'i18n_menu_link_translation_set',
  77. 'table' => 'menu_links',
  78. 'field' => 'i18n_tsid',
  79. 'parent' => 'menu',
  80. 'placeholder' => '%i18n_menu_translation',
  81. 'list path' => 'admin/structure/menu/manage/translation',
  82. 'edit path' => 'admin/structure/menu/manage/translation/edit/%i18n_menu_translation',
  83. 'delete path' => 'admin/structure/menu/manage/translation/delete/%i18n_menu_translation',
  84. 'page callback' => 'i18n_menu_item_translation_page',
  85. );
  86. return $info;
  87. }
  88. /**
  89. * Implements hook_i18n_string_info()
  90. */
  91. function i18n_menu_i18n_string_info() {
  92. $groups['menu'] = array(
  93. 'title' => t('Menu'),
  94. 'description' => t('Translatable menu items: title and description.'),
  95. 'format' => FALSE, // This group doesn't have strings with format
  96. 'list' => TRUE, // This group can list all strings
  97. );
  98. return $groups;
  99. }
  100. /**
  101. * Implements hook_i18n_string_objects()
  102. */
  103. function i18n_menu_i18n_string_objects($type) {
  104. if ($type == 'menu_link') {
  105. // All menu items that have no language and are customized.
  106. return db_select('menu_links', 'm')
  107. ->fields('m')
  108. ->condition('language', LANGUAGE_NONE)
  109. ->condition('customized', 1)
  110. ->execute()
  111. ->fetchAllAssoc('mlid', PDO::FETCH_ASSOC);
  112. }
  113. }
  114. /**
  115. * Callback for menu item translation tab.
  116. */
  117. function i18n_menu_item_translation_page($type, $item) {
  118. module_load_include('admin.inc', 'i18n_menu');
  119. // If the item has a language code, we can only support translation sets.
  120. $translation_set = !empty($item['i18n_tsid']) ? i18n_translation_set_load($item['i18n_tsid']) : NULL;
  121. $overview = i18n_menu_translation_item_overview($item, $translation_set);
  122. $translation_form = drupal_get_form('i18n_menu_translation_form', $translation_set, $item);
  123. return $overview + $translation_form;
  124. }