You are here

private function LingotekDashboardController::getLanguageDetails in Lingotek Translation 4.0.x

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

File

src/Controller/LingotekDashboardController.php, line 237

Class

LingotekDashboardController
Returns responses for lingotek module setup routes.

Namespace

Drupal\lingotek\Controller

Code

private function getLanguageDetails($lingotek_locale_requested = NULL) {
  $response = [];
  $available_languages = $this->languageManager
    ->getLanguages();
  $source_total = 0;
  $target_total = 0;
  $source_totals = [];
  $target_totals = [];

  // If we get a parameter, only return that language. Otherwise return all languages.
  foreach ($available_languages as $language) {

    // We check if we have a saved lingotek locale.
    // If not, we default to the id conversion.
    // Language manager returns Language objects, not ConfigurableLanguage,
    // because the language manager is initiated before the config system, and
    // loads the configuration bypassing it.
    $lingotek_locale = $this->languageLocaleMapper
      ->getLocaleForLangcode($language
      ->getId());
    if (!is_null($lingotek_locale_requested) && $lingotek_locale_requested != $lingotek_locale) {
      continue;
    }
    $language_report = $this
      ->getLanguageReport($language);
    if ($lingotek_locale_requested === $lingotek_locale) {
      $response = $language_report;
    }
    else {
      if (!empty($lingotek_locale)) {
        $response[$lingotek_locale] = $language_report;
      }
      else {

        // There are some edge cases where there is no locale.
        // We default to the only known code, which is only the langcode.
        $response[$language
          ->getId()] = $language_report;
      }
    }
    $source_total += $language_report['source']['total'];
    $target_total += $language_report['target']['total'];
    $source_totals = self::calcLanguageTotals($source_totals, $language_report['source']['types']);
    $target_totals = self::calcLanguageTotals($target_totals, $language_report['target']['types']);
  }
  if (is_null($lingotek_locale_requested)) {
    $response = [
      'languages' => $response,
      'source' => [
        'types' => $source_totals,
        'total' => $source_total,
      ],
      'target' => [
        'types' => $target_totals,
        'total' => $target_total,
      ],
      'count' => count($available_languages),
    ];
  }
  return $response;
}