i18n_taxonomy.i18n.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) hooks
  5. */
  6. /**
  7. * Implements hook_i18n_object_info().
  8. */
  9. function i18n_taxonomy_i18n_object_info() {
  10. $info['taxonomy_term'] = array(
  11. 'title' => t('Taxonomy term'),
  12. 'class' => 'i18n_taxonomy_term',
  13. 'entity' => 'taxonomy_term',
  14. 'key' => 'tid',
  15. 'placeholders' => array(
  16. '%taxonomy_term' => 'tid',
  17. ),
  18. // Auto generate edit path
  19. 'edit path' => 'taxonomy/term/%taxonomy_term/edit',
  20. // Auto-generate translate tab
  21. 'translate tab' => 'taxonomy/term/%taxonomy_term/translate',
  22. 'translation set' => TRUE,
  23. 'string translation' => array(
  24. 'textgroup' => 'taxonomy',
  25. 'type' => 'term',
  26. 'properties' => array(
  27. 'name' => t('Name'),
  28. 'description' => array(
  29. 'title' => t('Description'),
  30. 'format' => 'format',
  31. ),
  32. ),
  33. )
  34. );
  35. $info['taxonomy_vocabulary'] = array(
  36. 'title' => t('Vocabulary'),
  37. 'entity' => 'taxonomy_vocabulary',
  38. 'key' => 'vid',
  39. 'placeholders' => array(
  40. '%taxonomy_vocabulary_machine_name' => 'machine_name',
  41. ),
  42. // Auto generate edit path
  43. 'edit path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/edit',
  44. // Auto-generate translate tab
  45. 'translate tab' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/translate',
  46. // We can easily list all these objects
  47. 'list callback' => 'taxonomy_get_vocabularies',
  48. // Metadata for string translation
  49. 'string translation' => array(
  50. 'textgroup' => 'taxonomy',
  51. 'type' => 'vocabulary',
  52. 'properties' => array(
  53. 'name' => t('Name'),
  54. 'description' => t('Description'),
  55. ),
  56. ),
  57. 'translation container' => array(
  58. 'name' => t('vocabulary'),
  59. 'item type' => 'taxonomy_term',
  60. 'item name' => t('terms'),
  61. 'options' => array(I18N_MODE_NONE, I18N_MODE_LOCALIZE, I18N_MODE_TRANSLATE, I18N_MODE_LANGUAGE),
  62. ),
  63. );
  64. return $info;
  65. }
  66. /**
  67. * Implements hook_i18n_translation_set_info()
  68. */
  69. function i18n_taxonomy_i18n_translation_set_info() {
  70. $info['taxonomy_term'] = array(
  71. 'title' => t('Taxonomy term'),
  72. 'class' => 'i18n_taxonomy_translation_set',
  73. 'table' => 'taxonomy_term_data',
  74. 'field' => 'i18n_tsid',
  75. 'parent' => 'taxonomy_vocabulary',
  76. 'placeholder' => '%i18n_taxonomy_translation_set',
  77. 'list path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets',
  78. 'edit path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets/edit/%i18n_taxonomy_translation_set',
  79. 'delete path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/sets/delete/%i18n_taxonomy_translation_set',
  80. 'page callback' => 'i18n_taxonomy_term_translation_page',
  81. );
  82. return $info;
  83. }
  84. /**
  85. * Implements hook_i18n_string_info()
  86. */
  87. function i18n_taxonomy_i18n_string_info() {
  88. $groups['taxonomy'] = array(
  89. 'title' => t('Taxonomy'),
  90. 'description' => t('Vocabulary titles and term names for localizable vocabularies.'),
  91. 'format' => FALSE, // This group doesn't have strings with format
  92. 'list' => FALSE, // This group cannot list all strings
  93. 'refresh callback' => 'i18n_taxonomy_i18n_string_refresh',
  94. );
  95. return $groups;
  96. }
  97. /**
  98. * Implements hook_i18n_string_objects()
  99. */
  100. function i18n_taxonomy_i18n_string_objects($type) {
  101. if ($type == 'taxonomy_term') {
  102. $terms = array();
  103. foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
  104. if (isset($vocabulary->i18n_mode) && $vocabulary->i18n_mode & I18N_MODE_LOCALIZE) {
  105. foreach (taxonomy_get_tree($vid, 0) as $term) {
  106. $terms[] = $term;
  107. }
  108. }
  109. }
  110. return $terms;
  111. }
  112. }
  113. /**
  114. * Callback for term translation tab.
  115. *
  116. * @param $type
  117. * Should be always 'taxonomy_term'
  118. * @pram $term
  119. * Taxonomy term object
  120. */
  121. function i18n_taxonomy_term_translation_page($type, $term) {
  122. module_load_include('admin.inc', 'i18n_taxonomy');
  123. $vocabulary = taxonomy_vocabulary_load($term->vid);
  124. $translation_set = !empty($term->i18n_tsid) ? i18n_translation_set_load($term->i18n_tsid) : NULL;
  125. $translation_overview = i18n_taxonomy_translation_term_overview($term);
  126. $translation_term_form = drupal_get_form('i18n_taxonomy_translation_term_form', $vocabulary, $translation_set, $term);
  127. return $translation_overview + $translation_term_form;
  128. }