You are here

function _potx_write_files in Translation template extractor 6

Same name and namespace in other branches
  1. 8 potx.inc \_potx_write_files()
  2. 5.2 potx.inc \_potx_write_files()
  3. 5 potx.inc \_potx_write_files()
  4. 6.3 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

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

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

2 calls to _potx_write_files()
potx-cli.php in ./potx-cli.php
potx_select_form_submit in ./potx.module
Generate translation template or translation file for the requested module.

File

./potx.inc, line 473
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#  " . join("\n#  ", $contents['sources']);
      }
      elseif (count($contents['sources']) == 1) {
        $filelist = "Generated from file: " . join('', $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);
      }
    }
  }
}