Commit 76737efb authored by catch's avatar catch
Browse files

Issue #3218674 by promes, anybody, tobiasb, ressa, jordan.jamous, grevil,...

Issue #3218674 by promes, anybody, tobiasb, ressa, jordan.jamous, grevil, grimreaper: "Translation file not found" for English when "translate_english" is false

(cherry picked from commit 84b3f93f)
parent 0baddb31
Loading
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -98,7 +98,15 @@ function locale_translation_batch_status_check($project, $langcode, array $optio
  // Check the status of remote translation files.
  if ($options['use_remote'] && isset($source->files[LOCALE_TRANSLATION_REMOTE])) {
    $remote_file = $source->files[LOCALE_TRANSLATION_REMOTE];
    if ($result = locale_translation_http_check($remote_file->uri)) {
    if ($langcode === 'en') {
      // drupal.org does not support english as translation.
      $uri = locale_translation_build_server_pattern($source, strtr(\Drupal::TRANSLATION_DEFAULT_SERVER_PATTERN, ['%language' => $langcode]));
      if ($uri === $remote_file->uri) {
        $failure = TRUE;
      }
    }

    if (!$failure && $result = locale_translation_http_check($remote_file->uri)) {
      // Update the file object with the result data. In case of a redirect we
      // store the resulting uri.
      if (isset($result['last_modified'])) {
+62 −0
Original line number Diff line number Diff line
@@ -47,4 +47,66 @@ public function testBuildProjects(): void {
    $this->assertEquals('Ignoring already imported translation for drupal.', $context['message']);
  }

  /**
   * Tests English translations skip default drupal.org pattern.
   */
  public function testEnglishTranslationSkipsDefaultPattern(): void {
    $this->installConfig(['locale', 'language']);
    $this->installSchema('locale', ['locales_source', 'locales_target', 'locale_file']);
    $this->container->get('module_handler')->loadInclude('locale', 'batch.inc');

    // Create source matching default drupal.org pattern.
    $source = (object) [
      'name' => 'test_module',
      'langcode' => 'en',
      'project' => 'test_module',
      'version' => '1.0.0',
      'core' => 'all',
      'files' => [
        LOCALE_TRANSLATION_REMOTE => (object) [
          'uri' => 'https://ftp.drupal.org/files/translations/all/test_module/test_module-1.0.0.en.po',
        ],
      ],
    ];

    \Drupal::keyValue('locale.translation_status')->setMultiple(['test_module' => ['en' => $source]]);

    $context = ['results' => []];
    locale_translation_batch_status_check('test_module', 'en', ['use_remote' => TRUE, 'finish_feedback' => TRUE], $context);

    // Should be marked as failed (skipped) for English default pattern.
    $this->assertContains('test_module', $context['results']['failed_files']);
    $this->assertCount(0, $context['results']['files'] ?? []);
  }

  /**
   * Tests non-English languages do not skip default drupal.org pattern.
   */
  public function testNonEnglishLanguagesUnaffected(): void {
    $this->installConfig(['locale', 'language']);
    $this->installSchema('locale', ['locales_source', 'locales_target', 'locale_file']);
    $this->container->get('module_handler')->loadInclude('locale', 'batch.inc');

    $source = (object) [
      'name' => 'test_module',
      'langcode' => 'de',
      'project' => 'test_module',
      'version' => '1.0.0',
      'core' => 'all',
      'files' => [
        LOCALE_TRANSLATION_REMOTE => (object) [
          'uri' => 'https://ftp.drupal.org/files/translations/all/test_module/test_module-1.0.0.de.po',
        ],
      ],
    ];

    \Drupal::keyValue('locale.translation_status')->setMultiple(['test_module' => ['de' => $source]]);

    $context = ['results' => []];
    locale_translation_batch_status_check('test_module', 'de', ['use_remote' => TRUE, 'finish_feedback' => TRUE], $context);

    $this->assertContains('test_module', $context['results']['files']);
    $this->assertCount(0, $context['results']['failed_files'] ?? []);
  }

}