You are here

interface TranslatorPluginInterface in Translation Management Tool 8

Interface for service plugin controllers.

Hierarchy

Expanded class hierarchy of TranslatorPluginInterface

All classes that implement TranslatorPluginInterface

Related topics

File

src/TranslatorPluginInterface.php, line 12

Namespace

Drupal\tmgmt
View source
interface TranslatorPluginInterface extends PluginInspectionInterface {

  /**
   * Checks whether a translator is available.
   *
   * @param TranslatorInterface $translator
   *   The translator entity.
   *
   * @return \Drupal\tmgmt\Translator\AvailableResult
   *   The result of the availability check.
   */
  public function checkAvailable(TranslatorInterface $translator);

  /**
   * Check whether this service can handle a particular translation job.
   *
   * @param TranslatorInterface $translator
   *   The Translator entity that should handle the translation.
   * @param \Drupal\tmgmt\JobInterface $job
   *   The Job entity that should be translated.
   *
   * @return \Drupal\tmgmt\Translator\TranslatableResult
   *   The result of the translatable check.
   */
  public function checkTranslatable(TranslatorInterface $translator, JobInterface $job);

  /**
   * Specifies default mappings for local to remote language codes.
   *
   * This method can be used in case we know in advance what language codes are
   * used by the remote translator and to which local language codes they
   * correspond.
   *
   * @return array
   *   An array of local => remote language codes.
   *
   * @ingroup tmgmt_remote_languages_mapping
   */
  public function getDefaultRemoteLanguagesMappings();

  /**
   * Gets all supported languages of the translator.
   *
   * This list of all language codes used by the remote translator is then used
   * for example in the translator settings form to select which remote language
   * code correspond to which local language code.
   *
   * @param TranslatorInterface $translator
   *   Translator entity for which to get supported languages.
   *
   * @return array
   *   An array of language codes which are provided by the translator
   *   (remote language codes).
   *
   * @ingroup tmgmt_remote_languages_mapping
   */
  public function getSupportedRemoteLanguages(TranslatorInterface $translator);

  /**
   * Returns all available target languages that are supported by this service
   * when given a source language.
   *
   * @param TranslatorInterface $translator
   *   The translator entity.
   * @param $source_language
   *   The source language.
   *
   * @return array
   *   An array of remote languages in ISO format.
   *
   * @ingroup tmgmt_remote_languages_mapping
   */
  public function getSupportedTargetLanguages(TranslatorInterface $translator, $source_language);

  /**
   * Returns supported language pairs.
   *
   * This info may be used by other plugins to find out what language pairs
   * can handle the translator.
   *
   * @param \Drupal\tmgmt\TranslatorInterface $translator
   *   The translator entity.
   *
   * @return array
   *   List of language pairs where a pair is an associative array of
   *   source_language and target_language.
   *   Example:
   *   array(
   *     array('source_language' => 'en-US', 'target_language' => 'de-DE'),
   *     array('source_language' => 'en-US', 'target_language' => 'de-CH'),
   *   )
   *
   * @ingroup tmgmt_remote_languages_mapping
   */
  public function getSupportedLanguagePairs(TranslatorInterface $translator);

  /**
   * @abstract
   *
   * Submits the translation request and sends it to the translation provider.
   *
   * During the translation process, Job::getItems() will only return job items
   * that are not already fully translated.
   *
   * @param \Drupal\tmgmt\JobInterface $job
   *   The job that should be submitted.
   *
   * @see hook_tmgmt_job_before_request_translation()
   * @see hook_tmgmt_job_after_request_translation()
   *
   * @ingroup tmgmt_remote_languages_mapping
   */
  public function requestTranslation(JobInterface $job);

  /**
   * Aborts a translation job.
   *
   * @param \Drupal\tmgmt\JobInterface $job
   *   The job that should have its translation aborted.
   *
   * @return bool
   *   TRUE if the job could be aborted, FALSE otherwise.
   */
  public function abortTranslation(JobInterface $job);

  /**
   * Defines default settings.
   *
   * @return array
   *   An array of default settings.
   */
  public function defaultSettings();

  /**
   * Returns if the translator has any settings for the passed job.
   */
  public function hasCheckoutSettings(JobInterface $job);

  /**
   * Accept a single data item.
   *
   * @todo Using job item breaks the current convention which uses jobs.
   *
   * @param $job_item
   *   The Job item the accepted data item belongs to.
   * @param $key
   *   The key of the accepted data item.
   *   The key is an array containing the keys of a nested array hierarchy path.
   *
   * @return
   *   TRUE if the approving was succesfull, FALSE otherwise.
   *   In case of an error, it is the responsibility of the translator to
   *   provide informations about the failure by adding a message to the job
   *   item.
   */
  public function acceptedDataItem(JobItemInterface $job_item, array $key);

  /**
   * Returns the escaped #text of a data item.
   *
   * @param array $data_item
   *   A data item with a #text and optional #escape definitions.
   *
   * @return string
   *   The text of the data item with translator-specific escape patterns
   *   applied.
   */
  public function escapeText(array $data_item);

  /**
   * Removes escape patterns from an escaped text.
   *
   * @param string $text
   *   The text from which escape patterns should be removed.
   *
   * @return string
   *   The unescaped text.
   */
  public function unescapeText($text);

}

Members

Namesort descending Modifiers Type Description Overrides
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2
TranslatorPluginInterface::abortTranslation public function Aborts a translation job. 1
TranslatorPluginInterface::acceptedDataItem public function Accept a single data item. 1
TranslatorPluginInterface::checkAvailable public function Checks whether a translator is available. 1
TranslatorPluginInterface::checkTranslatable public function Check whether this service can handle a particular translation job. 1
TranslatorPluginInterface::defaultSettings public function Defines default settings. 1
TranslatorPluginInterface::escapeText public function Returns the escaped #text of a data item. 1
TranslatorPluginInterface::getDefaultRemoteLanguagesMappings public function Specifies default mappings for local to remote language codes. 1
TranslatorPluginInterface::getSupportedLanguagePairs public function Returns supported language pairs. 1
TranslatorPluginInterface::getSupportedRemoteLanguages public function Gets all supported languages of the translator. 1
TranslatorPluginInterface::getSupportedTargetLanguages public function Returns all available target languages that are supported by this service when given a source language. 1
TranslatorPluginInterface::hasCheckoutSettings public function Returns if the translator has any settings for the passed job. 1
TranslatorPluginInterface::requestTranslation public function @abstract 3
TranslatorPluginInterface::unescapeText public function Removes escape patterns from an escaped text. 1