tmgmt.plugin.interface.translator.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /**
  3. * @file
  4. * Contains the source plugin interface.
  5. */
  6. /**
  7. * Interface for service plugin controllers.
  8. *
  9. * @ingroup tmgmt_translator
  10. */
  11. interface TMGMTTranslatorPluginControllerInterface extends TMGMTPluginBaseInterface {
  12. /**
  13. * Checks whether a translator is available.
  14. *
  15. * @param TMGMTTranslator $translator
  16. * The translator entity.
  17. *
  18. * @return boolean
  19. * TRUE if the translator plugin is available, FALSE otherwise.
  20. */
  21. public function isAvailable(TMGMTTranslator $translator);
  22. /**
  23. * Return a reason why the translator is not available.
  24. *
  25. * @param TMGMTTranslator $translator
  26. * The translator entity.
  27. *
  28. * Might be called when isAvailable() returns FALSE to get a reason that
  29. * can be displayed to the user.
  30. *
  31. * @todo Remove this once http://drupal.org/node/1420364 is done.
  32. */
  33. public function getNotAvailableReason(TMGMTTranslator $translator);
  34. /**
  35. * Check whether this service can handle a particular translation job.
  36. *
  37. * @param TMGMTTranslator $translator
  38. * The TMGMTTranslator entity that should handle the translation.
  39. * @param TMGMTJob $job
  40. * The TMGMTJob entity that should be translated.
  41. *
  42. * @return boolean
  43. * TRUE if the job can be processed and translated, FALSE otherwise.
  44. */
  45. public function canTranslate(TMGMTTranslator $translator, TMGMTJob $job);
  46. /**
  47. * Return a reason why the translator is not able to translate this job.
  48. *
  49. * @param TMGMTJob $job
  50. * The job entity.
  51. *
  52. * Might be called when canTranslate() returns FALSE to get a reason that
  53. * can be displayed to the user.
  54. *
  55. * @todo Remove this once http://drupal.org/node/1420364 is done.
  56. */
  57. public function getNotCanTranslateReason(TMGMTJob $job);
  58. /**
  59. * Specifies default mappings for local to remote language codes.
  60. *
  61. * This method can be used in case we know in advance what language codes are
  62. * used by the remote translator and to which local language codes they
  63. * correspond.
  64. *
  65. * @return array
  66. * An array of local => remote language codes.
  67. *
  68. * @ingroup tmgmt_remote_languages_mapping
  69. */
  70. public function getDefaultRemoteLanguagesMappings();
  71. /**
  72. * Gets all supported languages of the translator.
  73. *
  74. * This list of all language codes used by the remote translator is then used
  75. * for example in the translator settings form to select which remote language
  76. * code correspond to which local language code.
  77. *
  78. * @param TMGMTTranslator $translator
  79. * Translator entity for which to get supported languages.
  80. *
  81. * @return array
  82. * An array of language codes which are provided by the translator
  83. * (remote language codes).
  84. *
  85. * @ingroup tmgmt_remote_languages_mapping
  86. */
  87. public function getSupportedRemoteLanguages(TMGMTTranslator $translator);
  88. /**
  89. * Gets existing remote languages mappings.
  90. *
  91. * This method is responsible to provide all local to remote language pairs.
  92. *
  93. * @param TMGMTTranslator $translator
  94. * Translator entity for which to get mappings.
  95. *
  96. * @return array
  97. * An array of local => remote language codes.
  98. *
  99. * @ingroup tmgmt_remote_languages_mapping
  100. */
  101. public function getRemoteLanguagesMappings(TMGMTTranslator $translator);
  102. /**
  103. * Maps local language to remote language.
  104. *
  105. * @param TMGMTTranslator $translator
  106. * Translator entity for which to get remote language.
  107. * @param $language
  108. * Local language code.
  109. *
  110. * @return string
  111. * Remote language code.
  112. *
  113. * @ingroup tmgmt_remote_languages_mapping
  114. */
  115. public function mapToRemoteLanguage(TMGMTTranslator $translator, $language);
  116. /**
  117. * Maps remote language to local language.
  118. *
  119. * @param TMGMTTranslator $translator
  120. * Translator entity for which to get local language.
  121. * @param $language
  122. * Remote language code.
  123. *
  124. * @return string
  125. * Local language code.
  126. *
  127. * @ingroup tmgmt_remote_languages_mapping
  128. */
  129. public function mapToLocalLanguage(TMGMTTranslator $translator, $language);
  130. /**
  131. * Returns all available target languages that are supported by this service
  132. * when given a source language.
  133. *
  134. * @param TMGMTTranslator $translator
  135. * The translator entity.
  136. * @param $source_language
  137. * The source language.
  138. *
  139. * @return array
  140. * An array of remote languages in ISO format.
  141. *
  142. * @ingroup tmgmt_remote_languages_mapping
  143. */
  144. public function getSupportedTargetLanguages(TMGMTTranslator $translator, $source_language);
  145. /**
  146. * Returns supported language pairs.
  147. *
  148. * This info may be used by other plugins to find out what language pairs
  149. * can handle the translator.
  150. *
  151. * @param TMGMTTranslator $translator
  152. * The translator entity.
  153. *
  154. * @return array
  155. * List of language pairs where a pair is an associative array of
  156. * source_language and target_language.
  157. * Example:
  158. * array(
  159. * array('source_language' => 'en-US', 'target_language' => 'de-DE'),
  160. * array('source_language' => 'en-US', 'target_language' => 'de-CH'),
  161. * )
  162. *
  163. * @ingroup tmgmt_remote_languages_mapping
  164. */
  165. public function getSupportedLanguagePairs(TMGMTTranslator $translator);
  166. /**
  167. * @abstract
  168. *
  169. * Submits the translation request and sends it to the translation provider.
  170. *
  171. * @param TMGMTJob $job
  172. * The job that should be submitted.
  173. *
  174. * @ingroup tmgmt_remote_languages_mapping
  175. */
  176. public function requestTranslation(TMGMTJob $job);
  177. /**
  178. * Aborts a translation job.
  179. *
  180. * @param TMGMTJob $job
  181. * The job that should have its translation aborted.
  182. *
  183. * @return boolean
  184. * TRUE if the job could be aborted, FALSE otherwise.
  185. */
  186. public function abortTranslation(TMGMTJob $job);
  187. /**
  188. * Defines default settings.
  189. *
  190. * @return array
  191. * An array of default settings.
  192. */
  193. public function defaultSettings();
  194. /**
  195. * Returns if the translator has any settings for the passed job.
  196. */
  197. public function hasCheckoutSettings(TMGMTJob $job);
  198. /**
  199. * Accept a single data item.
  200. *
  201. * @todo Using job item breaks the current convention which uses jobs.
  202. *
  203. * @param $job_item
  204. * The Job item the accepted data item belongs to.
  205. * @param $key
  206. * The key of the accepted data item.
  207. * The key is an array containing the keys of a nested array hierarchy path.
  208. *
  209. * @return
  210. * TRUE if the approving was succesfull, FALSE otherwise.
  211. * In case of an error, it is the responsibility of the translator to
  212. * provide informations about the failure by adding a message to the job
  213. * item.
  214. */
  215. public function acceptetDataItem(TMGMTJobItem $job_item, array $key);
  216. /**
  217. * Returns the escaped #text of a data item.
  218. *
  219. * @param array $data_item
  220. * A data item with a #text and optional #escape definitions.
  221. *
  222. * @return string
  223. * The text of the data item with translator-specific escape patterns
  224. * applied.
  225. */
  226. public function escapeText(array $data_item);
  227. /**
  228. * Removes escape patterns from an escaped text.
  229. *
  230. * @param string $text
  231. * The text from which escape patterns should be removed.
  232. *
  233. * @return string
  234. * The unescaped text.
  235. */
  236. public function unescapeText($text);
  237. }