You are here

function _potx_write_files in Translation template extractor 8

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

Write out generated files to the current folder.

@todo Look into whether multiple files can be output via HTTP.

Parameters

string $http_filename: File name for content-disposition header in case of usage over HTTP. If not given, files are written to the local filesystem.

string $content_disposition: See RFC2183. 'inline' or 'attachment', with a default of 'inline'. Only used if $http_filename is set.

6 calls to _potx_write_files()
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::buildOutput in tests/src/Kernel/PotxTest.php
Build the output from parsed files.
PotxTest::parseFile in tests/src/Kernel/PotxTest.php
Parse the given file with the given API version.
PotxTest::parsePhpContent in tests/src/Kernel/PotxTest.php
Parse the given file with the given API version.

... See full list

File

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

Code

function _potx_write_files($http_filename = NULL, $content_disposition = 'inline') {
  global $_potx_store;

  // Generate file lists and output files.
  if (is_array($_potx_store)) {
    foreach ($_potx_store as $file => $contents) {

      // Build replacement for file listing.
      if (count($contents['sources']) > 1) {
        $filelist = "Generated from files:\n#  " . implode("\n#  ", $contents['sources']);
      }
      elseif (count($contents['sources']) == 1) {
        $filelist = "Generated from file: " . implode('', $contents['sources']);
      }
      else {
        $filelist = 'No version information was available in the source files.';
      }
      $output = str_replace('--VERSIONS--', $filelist, $contents['header'] . $contents['strings']);
      if ($http_filename) {

        // HTTP output.
        header('Content-Type: text/plain; charset=utf-8');
        header('Content-Transfer-Encoding: 8bit');
        header("Content-Disposition: {$content_disposition}; filename={$http_filename}");
        print $output;
        return;
      }
      else {

        // Local file output, flatten directory structure.
        $file = str_replace('.', '-', preg_replace('![/]?([a-zA-Z_0-9]*/)*!', '', $file)) . '.pot';
        $fp = fopen($file, 'w');
        fwrite($fp, $output);
        fclose($fp);
      }
    }
  }
}