1 locale.module locale_form_language_admin_overview_form_alter(&$form, &$form_state)

Implements hook_form_FORM_ID_alter() for language_admin_overview_form().

File

core/modules/locale/locale.module, line 936
Add language handling functionality and enables the translation of the user interface to languages other than English.

Code

function locale_form_language_admin_overview_form_alter(&$form, &$form_state) {
  $languages = $form['languages']['#languages'];

  $total_strings = db_query("SELECT COUNT(*) FROM {locales_source}")->fetchField();
  $stats = array_fill_keys(array_keys($languages), array());

  // If we have source strings, count translations and calculate progress.
  if (!empty($total_strings)) {
    $translations = db_query("SELECT COUNT(*) AS translated, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY language");
    foreach ($translations as $data) {
      $stats[$data->language]['translated'] = $data->translated;
      if ($data->translated > 0) {
        $stats[$data->language]['ratio'] = round($data->translated / $total_strings * 100, 2);
      }
    }
  }

  array_splice($form['languages']['#header'], -1, 0, t('Interface translation'));

  foreach ($languages as $langcode => $language) {
    $stats[$langcode] += array(
      'translated' => 0,
      'ratio' => 0,
    );
    if ($langcode != 'en' || locale_translate_english()) {
      $form['languages'][$langcode]['locale_statistics'] = array(
        '#type' => 'link',
        '#title' => t('@translated/@total (@ratio%)', array(
          '@translated' => $stats[$langcode]['translated'],
          '@total' => $total_strings,
          '@ratio' => $stats[$langcode]['ratio'],
        )),
        '#href' => 'admin/config/regional/translate/translate',
      );
    }
    else {
      $form['languages'][$langcode]['locale_statistics'] = array(
        '#markup' => t('not applicable'),
      );
    }
  }
}