locale_form_language_admin_overview_form_alter(&$form, FormStateInterface $form_state)
Implements hook_form_FORM_ID_alter() for language_admin_overview_form().
File
- core/modules/locale/locale.module, line 623
- Enables the translation of the user interface to languages other than English.
Code
function locale_form_language_admin_overview_form_alter(&$form, FormStateInterface $form_state) { $languages = $form['languages']['#languages']; $total_strings = \Drupal::service('locale.storage')->countStrings(); $stats = array_fill_keys(array_keys($languages), array()); // If we have source strings, count translations and calculate progress. if (!empty($total_strings)) { $translations = \Drupal::service('locale.storage')->countTranslations(); foreach ($translations as $langcode => $translated) { $stats[$langcode]['translated'] = $translated; if ($translated > 0) { $stats[$langcode]['ratio'] = round($translated / $total_strings * 100, 2); } } } array_splice($form['languages']['#header'], -1, 0, ['translation-interface' => t('Interface translation')]); foreach ($languages as $langcode => $language) { $stats[$langcode] += array( 'translated' => 0, 'ratio' => 0, ); if (!$language->isLocked() && locale_is_translatable($langcode)) { $form['languages'][$langcode]['locale_statistics'] = array( '#markup' => \Drupal::l( t('@translated/@total (@ratio%)', array( '@translated' => $stats[$langcode]['translated'], '@total' => $total_strings, '@ratio' => $stats[$langcode]['ratio'], )), new Url('locale.translate_page', array(), array('query' => array('langcode' => $langcode))) ), ); } else { $form['languages'][$langcode]['locale_statistics'] = array( '#markup' => t('not applicable'), ); } // #type = link doesn't work with #weight on table. // reset and set it back after locale_statistics to get it at the right end. $operations = $form['languages'][$langcode]['operations']; unset($form['languages'][$langcode]['operations']); $form['languages'][$langcode]['operations'] = $operations; } }
Please login to continue.