findTranslationFiles example

NULL => ['drupal-8.0.0-beta2.hu.po', 'drupal-8.0.0.de.po', 'drupal-8.0.x.fr-CA.po'],
      'de' => ['drupal-8.0.0.de.po'],
      'fr-CA' => ['drupal-8.0.x.fr-CA.po'],
      'hu' => ['drupal-8.0.0-beta2.hu.po'],
      'it' => [],
    ];

    // Hardcode the fixtures location as we don't yet know where it is.     // @todo Remove as part of https://www.drupal.org/node/2186491     $file_translation = new FileTranslation('core/tests/fixtures/files/translations', $this->container->get('file_system'));
    foreach ($expected_translation_files as $langcode => $files_expected) {
      $files_found = $file_translation->findTranslationFiles($langcode);
      $this->assertSameSize($files_expected$files_foundnew FormattableMarkup('@count installer languages found.', ['@count' => count($files_expected)]));
      foreach ($files_found as $file) {
        $this->assertContains($file->filename, $files_expectednew FormattableMarkup('@file found.', ['@file' => $file->filename]));
      }
    }
  }

  /** * Tests profile info caching in non-English languages. */
  public function testInstallerTranslationCache() {
    
$this->fileSystem = $file_system;
  }

  /** * {@inheritdoc} */
  protected function getLanguage($langcode) {
    // If the given langcode was selected, there should be at least one .po     // file with its name in the pattern drupal-$version.$langcode.po.     // This might or might not be the entire filename. It is also possible     // that multiple files end with the same suffix, even if unlikely.     $files = $this->findTranslationFiles($langcode);

    if (!empty($files)) {
      return $this->filesToArray($langcode$files);
    }
    else {
      return [];
    }
  }

  /** * Finds installer translations either for a specific or all languages. * * Filenames must match the pattern: * - 'drupal-[version].[langcode].po (if langcode is provided) * - 'drupal-[version].*.po (if no langcode is provided) * * @param string $langcode * (optional) The language code corresponding to the language for which we * want to find translation files. If omitted, information on all available * files will be returned. * * @return array * An associative array of file information objects keyed by file URIs as * returned by FileSystemInterface::scanDirectory(). * * @see \Drupal\Core\File\FileSystemInterface::scanDirectory() */
foreach ($config['original_files'] as $originalFilePath) {
    if (!file_exists($originalFilePath)) {
        echo sprintf('The following file does not exist. Make sure that you execute this command at the root dir of the Symfony code repository.%s %s', \PHP_EOL, $originalFilePath);
        exit(1);
    }
}

$totalMissingTranslations = 0;
$totalTranslationMismatches = 0;

foreach ($config['original_files'] as $originalFilePath) {
    $translationFilePaths = findTranslationFiles($originalFilePath$config['locale_to_analyze']);
    $translationStatus = calculateTranslationStatus($originalFilePath$translationFilePaths);

    $totalMissingTranslations += array_sum(array_map(fn ($translation) => count($translation['missingKeys'])array_values($translationStatus)));
    $totalTranslationMismatches += array_sum(array_map(fn ($translation) => count($translation['mismatches'])array_values($translationStatus)));

    printTranslationStatus($originalFilePath$translationStatus$config['verbose_output']$config['include_completed_languages']);
}

exit($totalTranslationMismatches > 0 ? 1 : 0);

function findTranslationFiles($originalFilePath$localeToAnalyze): array
{
Home | Imprint | This part of the site doesn't use cookies.