You are here

function locale_translate_get_interface_translation_files in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.bulk.inc \locale_translate_get_interface_translation_files()
  2. 10 core/modules/locale/locale.bulk.inc \locale_translate_get_interface_translation_files()

Get interface translation files present in the translations directory.

Parameters

array $projects: (optional) Project names from which to get the translation files and history. Defaults to all projects.

array $langcodes: (optional) Language codes from which to get the translation files and history. Defaults to all languages.

Return value

array An array of interface translation files keyed by their URI.

3 calls to locale_translate_get_interface_translation_files()
locale_translate_batch_import_files in core/modules/locale/locale.bulk.inc
Prepare a batch to import all translations.
locale_translate_delete_translation_files in core/modules/locale/locale.bulk.inc
Deletes interface translation files and translation history records.
_install_prepare_import in core/includes/install.core.inc
Tells the translation import process that Drupal core is installed.

File

core/modules/locale/locale.bulk.inc, line 90
Mass import-export and batch import functionality for Gettext .po files.

Code

function locale_translate_get_interface_translation_files(array $projects = [], array $langcodes = []) {
  module_load_include('compare.inc', 'locale');
  $files = [];
  $projects = $projects ? $projects : array_keys(locale_translation_get_projects());
  $langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());

  // Scan the translations directory for files matching a name pattern
  // containing a project name and language code: {project}.{langcode}.po or
  // {project}-{version}.{langcode}.po.
  // Only files of known projects and languages will be returned.
  $directory = \Drupal::config('locale.settings')
    ->get('translation.path');
  $result = [];
  if (is_dir($directory)) {
    $result = \Drupal::service('file_system')
      ->scanDirectory($directory, '![a-z_]+(\\-[0-9a-z\\.\\-\\+]+|)\\.[^\\./]+\\.po$!', [
      'recurse' => FALSE,
    ]);
  }
  foreach ($result as $file) {

    // Update the file object with project name and version from the file name.
    $file = locale_translate_file_attach_properties($file);
    if (in_array($file->project, $projects)) {
      if (in_array($file->langcode, $langcodes)) {
        $files[$file->uri] = $file;
      }
    }
  }
  return $files;
}