You are here

public function Lingotek::getDocumentTranslationStatus in Lingotek Translation 8

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

Overrides LingotekInterface::getDocumentTranslationStatus

File

src/Lingotek.php, line 334
Contains \Drupal\lingotek\Lingotek.

Class

Lingotek

Namespace

Drupal\lingotek

Code

public function getDocumentTranslationStatus($doc_id, $locale) {

  // For now, a passthrough to the API object so the controllers do not
  // need to include that class.
  $response = $this->api
    ->getDocumentTranslationStatus($doc_id, $locale);
  $progress = 0;
  if ($response
    ->getStatusCode() == Response::HTTP_OK) {
    $progress_json = json_decode($response
      ->getBody(), TRUE);
    $lingotek_locale = str_replace("_", "-", $locale);
    if (!empty($progress_json['entities'])) {
      foreach ($progress_json['entities'] as $index => $data) {
        if ($data['properties']['locale_code'] === $lingotek_locale) {
          $progress = $data['properties']['percent_complete'];
          break;
        }
      }
    }
    if ($progress === self::PROGRESS_COMPLETE) {
      return TRUE;
    }
  }
  return FALSE;
}