You are here

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

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

Gets the status of the translations.

Parameters

string $doc_id: The document ID in Lingotek.

Return value

array Returns array keyed by the locale with the percentage of completion.

Overrides LingotekInterface::getDocumentTranslationStatuses

File

src/Lingotek.php, line 754

Class

Lingotek
The connecting class between Drupal and Lingotek

Namespace

Drupal\lingotek

Code

public function getDocumentTranslationStatuses($doc_id) {
  $statuses = [];
  try {
    $response = $this->api
      ->getDocumentTranslationStatuses($doc_id);
  } catch (LingotekApiException $e) {

    // No targets found for this doc
    return $statuses;
  }
  if ($response
    ->getStatusCode() == Response::HTTP_OK) {
    $progress_json = json_decode($response
      ->getBody(), TRUE);
    if (!empty($progress_json['entities'])) {
      foreach ($progress_json['entities'] as $index => $data) {
        $lingotek_locale = $data['properties']['locale_code'];
        $statuses[$lingotek_locale] = $data['properties']['percent_complete'];

        // ToDo: We should have an structure for this, instead of treating this as an snowflake.
        if ($data['properties']['status'] === Lingotek::STATUS_CANCELLED) {
          $statuses[$lingotek_locale] = $data['properties']['status'];
        }
      }
    }
  }
  return $statuses;
}