You are here

public function LingotekFake::getDocumentTranslationStatus in Lingotek Translation 3.3.x

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

Gets the status of the translation.

Parameters

string $doc_id: The document ID in Lingotek.

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

Return value

bool|int Returns TRUE if the document translation is completed. FALSE if it was not requested. The percentage if it's still in progress.

Overrides LingotekInterface::getDocumentTranslationStatus

File

tests/modules/lingotek_test/src/LingotekFake.php, line 277

Class

LingotekFake

Namespace

Drupal\lingotek_test

Code

public function getDocumentTranslationStatus($doc_id, $locale) {
  if (\Drupal::state()
    ->get('lingotek.must_error_in_check_target_status', FALSE)) {
    throw new LingotekApiException('Error was forced.');
  }
  \Drupal::state()
    ->set('lingotek.checked_target_locale', $locale);

  // Return true if translation is done.
  if (\Drupal::state()
    ->get('lingotek.document_completion', NULL) === NULL) {
    $result = TRUE;
    $requested_locales = \Drupal::state()
      ->get('lingotek.requested_locales', []);
    if (!isset($requested_locales[$doc_id]) || !in_array($locale, $requested_locales[$doc_id])) {
      $result = FALSE;
    }
    $cancelled_locales = \Drupal::state()
      ->get('lingotek.cancelled_locales', []);
    if (isset($cancelled_locales[$doc_id]) && in_array($locale, $cancelled_locales[$doc_id])) {
      $result = 'CANCELLED';
    }
    return $result;
  }
  return \Drupal::state()
    ->get('lingotek.document_completion', TRUE);
}