function locale_translation_build_projects

Builds list of projects and stores the result in the database.

The project data is based on the project list supplied by the Update module. Only the properties required by Locale module is included and additional (custom) modules and translation server data is added.

In case the Update module is disabled this function will return an empty array.

Return value

array Array of project data:

  • "name": Project system name.
  • "project_type": Project type, e.g. 'module', 'theme'.
  • "core": Core release version, e.g. 8.x
  • "version": Project release version, e.g. 8.x-1.0 See http://drupalcode.org/project/drupalorg.git/blob/refs/heads/7.x-3.x:/dru... for how the version strings are created.
  • "server_pattern": Translation server po file pattern.
  • "status": Project status, 1 = enabled.
4 calls to locale_translation_build_projects()
install_import_translations_remaining in drupal/core/includes/install.core.inc
Finishes importing files at end of installation.
locale_system_update in drupal/core/modules/locale/locale.module
Imports translations when new modules or themes are installed.
locale_translation_get_projects in drupal/core/modules/locale/locale.translation.inc
Get array of projects which are available for interface translation.
locale_translation_status_form in drupal/core/modules/locale/locale.pages.inc
Page callback: Display the current translation status.

File

drupal/core/modules/locale/locale.compare.inc, line 47
The API for comparing project translation status with available translation.

Code

function locale_translation_build_projects() {

  // This function depends on Update module. We degrade gracefully.
  if (!module_exists('update')) {
    return array();
  }

  // Get the project list based on .info.yml files.
  $projects = locale_translation_project_list();

  // Mark all previous projects as disabled and store new project data.
  db_update('locale_project')
    ->fields(array(
    'status' => 0,
  ))
    ->execute();
  $default_server = locale_translation_default_translation_server();

  // If project is a dev release, or core, find the latest available release.
  $project_updates = update_get_available(TRUE);
  foreach ($projects as $name => $data) {
    if (isset($project_updates[$name]['releases']) && $project_updates[$name]['project_status'] != 'not-fetched') {

      // Find out if a dev version is installed.
      if (preg_match("/^[0-9]+\\.x-([0-9]+)\\..*-dev\$/", $data['info']['version'], $matches)) {

        // Find a suitable release to use as alternative translation.
        foreach ($project_updates[$name]['releases'] as $project_release) {

          // The first release with the same major release number which is not a
          // dev release is the one. Releases are sorted the most recent first.
          // @todo http://drupal.org/node/1774024 Make a helper function.
          if ($project_release['version_major'] == $matches[1] && (!isset($project_release['version_extra']) || $project_release['version_extra'] != 'dev')) {
            $release = $project_release;
            break;
          }
        }
      }
      elseif ($name == "drupal") {

        // Pick latest available release.
        $release = array_shift($project_updates[$name]['releases']);
      }
      if (!empty($release['version'])) {
        $data['info']['version'] = $release['version'];
      }
      unset($release);
    }

    // For every project store information.
    $data += array(
      'version' => isset($data['info']['version']) ? $data['info']['version'] : '',
      'core' => isset($data['info']['core']) ? $data['info']['core'] : DRUPAL_CORE_COMPATIBILITY,
      // A project can provide the path and filename pattern to download the
      // gettext file. Use the default if not.
      'server_pattern' => isset($data['info']['interface translation server pattern']) && $data['info']['interface translation server pattern'] ? $data['info']['interface translation server pattern'] : $default_server['pattern'],
      'status' => !empty($data['project_status']) ? 1 : 0,
    );
    $project = (object) $data;
    $projects[$name] = $project;

    // Create or update the project record.
    db_merge('locale_project')
      ->key(array(
      'name' => $project->name,
    ))
      ->fields(array(
      'name' => $project->name,
      'project_type' => $project->project_type,
      'core' => $project->core,
      'version' => $project->version,
      'server_pattern' => $project->server_pattern,
      'status' => $project->status,
    ))
      ->execute();

    // Invalidate the cache of translatable projects.
    locale_translation_clear_cache_projects();
  }
  return $projects;
}