You are here

function lingotek_get_language_details in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lingotek.dashboard.inc \lingotek_get_language_details()
  2. 7.6 lingotek.dashboard.inc \lingotek_get_language_details()

Get the details of each language

1 call to lingotek_get_language_details()
lingotek_dashboard_command_ajax in ./lingotek.dashboard.inc
Ajax Command Processing for the Lingotek dashboard.

File

./lingotek.dashboard.inc, line 197
Lingotek Dashboard.

Code

function lingotek_get_language_details($lingotek_locale_requested = NULL) {
  $response = array();
  $available_languages = Lingotek::getLanguages(NULL, TRUE);
  $source_total = 0;
  $target_total = 0;
  $source_totals = array();
  $target_totals = array();

  // If we get a parameter, only return that language. Otherwise return all languages.
  foreach ($available_languages as $l) {
    if (!is_null($lingotek_locale_requested) && $lingotek_locale_requested != $l->lingotek_locale) {
      continue;
    }
    $drupal_language_code = $l->language;
    $lingotek_locale = $l->lingotek_locale;
    $source_counts = LingotekSync::getSourceCounts($lingotek_locale);
    $source_count = $source_counts['total'];

    //unset($source_counts['total']);
    $target_statuses_to_include = array(
      LingotekSync::STATUS_CURRENT,
    );
    $target_counts = LingotekSync::getCountsByStatus($target_statuses_to_include, $lingotek_locale);
    $target_count = $target_counts['total'];
    $target_status = array(
      'locale' => $lingotek_locale,
      // Return this language code as the Lingotek language code.
      'dcode' => $drupal_language_code,
      'active' => intval($l->lingotek_enabled),
      //lingotek_enabled,
      'enabled' => intval($l->enabled),
      // drupal enabled
      'source' => $source_counts,
      'target' => $target_counts,
    );
    if ($lingotek_locale_requested == $l->lingotek_locale) {
      $response = $target_status;
    }
    else {
      $response[$lingotek_locale] = $target_status;
    }
    $source_total += $source_count;
    $target_total += $target_count;
    $source_totals = LingotekSync::arraySumValues($source_totals, $source_counts['types']);
    $target_totals = LingotekSync::arraySumValues($target_totals, $target_counts['types']);
  }
  if (is_null($lingotek_locale_requested)) {
    $response = array(
      'languages' => $response,
      'source' => array(
        'types' => $source_totals,
        'total' => $source_total,
      ),
      'target' => array(
        'types' => $target_totals,
        'total' => $target_total,
      ),
      'count' => count($available_languages),
    );
  }
  return $response;
}