translation_table.module 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * @file
  4. * Translation table module
  5. *
  6. * UI for quick translation of user submitted strings.
  7. * The i18n module allows the translation of different dynamic strings, but the
  8. * process is tedious.
  9. *
  10. * This module presents your taxonomy terms, menu items and other text groups in
  11. * a table, and each language has a corresponding column. Just fill out the
  12. * translations and click Save.
  13. */
  14. /**
  15. * Implementation of hook_menu().
  16. */
  17. function translation_table_menu() {
  18. $items = array();
  19. // Get the different translation tables.
  20. foreach (module_list() as $module) {
  21. translation_table_module_include("$module.translation_table.inc");
  22. }
  23. $module_items = module_invoke_all('translation_table_data');
  24. foreach ($module_items as $key => $module_item) {
  25. if (isset($module_item['form']) && isset($module_item['file'])) {
  26. $items['admin/config/regional/translate/table/'. $key] = array(
  27. 'title' => isset($module_item['title']) ? $module_item['title'] : 'Unknown',
  28. 'description' => isset($module_item['description']) ? $module_item['description'] : '*',
  29. 'page callback' => 'translation_table_get_form',
  30. 'page arguments' => array($module_item['form']),
  31. 'access callback' => 'user_access',
  32. 'access arguments' => array('translate interface'),
  33. 'type' => MENU_LOCAL_TASK,
  34. 'file' => $module_item['file'],
  35. 'file path' => isset($module_item['file path']) ? $module_item['file path'] : NULL,
  36. );
  37. }
  38. }
  39. if (!empty($items)) {
  40. // Modify the fist item to local task.
  41. $first_key = key($items);
  42. $items[$first_key]['weight'] = -10;
  43. $items[$first_key]['type'] = MENU_DEFAULT_LOCAL_TASK;
  44. $items['admin/config/regional/translate/table'] = array(
  45. 'title' => 'Translation table',
  46. 'description' => 'Edit translations',
  47. 'page callback' => 'translation_table_get_form',
  48. 'page arguments' => $items[$first_key]['page arguments'],
  49. 'access callback' => 'user_access',
  50. 'access arguments' => array('translate interface'),
  51. 'type' => MENU_LOCAL_TASK,
  52. 'file' => $items[$first_key]['file'],
  53. );
  54. }
  55. return $items;
  56. }
  57. /**
  58. * Menu callback;
  59. */
  60. function translation_table_get_form($form_id) {
  61. module_load_include('inc', 'translation_table', 'includes/admin');
  62. return drupal_get_form($form_id);
  63. }
  64. /**
  65. * Implementation of hook_theme().
  66. */
  67. function translation_table_theme() {
  68. return array(
  69. 'translation_table' => array(
  70. 'render element' => 'form',
  71. 'file' => 'includes/theme.inc',
  72. ),
  73. 'translation_table_filter' => array(
  74. 'render element' => 'form',
  75. 'file' => 'includes/theme.inc',
  76. ),
  77. );
  78. }
  79. /**
  80. * Load translation table files on behalf of modules.
  81. */
  82. function translation_table_module_include($file) {
  83. foreach (translation_table_get_module_apis() as $module => $info) {
  84. if (file_exists(DRUPAL_ROOT . "/$info[path]/$file")) {
  85. require_once DRUPAL_ROOT . "/$info[path]/$file";
  86. }
  87. }
  88. }
  89. /**
  90. * Get a list of modules that support the current translation_table API.
  91. */
  92. function translation_table_get_module_apis() {
  93. static $cache = NULL;
  94. if (!isset($cache)) {
  95. $cache = array();
  96. foreach (module_implements('translation_table_api') as $module) {
  97. $function = $module .'_translation_table_api';
  98. $info = $function();
  99. if (isset($info['api']) && $info['api'] == 1.000) {
  100. if (!isset($info['path'])) {
  101. $info['path'] = drupal_get_path('module', $module);
  102. }
  103. $cache[$module] = $info;
  104. }
  105. }
  106. }
  107. return $cache;
  108. }
  109. /**
  110. * Implementation of hook_translation_table_api().
  111. */
  112. function translation_table_translation_table_api() {
  113. return array(
  114. 'api' => 1,
  115. 'path' => drupal_get_path('module', 'translation_table') .'/modules',
  116. );
  117. }