function locale_translation_build_projects

Same name in other branches
  1. 9 core/modules/locale/locale.compare.inc \locale_translation_build_projects()
  2. 8.9.x core/modules/locale/locale.compare.inc \locale_translation_build_projects()
  3. 10 core/modules/locale/locale.compare.inc \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
  • "server_pattern": Translation server po file pattern.
  • "status": Project status, 1 = enabled.
6 calls to locale_translation_build_projects()
install_finish_translations in core/includes/install.core.inc
Finishes importing files at end of installation.
LocaleBuildTest::testBuildProjects in core/modules/locale/tests/src/Kernel/LocaleBuildTest.php
Checks if a list of translatable projects gets built.
LocaleUpdateDevelopmentReleaseTest::testLocaleUpdateDevelopmentRelease in core/modules/locale/tests/src/Functional/LocaleUpdateDevelopmentReleaseTest.php
locale_system_update in core/modules/locale/locale.module
Imports translations when new modules or themes are installed.
locale_translation_get_projects in core/modules/locale/locale.translation.inc
Get array of projects which are available for interface translation.

... See full list

File

core/modules/locale/locale.compare.inc, line 43

Code

function locale_translation_build_projects() {
    // 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.
    \Drupal::service('locale.project')->disableAll();
    $default_server = locale_translation_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: 8.x-1.x-dev, 8.x-1.0-alpha1+5-dev => 8.x-1.x
                $data['info']['version'] = $matches[1] . 'x';
            }
            elseif (preg_match("/^(\\d+\\.\\d+\\.).*\$/", $data['info']['version'], $matches)) {
                // Example match: 8.0.0-dev => 8.0.x (Drupal core)
                $data['info']['version'] = $matches[1] . 'x';
            }
        }
        // For every project store information.
        $data += [
            'name' => $name,
            'version' => $data['info']['version'] ?? '',
            'core' => 'all',
            // 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.
        \Drupal::service('locale.project')->set($project->name, $data);
        // Invalidate the cache of translatable projects.
        locale_translation_clear_cache_projects();
    }
    return $projects;
}

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