You are here

function l10n_update_build_projects in Localization update 7.2

Same name and namespace in other branches
  1. 6 l10n_update.project.inc \l10n_update_build_projects()
  2. 7 l10n_update.project.inc \l10n_update_build_projects()

Rebuild project list.

Parameters

bool $refresh: TRUE: Refresh project list.

Return value

array Array of project objects to be considered for translation update.

3 calls to l10n_update_build_projects()
l10n_update_get_projects in ./l10n_update.translation.inc
Get array of projects which are available for interface translation.
l10n_update_status_form in ./l10n_update.admin.inc
Page callback: Translation status page.
l10n_update_system_update in ./l10n_update.module
Imports translations when new modules or themes are installed.
1 string reference to 'l10n_update_build_projects'
l10n_update_flush_projects in ./l10n_update.compare.inc
Clear the project data table.

File

./l10n_update.compare.inc, line 32
The API for comparing project translation status with available translation.

Code

function l10n_update_build_projects($refresh = FALSE) {
  $projects =& drupal_static(__FUNCTION__, array(), $refresh);
  if (empty($projects)) {
    module_load_include('inc', 'l10n_update');

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

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

      // For dev releases, remove the '-dev' part and trust the translation
      // server to fall back to the latest stable release for that branch.
      if (isset($data['info']['version']) && strpos($data['info']['version'], '-dev')) {
        if (preg_match("/^(\\d+\\.x-\\d+\\.).*\$/", $data['info']['version'], $matches)) {

          // Example matches: 7.x-1.x-dev, 7.x-1.0-alpha1+5-dev => 7.x-1.x.
          $data['info']['version'] = $matches[1] . 'x';
        }
        elseif (preg_match("/^(\\d+\\.).*\$/", $data['info']['version'], $matches)) {

          // Example match: 7.33-dev => 7.x (Drupal core).
          $data['info']['version'] = $matches[1] . 'x';
        }
      }
      $data += array(
        'version' => isset($data['info']['version']) ? $data['info']['version'] : '',
        'core' => isset($data['info']['core']) ? $data['info']['core'] : DRUPAL_CORE_COMPATIBILITY,
        'l10n_path' => isset($data['info']['l10n path']) && $data['info']['l10n path'] ? $data['info']['l10n path'] : $default_server['pattern'],
        'status' => 1,
      );
      $project = (object) $data;
      $projects[$name] = $project;

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

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