You are here

public function Lingotek::downloadDocument in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8 src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  2. 8.2 src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  3. 4.0.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  4. 3.0.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  5. 3.1.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  6. 3.2.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  7. 3.3.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  8. 3.5.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  9. 3.6.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  10. 3.7.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()
  11. 3.8.x src/Lingotek.php \Drupal\lingotek\Lingotek::downloadDocument()

Gets the translation of a document for a given locale.

Parameters

string $doc_id: The document ID in Lingotek.

$locale: The locale we want to know the translation status.

Return value

array Returns array with the content of the document.

Overrides LingotekInterface::downloadDocument

File

src/Lingotek.php, line 782

Class

Lingotek
The connecting class between Drupal and Lingotek

Namespace

Drupal\lingotek

Code

public function downloadDocument($doc_id, $locale) {

  // For now, a passthrough to the API object so the controllers do not
  // need to include that class.
  $response = $this->api
    ->getTranslation($doc_id, $locale, $this->configFactory
    ->get(static::SETTINGS)
    ->get('preference.enable_download_source'));
  $statusCode = $response
    ->getStatusCode();
  if ($statusCode == Response::HTTP_OK) {
    return json_decode($response
      ->getBody(), TRUE);
  }
  elseif ($statusCode == Response::HTTP_GONE) {

    // Set the status of the document back to its pre-uploaded state.
    // Typically this means the state would be set to Upload, or None but this
    // may vary depending on connector. Essentially, the content’s status
    // indicator should show that the source content needs to be re-uploaded
    // to Lingotek.
    return FALSE;
  }
  return FALSE;
}