function _potx_write_files in Translation template extractor 5
Same name and namespace in other branches
- 8 potx.inc \_potx_write_files()
- 5.2 potx.inc \_potx_write_files()
- 6.3 potx.inc \_potx_write_files()
- 6 potx.inc \_potx_write_files()
- 6.2 potx.inc \_potx_write_files()
- 7.3 potx.inc \_potx_write_files()
- 7 potx.inc \_potx_write_files()
- 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 455 - Extraction API used by the web and command line interface.
Code
function _potx_write_files($http_filename = NULL, $content_disposition = 'inline') {
global $_potx_store;
if (!is_array($_potx_store)) {
// If $_potx_store is not an array, then we did not find any strings to export.
return;
}
// Possibly merge some files if we have more then one.
if (count($_potx_store) > 1) {
foreach ($_potx_store as $file => $contents) {
// Merge too small files into general.pot.
if ($contents['count'] < 10 && $file != 'general' && $file != 'installer') {
if (!isset($_potx_store['general'])) {
$_potx_store['general'] = $contents;
}
else {
$_potx_store['general']['sources'] = array_unique(array_merge($_potx_store['general']['sources'], $contents['sources']));
$_potx_store['general']['strings'] .= $contents['strings'];
}
// Drop this file, contents are integrated into general.pot.
unset($_potx_store[$file]);
}
}
}
// Generate file lists and output files.
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);
}
}
}