function LocaleJs::invalidate

Same name and namespace in other branches
  1. 11.x core/modules/locale/src/LocaleJs.php \Drupal\locale\LocaleJs::invalidate()

Force the JavaScript translation file(s) to be refreshed.

This function sets a refresh flag for a specified language, or all languages except English, if none specified. JavaScript translation files are rebuilt (with locale_update_js_files()) the next time a request is served in that language.

Parameters

string|null $langcode: (optional) The language code for which the file needs to be refreshed, or NULL to refresh all languages. Defaults to NULL.

Return value

array New content of the 'system.javascript_parsed' variable.

2 calls to LocaleJs::invalidate()
LocaleJs::jsTranslate in core/modules/locale/src/LocaleJs.php
Returns a list of translation files given a list of JavaScript files.
LocaleJs::refreshTranslations in core/modules/locale/src/LocaleJs.php
Refresh related information after string translations have been updated.

File

core/modules/locale/src/LocaleJs.php, line 247

Class

LocaleJs
Provides the locale javascript related methods.

Namespace

Drupal\locale

Code

public function invalidate(?string $langcode = NULL) : array {
  $parsed = $this->state
    ->get('system.javascript_parsed', []);
  if (empty($langcode)) {
    // Invalidate all languages.
    $languages = $this->localeLanguages
      ->getTranslatableLanguages();
    foreach ($languages as $languageCode => $data) {
      $parsed['refresh:' . $languageCode] = 'waiting';
    }
  }
  else {
    // Invalidate single language.
    $parsed['refresh:' . $langcode] = 'waiting';
  }
  $this->state
    ->set('system.javascript_parsed', $parsed);
  return $parsed;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.