function LocaleSource::loadSources

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

Loads cached translation sources containing current translation status.

Parameters

array|null $projects: Array of project names. Defaults to all translatable projects.

array|null $langcodes: Array of language codes. Defaults to all translatable languages.

Return value

\Drupal\locale\LocaleTranslationSource[][] Array of source objects. Keyed with <project name>:<language code>.

See also

sourceBuild()

1 call to LocaleSource::loadSources()
LocaleSource::deleteSourcesByLanguage in core/modules/locale/src/LocaleSource.php
Deletes sources for a given language code.

File

core/modules/locale/src/LocaleSource.php, line 49

Class

LocaleSource
Provides the locale source services.

Namespace

Drupal\locale

Code

public function loadSources(?array $projects = NULL, ?array $langcodes = NULL) : array {
  $projects = $projects ?: array_keys($this->localeProjectRepository
    ->getAll());
  $langcodes = $langcodes ?: array_keys(locale_translatable_language_list());
  // If there are no translatable languages, return early.
  if (!$langcodes) {
    return [];
  }
  // Load source data from locale_translation_status key value store.
  $sources = $this->keyValueFactory
    ->get('locale.translation_status')
    ->getMultiple($projects);
  // Build sources that are missing.
  foreach ($projects as $project_name) {
    foreach ($langcodes as $langcode) {
      if (!isset($sources[$project_name][$langcode])) {
        $project = $this->localeProjectRepository
          ->getMultiple([
          $project_name,
        ])[$project_name];
        $sources[$project_name][$langcode] = $this->sourceBuild($project, $langcode);
      }
    }
  }
  return $sources;
}

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