function LocaleJs::refreshTranslations

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

Refresh related information after string translations have been updated.

The information that will be refreshed includes:

  • JavaScript translations.
  • Locale cache.
  • Render cache.

Parameters

array $langcodes: Language codes for updated translations.

array $lids: (optional) List of string identifiers that have been updated / created. If not provided, all caches for the affected languages are cleared.

File

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

Class

LocaleJs
Provides the locale javascript related methods.

Namespace

Drupal\locale

Code

public function refreshTranslations(array $langcodes, array $lids = []) : void {
  if (!empty($langcodes)) {
    // Update javascript translations if any of the strings has a javascript
    // location, or if no string ids were provided, update all languages.
    if (empty($lids) || !empty($this->localeStorage
      ->getStrings([
      'lid' => $lids,
      'type' => 'javascript',
    ]))) {
      foreach ($langcodes as $langcode) {
        $this->invalidate($langcode);
      }
    }
  }
  // Throw locale.save_translation event.
  $this->eventDispatcher
    ->dispatch(new LocaleEvent($langcodes, $lids), LocaleEvents::SAVE_TRANSLATION);
}

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