You are here

function locale_test_locale_translation_projects_alter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/tests/modules/locale_test/locale_test.module \locale_test_locale_translation_projects_alter()

Implements hook_locale_translation_projects_alter().

The translation status process by default checks the status of the installed projects. This function replaces the data of the installed modules by a predefined set of modules with fixed file names and release versions. Project names, versions, timestamps etc must be fixed because they must match the files created by the test script.

The "locale.test_projects_alter" state variable must be set by the test script in order for this hook to take effect.

File

core/modules/locale/tests/modules/locale_test/locale_test.module, line 42
Simulate a custom module with a local po file.

Code

function locale_test_locale_translation_projects_alter(&$projects) {

  // Drupal core should not be translated. By overriding the server pattern we
  // make sure that no translation for drupal core will be found and that the
  // translation update system will not go out to l.d.o to check.
  $projects['drupal']['server_pattern'] = 'translations://';
  if (\Drupal::state()
    ->get('locale.remove_core_project')) {
    unset($projects['drupal']);
  }
  if (\Drupal::state()
    ->get('locale.test_projects_alter')) {

    // Instead of the default ftp.drupal.org we use the file system of the test
    // instance to simulate a remote file location.
    $url = \Drupal::url('<front>', [], [
      'absolute' => TRUE,
    ]);
    $remote_url = $url . PublicStream::basePath() . '/remote/';

    // Completely replace the project data with a set of test projects.
    $projects = array(
      'contrib_module_one' => array(
        'name' => 'contrib_module_one',
        'info' => array(
          'name' => 'Contributed module one',
          'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
          'package' => 'Other',
          'version' => '8.x-1.1',
          'project' => 'contrib_module_one',
          'datestamp' => '1344471537',
          '_info_file_ctime' => 1348767306,
        ),
        'datestamp' => '1344471537',
        'project_type' => 'module',
        'project_status' => TRUE,
      ),
      'contrib_module_two' => array(
        'name' => 'contrib_module_two',
        'info' => array(
          'name' => 'Contributed module two',
          'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
          'package' => 'Other',
          'version' => '8.x-2.0-beta4',
          'project' => 'contrib_module_two',
          'datestamp' => '1344471537',
          '_info_file_ctime' => 1348767306,
        ),
        'datestamp' => '1344471537',
        'project_type' => 'module',
        'project_status' => TRUE,
      ),
      'contrib_module_three' => array(
        'name' => 'contrib_module_three',
        'info' => array(
          'name' => 'Contributed module three',
          'interface translation server pattern' => $remote_url . '%core/%project/%project-%version.%language._po',
          'package' => 'Other',
          'version' => '8.x-1.0',
          'project' => 'contrib_module_three',
          'datestamp' => '1344471537',
          '_info_file_ctime' => 1348767306,
        ),
        'datestamp' => '1344471537',
        'project_type' => 'module',
        'project_status' => TRUE,
      ),
      'locale_test' => array(
        'name' => 'locale_test',
        'info' => array(
          'name' => 'Locale test',
          'interface translation project' => 'locale_test',
          'interface translation server pattern' => 'core/modules/locale/tests/test.%language.po',
          'package' => 'Other',
          'version' => NULL,
          'project' => 'locale_test',
          '_info_file_ctime' => 1348767306,
          'datestamp' => 0,
        ),
        'datestamp' => 0,
        'project_type' => 'module',
        'project_status' => TRUE,
      ),
      'custom_module_one' => array(
        'name' => 'custom_module_one',
        'info' => array(
          'name' => 'Custom module one',
          'interface translation project' => 'custom_module_one',
          'interface translation server pattern' => 'translations://custom_module_one.%language.po',
          'package' => 'Other',
          'version' => NULL,
          'project' => 'custom_module_one',
          '_info_file_ctime' => 1348767306,
          'datestamp' => 0,
        ),
        'datestamp' => 0,
        'project_type' => 'module',
        'project_status' => TRUE,
      ),
    );
  }
}