You are here

function _potx_explore_dir in Translation template extractor 8

Same name and namespace in other branches
  1. 5.2 potx.inc \_potx_explore_dir()
  2. 5 potx.inc \_potx_explore_dir()
  3. 6.3 potx.inc \_potx_explore_dir()
  4. 6 potx.inc \_potx_explore_dir()
  5. 6.2 potx.inc \_potx_explore_dir()
  6. 7.3 potx.inc \_potx_explore_dir()
  7. 7 potx.inc \_potx_explore_dir()
  8. 7.2 potx.inc \_potx_explore_dir()

Collect a list of file names relevant for extraction, starting from $path.

Parameters

string $path: Where to start searching for files recursively. Provide non-empty path values with a trailing slash.

string $basename: Allows the restriction of search to a specific basename (ie. to collect files for a specific module).

int $api_version: Drupal API version to work with.

bool $skip_self: Skip potx related files. To be used when command line type of extraction is used and the potx files at in the webroot, and their strings should not end up in the generated template. Set to TRUE if skiping is needed.

7 calls to _potx_explore_dir()
PotxCommands::potx in src/Commands/PotxCommands.php
Extract translatable strings from Drupal source code.
PotxExtractTranslationForm::submitForm in src/Form/PotxExtractTranslationForm.php
Form submission handler.
PotxTest::testDrupal8CustomYml in tests/src/Kernel/PotxTest.php
Test parsing of custom yaml files.
PotxTest::testDrupal8ShippedConfiguration in tests/src/Kernel/PotxTest.php
Test parsing of Drupal 8 shipped configuration files.
potx_drush_extract in ./potx.drush.inc
Drush command callback.

... See full list

File

./potx.inc, line 3210
Extraction API used by the web and command line interface.

Code

function _potx_explore_dir($path = '', $basename = '*', $api_version = POTX_API_CURRENT, $skip_self = FALSE) {

  // It would be so nice to just use GLOB_BRACE, but it is not available on all
  // operarting systems, so we are working around the missing functionality.
  $extensions = [
    'php',
    'inc',
    'module',
    'engine',
    'theme',
    'install',
    'info',
    'profile',
  ];
  if ($api_version > POTX_API_5) {
    $extensions[] = 'js';
  }
  if ($api_version > POTX_API_7) {
    $extensions[] = 'twig';
    $extensions[] = 'yml';
    _potx_init_yaml_translation_patterns($path);
  }
  $files = [];
  foreach ($extensions as $extension) {
    $files_here = glob($path . $basename . '.' . $extension);
    if (is_array($files_here)) {
      $files = array_merge($files, $files_here);
    }
    if ($basename != '*') {

      // Basename was specific, so look for things like basename.admin.inc as
      // well. If the basnename was *, the above glob() already covered this
      // case.
      $files_here = glob($path . $basename . '.*.' . $extension);
      if (is_array($files_here)) {
        $files = array_merge($files, $files_here);
      }
    }
  }

  // Grab subdirectories.
  $dirs = glob($path . '*', GLOB_ONLYDIR);
  if (is_array($dirs)) {
    foreach ($dirs as $dir) {
      if (!preg_match("!(^|.+/)(CVS|\\.svn|\\.git|tests|Tests|vendor|node_modules)\$!", $dir)) {
        $files = array_merge($files, _potx_explore_dir("{$dir}/", $basename, $api_version, $skip_self));
      }
    }
  }

  // Skip API and test files. Also skip our own files, if that was requested.
  $skip_pattern = $skip_self ? '!(potx\\.inc|\\.api\\.php|\\.test)$!' : '!(\\.api\\.php|\\.test)$!';
  foreach ($files as $id => $file_name) {
    if (preg_match($skip_pattern, $file_name)) {
      unset($files[$id]);
    }
  }
  return $files;
}