tmgmt.api.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Translation Management module.
  5. */
  6. /**
  7. * @addtogroup tmgmt_source
  8. * @{
  9. */
  10. /**
  11. * Provide information about source plugins.
  12. *
  13. * @see TMGMTTestSourcePluginController
  14. */
  15. function hook_tmgmt_source_plugin_info() {
  16. return array(
  17. 'test_source' => array(
  18. 'label' => t('Test source'),
  19. 'description' => t('Simple source for testing purposes.'),
  20. 'controller class' => 'TMGMTTestSourcePluginController',
  21. ),
  22. );
  23. }
  24. /**
  25. * Alter source plugins information.
  26. *
  27. * @param $info
  28. * The defined source plugin information.
  29. *
  30. * @see hook_tmgmt_source_plugin_info()
  31. */
  32. function hook_tmgmt_source_plugin_info_alter(&$info) {
  33. $info['test_source']['description'] = t('Updated description');
  34. }
  35. /**
  36. * Return a list of suggested sources for job items.
  37. *
  38. * @param array $items
  39. * An array with TMGMTJobItem objects which must be checked for suggested
  40. * translations.
  41. * - TMGMTJobItem A JobItem to check for suggestions.
  42. * - ...
  43. * @param TMGMTJob $job
  44. * The current translation job to check for additional translation items.
  45. *
  46. * @return array
  47. * An array with all additional translation suggestions.
  48. * - job_item: A TMGMTJobItem instance.
  49. * - referenced: A string which indicates where this suggestion comes from.
  50. * - from_job: The main TMGMTJob-ID which suggests this translation.
  51. */
  52. function hook_tmgmt_source_suggestions(array $items, TMGMTJob $job) {
  53. return array(
  54. array(
  55. 'job_item' => tmgmt_job_item_create('entity', 'node', 0),
  56. 'reason' => t('Referenced @type of field @label', array('@type' => 'entity', '@label' => 'label')),
  57. 'from_item' => $items[1]->tjiid,
  58. )
  59. );
  60. }
  61. /**
  62. * @} End of "addtogroup tmgmt_source".
  63. */
  64. /**
  65. * @addtogroup tmgmt_translator
  66. * @{
  67. */
  68. /**
  69. * Provide information about translator plugins.
  70. *
  71. * @see TMGMTTestTranslatorPluginController
  72. */
  73. function hook_tmgmt_translator_plugin_info() {
  74. return array(
  75. 'test_translator' => array(
  76. 'label' => t('Test translator'),
  77. 'description' => t('Simple translator for testing purposes.'),
  78. 'plugin controller class' => 'TMGMTTestTranslatorPluginController',
  79. 'ui controller class' => 'TMGMTTestTranslatorUIController',
  80. 'default settings' => array(
  81. 'expose_settings' => TRUE,
  82. ),
  83. // By default, a translator is automatically created with the default
  84. // settings. Set auto create to FALSE to prevent this.
  85. 'auto create' => TRUE,
  86. // If the translator should provide remote languages mappings feature.
  87. // It defaults to TRUE.
  88. 'map remote languages' => FALSE,
  89. // Flag defining if job settings are handled by plugin itself.
  90. // Defaults to FALSE.
  91. 'job settings custom handling' => FALSE,
  92. ),
  93. );
  94. }
  95. /**
  96. * Alter information about translator plugins.
  97. */
  98. function hook_tmgmt_translator_plugin_info_alter(&$info) {
  99. $info['test_source']['description'] = t('Updated description');
  100. }
  101. /**
  102. * @} End of "addtogroup tmgmt_translator".
  103. */
  104. /**
  105. * @defgroup tmgmt_job Translation Jobs
  106. *
  107. * A single task to translate something into a given language using a @link
  108. * translator translator @endlink.
  109. *
  110. * Attached to these jobs are job items, which specify which @link source
  111. * sources @endlink are to be translated.
  112. *
  113. * To create a new translation job, first create a job and then assign items to
  114. * each. Each item needs to specify the source plugin that should be used
  115. * and the type and id, which the source plugin then uses to identify it later
  116. * on.
  117. *
  118. * @code
  119. * $job = tmgmt_job_create('en', $target_language);
  120. *
  121. * for ($i = 1; $i < 3; $i++) {
  122. * $job->addItem('test_source', 'test', $i);
  123. * }
  124. * @endcode
  125. *
  126. * Once a job has been created, it can be assigned to a translator plugin, which
  127. * is the service that is going to do the translation.
  128. *
  129. * @code
  130. * $job->translator = 'test_translator';
  131. * // Translator specific settings.
  132. * $job->settings = array(
  133. * 'priority' => 5,
  134. * );
  135. * $job->save();
  136. *
  137. * // Get the translator plugin and request a translation.
  138. * if ($job->isTranslatable()) {
  139. * $job->requestTranslation();
  140. * }
  141. * @endcode
  142. *
  143. * The translation plugin will then request the text from the source plugin.
  144. * Depending on the plugin, the text might be sent to an external service
  145. * or assign it to a local user or team of users. At some point, a translation
  146. * will be returned and saved in the job items.
  147. *
  148. * The translation can now be reviewed, accepted and the source plugins be told
  149. * to save the translation.
  150. *
  151. * @code
  152. * $job->accepted('Optional message');
  153. * @endcode
  154. */
  155. /**
  156. * @defgroup tmgmt_translator Translators
  157. *
  158. * A translator plugin integrates a translation service.
  159. *
  160. * To define a translator, hook_tmgmt_translator_plugin_info() needs to be
  161. * implemented and a controller class (specified in the info) created.
  162. *
  163. * A translator plugin is then responsible for sending out a translation job and
  164. * storing the translated texts back into the job and marking it as needs review
  165. * once it's finished.
  166. *
  167. * TBD.
  168. */
  169. /**
  170. * @defgroup tmgmt_source Translation source
  171. *
  172. * A source plugin represents translatable elements on a site.
  173. *
  174. * For example nodes, but also plain strings, menu items, other entities and so
  175. * on.
  176. *
  177. * To define a source, hook_tmgmt_source_plugin_info() needs to be implemented
  178. * and a controller class (specified in the info) created.
  179. *
  180. * A source has three separate tasks.
  181. *
  182. * - Allows to create a new @link job translation job @endlink and assign job
  183. * items to itself.
  184. * - Extract the translatable text into a nested array when
  185. * requested to do in their implementation of
  186. * TMGMTSourcePluginControllerInterface::getData().
  187. * - Save the accepted translations returned by the translation plugin in their
  188. * sources in their implementation of
  189. * TMGMTSourcePluginControllerInterface::saveTranslation().
  190. */
  191. /**
  192. * @defgroup tmgmt_remote_languages_mapping Remote languages mapping
  193. *
  194. * Logic to deal with different language codes at client and server that stand
  195. * for the same language.
  196. *
  197. * Each tmgmt plugin is expected to support this feature. However for those
  198. * plugins where such feature has no use there is a plugin setting
  199. * "map remote languages" which can be set to FALSE.
  200. *
  201. * @section mappings_info Mappings info
  202. *
  203. * There are several methods defined by
  204. * TMGMTTranslatorPluginControllerInterface and implemented in
  205. * TMGMTDefaultTranslatorPluginController that deal with mappings info.
  206. *
  207. * - getRemoteLanguagesMappings() - provides pairs of local_code => remote_code.
  208. * - mapToRemoteLanguage() & mapToLocalLanguage() - helpers to map local/remote.
  209. * Note that methods with same names and functionality are provided by the
  210. * TMGMTTranslator entity. These are convenience methods.
  211. *
  212. * The above methods should not need reimplementation unless special logic is
  213. * needed. However following methods provide only the fallback behaviour and
  214. * therefore it is recommended that each plugin provides its specific
  215. * implementation.
  216. *
  217. * - getDefaultRemoteLanguagesMappings() - we might know some mapping pairs
  218. * prior to configuring a plugin, this is the place where we can define these
  219. * mappings. The default implementation returns an empty array.
  220. * - getSupportedRemoteLanguages() - gets array of language codes in lang_code =>
  221. * lang_code format. It says with what languages the remote system can deal
  222. * with. These codes are in the remote format.
  223. *
  224. * @section mapping_remote_to_local Mapping remote to local
  225. *
  226. * Mapping remote to local language codes is done when determining the
  227. * language capabilities of the remote system. All following logic should then
  228. * solely work with local language codes. There are two methods defined by
  229. * the TMGMTTranslatorPluginControllerInterface interface. To do the mapping
  230. * a plugin must implement getSupportedTargetLanguages().
  231. *
  232. * - getSupportedTargetLanguages() - should return local language codes. So
  233. * within this method the mapping needs to be executed.
  234. * - getSupportedLanguagePairs() - gets language pairs for which translations
  235. * can be done. The language codes must be in local form. The default
  236. * implementation uses getSupportedTargetLanguages() so mapping occur. However
  237. * this approach is not effective and therefore each plugin should provide
  238. * its specific implementation with regard to performance.
  239. *
  240. * @section mapping_local_to_remote Mapping local to remote
  241. *
  242. * Mapping of local to remote language codes is done upon translation job
  243. * request in the TMGMTTranslatorPluginControllerInterface::requestTranslation()
  244. * plugin implementation.
  245. */
  246. /**
  247. * @defgroup tmgmt_ui_cart Translation cart
  248. *
  249. * The translation cart can collect multiple source items of different types
  250. * which are meant for translation into a list. The list then provides
  251. * functionality to request translation of the items into multiple target
  252. * languages.
  253. *
  254. * Each source can easily plug into the cart system utilising the
  255. * tmgmt_ui_add_cart_form() on either the source overview page as well as the
  256. * translate tab.
  257. */