You are here

function locale_translation_get_projects in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/locale.translation.inc \locale_translation_get_projects()

Get array of projects which are available for interface translation.

This project data contains all projects which will be checked for available interface translations.

For full functionality this function depends on Update module. When Update module is enabled the project data will contain the most recent module status; both in enabled status as in version. When Update module is disabled this function will return the last known module state. The status will only be updated once Update module is enabled.

Parameters

array $project_names: Array of names of the projects to get.

Return value

array Array of project data for translation update.

See also

locale_translation_build_projects()

12 calls to locale_translation_get_projects()
LocaleTranslationProjectsTest::testLocaleTranslationClearCacheProjects in core/modules/locale/src/Tests/LocaleTranslationProjectsTest.php
Tests locale_translation_clear_cache_projects().
LocaleUpdateTest::testEnableUninstallModule in core/modules/locale/src/Tests/LocaleUpdateTest.php
Tests automatic translation import when a module is enabled.
locale_system_remove in core/modules/locale/locale.module
Delete translation history of modules and themes.
locale_translate_get_interface_translation_files in core/modules/locale/locale.bulk.inc
Get interface translation files present in the translations directory.
locale_translation_batch_fetch_build in core/modules/locale/locale.fetch.inc
Builds a batch to download and import project translations.

... See full list

1 string reference to 'locale_translation_get_projects'
locale_translation_clear_cache_projects in core/modules/locale/locale.translation.inc
Clears the projects cache.

File

core/modules/locale/locale.translation.inc, line 55
Common API for interface translation.

Code

function locale_translation_get_projects(array $project_names = array()) {
  $projects =& drupal_static(__FUNCTION__, array());
  if (empty($projects)) {

    // Get project data from the database.
    $row_count = \Drupal::service('locale.project')
      ->countProjects();

    // https://www.drupal.org/node/1777106 is a follow-up issue to make the
    // check for possible out-of-date project information more robust.
    if ($row_count == 0) {
      module_load_include('compare.inc', 'locale');

      // At least the core project should be in the database, so we build the
      // data if none are found.
      locale_translation_build_projects();
    }
    $projects = \Drupal::service('locale.project')
      ->getAll();
    array_walk($projects, function (&$project) {
      $project = (object) $project;
    });
  }

  // Return the requested project names or all projects.
  if ($project_names) {
    return array_intersect_key($projects, array_combine($project_names, $project_names));
  }
  return $projects;
}