You are here

public function LingotekApi::addTranslationTarget in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addTranslationTarget()
  2. 7.2 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addTranslationTarget()
  3. 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addTranslationTarget()
  4. 7.4 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addTranslationTarget()
  5. 7.6 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addTranslationTarget()

Adds a target language to an existing Lingotek Document or Project.

Parameters

int $lingotek_document_id: The document to which the new translation target should be added. Or null if the target will be added to the project.

int $lingotek_project_id: The project to which the new translation target should be added. Or null if the target will be added to a document instead.

string $lingotek_locale: The two letter code representing the language which should be added as a translation target.

string $workflow_id: The optional workflow to associate with this target. If omitted, the project's default workflow will be applied.

Return value

mixed The ID of the new translation target in the Lingotek system, or FALSE on error.

File

lib/Drupal/lingotek/LingotekApi.php, line 198
Defines Drupal\lingotek\LingotekApi

Class

LingotekApi
@file Defines Drupal\lingotek\LingotekApi

Code

public function addTranslationTarget($lingotek_document_id, $lingotek_project_id, $lingotek_locale, $workflow_id = '') {
  global $_lingotek_client, $_lingotek_locale;
  $parameters = array(
    'applyWorkflow' => 'true',
    // Ensure that as translation targets are added, the associated project's Workflow template is applied.
    'targetLanguage' => $lingotek_locale,
  );
  if (isset($lingotek_document_id) && !isset($lingotek_project_id)) {
    $parameters['documentId'] = $lingotek_document_id;
  }
  elseif (isset($lingotek_project_id) && !isset($lingotek_document_id)) {
    $parameters['projectId'] = $lingotek_project_id;
  }
  if ($workflow_id) {
    $parameters['workflowId'] = $workflow_id;
  }
  if ($new_translation_target = $this
    ->request('addTranslationTarget', $parameters)) {

    // If the request went through, there was no OAuth error and we should enable.
    return TRUE;
  }
  return FALSE;
}