7 locale.module locale_js_alter(&$javascript)
8 locale.module locale_js_alter(&$javascript, AttachedAssetsInterface $assets)

Implements hook_js_alter().

File

core/modules/locale/locale.module, line 489
Enables the translation of the user interface to languages other than English.

Code

function locale_js_alter(&$javascript, AttachedAssetsInterface $assets) {
  // @todo remove this in https://www.drupal.org/node/2421323
  $files = array();
  foreach ($javascript as $item) {
    if (isset($item ['type']) && $item ['type'] == 'file') {
      // Ignore the JS translation placeholder file.
      if ($item ['data'] === 'core/modules/locale/locale.translation.js') {
        continue;
      }
      $files [] = $item ['data'];
    }
  }

  // Replace the placeholder file with the actual JS translation file.
  $placeholder_file = 'core/modules/locale/locale.translation.js';
  if (isset($javascript [$placeholder_file])) {
    if ($translation_file = locale_js_translate($files)) {
      $js_translation_asset = &$javascript [$placeholder_file];
      $js_translation_asset ['data'] = $translation_file;
      // @todo Remove this when https://www.drupal.org/node/1945262 lands.
      // Decrease the weight so that the translation file is loaded first.
      $js_translation_asset ['weight'] = $javascript ['core/misc/drupal.js']['weight'] - 0.001;
    }
    else {
      // If no translation file exists, then remove the placeholder JS asset.
      unset($javascript [$placeholder_file]);
    }
  }
}