You are here

function tmgmt_translator_labels_flagged in Translation Management Tool 8

Same name and namespace in other branches
  1. 7 tmgmt.module \tmgmt_translator_labels_flagged()

Returns a list of flagged translator labels.

If a translator is not available it will be suffixed with a short text explaining why it is not available. This can either be because the configuration of the passed job is not supported or because the translator service can't be reached.

Parameters

\Drupal\tmgmt\JobInterface $job: (Optional) A translation job.

Return value

array An array of flagged translator labels.

Related topics

1 call to tmgmt_translator_labels_flagged()
JobForm::form in src/Form/JobForm.php
Gets the actual form array to be built.

File

./tmgmt.module, line 519
Main module file for the Translation Management module.

Code

function tmgmt_translator_labels_flagged(JobInterface $job = NULL) {
  $labels = array();
  $translators = Translator::loadMultiple();
  uasort($translators, array(
    'Drupal\\Core\\Config\\Entity\\ConfigEntityBase',
    'sort',
  ));

  /** @var \Drupal\tmgmt\Entity\Translator $translator */
  foreach ($translators as $translator) {
    if (isset($job) && $job
      ->isContinuous() && !$translator
      ->getPlugin() instanceof ContinuousTranslatorInterface) {
      continue;
    }
    if (!$translator
      ->checkAvailable()
      ->getSuccess()) {
      $labels[$translator
        ->id()] = t('@label (not available)', array(
        '@label' => $translator
          ->label(),
      ));
    }
    elseif (isset($job) && !$translator
      ->checkTranslatable($job)
      ->getSuccess()) {
      $labels[$translator
        ->id()] = t('@label (unsupported)', array(
        '@label' => $translator
          ->label(),
      ));
    }
    else {
      $labels[$translator
        ->id()] = $translator
        ->label();
    }
  }
  return $labels;
}