You are here

class TMGMTTestTranslatorPluginController in Translation Management Tool 7

@file Cotains the test translator plugin.

Hierarchy

Expanded class hierarchy of TMGMTTestTranslatorPluginController

2 string references to 'TMGMTTestTranslatorPluginController'
hook_tmgmt_translator_plugin_info in ./tmgmt.api.php
Provide information about translator plugins.
tmgmt_test_tmgmt_translator_plugin_info in tests/tmgmt_test.module
Implements hook_tmgmt_translator_plugin_info().

File

tests/tmgmt_test.plugin.translator.inc, line 8
Cotains the test translator plugin.

View source
class TMGMTTestTranslatorPluginController extends TMGMTDefaultTranslatorPluginController implements TMGMTTranslatorRejectDataItem {

  /**
   * {@inheritdoc}
   */
  protected $escapeStart = '[[[';

  /**
   * {@inheritdoc}
   */
  protected $escapeEnd = ']]]';

  /**
   * {@inheritdoc}
   */
  public function getDefaultRemoteLanguagesMappings() {
    return array(
      'en' => 'en-us',
      'de' => 'de-ch',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function hasCheckoutSettings(TMGMTJob $job) {
    return $job
      ->getTranslator()
      ->getSetting('expose_settings');
  }

  /**
   * {@inheritdoc}
   */
  function requestTranslation(TMGMTJob $job) {

    // Add a debug message.
    $job
      ->addMessage('Test translator called.', array(), 'debug');

    // Do something different based on the action, if defined.
    $action = isset($job->settings['action']) ? $job->settings['action'] : '';
    switch ($action) {
      case 'submit':
        $job
          ->submitted('Test submit.');
        break;
      case 'reject':
        $job
          ->rejected('This is not supported.');
        break;
      case 'fail':

        // Target not reachable.
        $job
          ->addMessage('Service not reachable.', array(), 'error');
        break;
      case 'translate':
      default:

        // The dummy translation prefixes strings with the target language.
        $data = array_filter(tmgmt_flatten_data($job
          ->getData()), '_tmgmt_filter_data');
        $tdata = array();
        foreach ($data as $key => $value) {
          $tdata[$key]['#text'] = $job->target_language . '_' . $value['#text'];
        }
        $job
          ->submitted('Test translation created.');
        $job
          ->addTranslatedData(tmgmt_unflatten_data($tdata));
        break;
    }
  }

  /**
   * {@inheritdoc}
   */
  function canTranslate(TMGMTTranslator $translator, TMGMTJob $job) {
    if (isset($job->settings['action']) && $job->settings['action'] == 'not_translatable') {
      return FALSE;
    }
    return parent::canTranslate($translator, $job);
  }

  /**
   * {@inheritdoc}
   */
  public function getSupportedTargetLanguages(TMGMTTranslator $translator, $source_language) {
    $languages = drupal_map_assoc(array(
      'en',
      'de',
      'es',
      'it',
      'zh-hans',
      'gsw-berne',
    ));
    unset($languages[$source_language]);
    return $languages;
  }

  /**
   * {@inheritdoc}
   */
  public function rejectDataItem(TMGMTJobItem $job_item, array $key, array $values = NULL) {
    $key = '[' . implode('][', $key) . ']';
    $job_item
      ->addMessage('Rejected data item @key for job item @item in job @job.', array(
      '@key' => $key,
      '@item' => $job_item->tjiid,
      '@job' => $job_item->tjid,
    ));
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function rejectForm($form, &$form_state) {
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TMGMTDefaultTranslatorPluginController::$remoteLanguagesMappings protected property
TMGMTDefaultTranslatorPluginController::$supportedRemoteLanguages protected property
TMGMTDefaultTranslatorPluginController::abortTranslation public function Aborts a translation job. Overrides TMGMTTranslatorPluginControllerInterface::abortTranslation
TMGMTDefaultTranslatorPluginController::acceptetDataItem public function Accept a single data item. Overrides TMGMTTranslatorPluginControllerInterface::acceptetDataItem
TMGMTDefaultTranslatorPluginController::defaultSettings public function Defines default settings. Overrides TMGMTTranslatorPluginControllerInterface::defaultSettings 1
TMGMTDefaultTranslatorPluginController::escapeText public function Returns the escaped #text of a data item. Overrides TMGMTTranslatorPluginControllerInterface::escapeText
TMGMTDefaultTranslatorPluginController::getEscapedString protected function Returns the escaped string.
TMGMTDefaultTranslatorPluginController::getNotAvailableReason public function Return a reason why the translator is not available. Overrides TMGMTTranslatorPluginControllerInterface::getNotAvailableReason
TMGMTDefaultTranslatorPluginController::getNotCanTranslateReason public function Return a reason why the translator is not able to translate this job. Overrides TMGMTTranslatorPluginControllerInterface::getNotCanTranslateReason
TMGMTDefaultTranslatorPluginController::getRemoteLanguagesMappings public function Gets existing remote languages mappings. Overrides TMGMTTranslatorPluginControllerInterface::getRemoteLanguagesMappings
TMGMTDefaultTranslatorPluginController::getSupportedLanguagePairs public function Default implementation that gets target languages for each remote language. This approach is ineffective and therefore it is advised that a plugin should provide own implementation. Overrides TMGMTTranslatorPluginControllerInterface::getSupportedLanguagePairs 1
TMGMTDefaultTranslatorPluginController::getSupportedRemoteLanguages public function Gets all supported languages of the translator. Overrides TMGMTTranslatorPluginControllerInterface::getSupportedRemoteLanguages
TMGMTDefaultTranslatorPluginController::isAvailable public function Checks whether a translator is available. Overrides TMGMTTranslatorPluginControllerInterface::isAvailable
TMGMTDefaultTranslatorPluginController::mapToLocalLanguage public function Maps remote language to local language. Overrides TMGMTTranslatorPluginControllerInterface::mapToLocalLanguage
TMGMTDefaultTranslatorPluginController::mapToRemoteLanguage public function Maps local language to remote language. Overrides TMGMTTranslatorPluginControllerInterface::mapToRemoteLanguage
TMGMTDefaultTranslatorPluginController::unescapeText public function Removes escape patterns from an escaped text. Overrides TMGMTTranslatorPluginControllerInterface::unescapeText
TMGMTPluginBase::$pluginInfo protected property
TMGMTPluginBase::$pluginType protected property
TMGMTPluginBase::pluginInfo public function Returns the info of the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginInfo
TMGMTPluginBase::pluginType public function Returns the type of the plugin. Overrides TMGMTPluginBaseInterface::pluginType
TMGMTPluginBase::__construct public function Constructor. Overrides TMGMTPluginBaseInterface::__construct
TMGMTTestTranslatorPluginController::$escapeEnd protected property Characters that indicate the end of an escaped string. Overrides TMGMTDefaultTranslatorPluginController::$escapeEnd
TMGMTTestTranslatorPluginController::$escapeStart protected property Characters that indicate the beginning of an escaped string. Overrides TMGMTDefaultTranslatorPluginController::$escapeStart
TMGMTTestTranslatorPluginController::canTranslate function Check whether this service can handle a particular translation job. Overrides TMGMTDefaultTranslatorPluginController::canTranslate
TMGMTTestTranslatorPluginController::getDefaultRemoteLanguagesMappings public function Specifies default mappings for local to remote language codes. Overrides TMGMTDefaultTranslatorPluginController::getDefaultRemoteLanguagesMappings
TMGMTTestTranslatorPluginController::getSupportedTargetLanguages public function Returns all available target languages that are supported by this service when given a source language. Overrides TMGMTDefaultTranslatorPluginController::getSupportedTargetLanguages
TMGMTTestTranslatorPluginController::hasCheckoutSettings public function Returns if the translator has any settings for the passed job. Overrides TMGMTDefaultTranslatorPluginController::hasCheckoutSettings
TMGMTTestTranslatorPluginController::rejectDataItem public function Reject one single data item. Overrides TMGMTTranslatorRejectDataItem::rejectDataItem
TMGMTTestTranslatorPluginController::rejectForm public function Reject form. Overrides TMGMTTranslatorRejectDataItem::rejectForm
TMGMTTestTranslatorPluginController::requestTranslation function @abstract Overrides TMGMTTranslatorPluginControllerInterface::requestTranslation