-
Notifications
You must be signed in to change notification settings - Fork 10
/
pear-dh-compile-translationfile
executable file
·88 lines (74 loc) · 2.47 KB
/
pear-dh-compile-translationfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!@PHP-BIN@
<?php
/**
* Script that can be used to compile xml-based language-files.
*
* @version $Id$
* @author Carsten Lucke <[email protected]>
*/
require_once 'Console/Getargs.php';
require_once 'XML/Unserializer.php';
$options = array(
'parseAttributes' => false,
'attributesArray' => false,
'keyAttribute' => array('property' => 'id')
);
$config = array(
'outputdir' => array(
'short' => 'd',
'min' => 1,
'max' => 1,
'desc' => 'Directory where compiled files are saved. Defaults to the current working directory.',
'default' => getcwd()
),
'verbose' => array(
'short' => 'v',
'min' => 0,
'max' => 0,
'desc' => 'Enable verbose mode.'
),
CONSOLE_GETARGS_PARAMS => array(
'min' => 1,
'max' => -1,
'desc' => 'Input file(s)'
)
);
$args = &Console_Getargs::factory($config);
if (PEAR::isError($args) || is_null($args->getValue(CONSOLE_GETARGS_PARAMS))) {
$header = "Date_Holidays language-file compiler\n--\n".
'Usage: '.basename($_SERVER['SCRIPT_NAME'])." [options] filename(s)\n\n";
if (is_a($args, 'PEAR_Error') && $args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
echo Console_Getargs::getHelp($config, $header, $args->getMessage())."\n";
} else {
echo Console_Getargs::getHelp($config, $header)."\n";
}
exit;
}
$files = $args->getValue(CONSOLE_GETARGS_PARAMS);
if (is_string($files)) {
$files = array($files);
}
$outputDir = $args->getValue('outputdir');
foreach ($files as $file) {
if (! file_exists($file)) {
die(sprintf('File not found: %s', $file) . "\n");
}
$unserializer = &new XML_Unserializer($options);
$status = $unserializer->unserialize($file, true);
if (PEAR::isError($status)) {
die('Error occurred: ' . $status->getMessage());
} else {
$content = $unserializer->getUnserializedData();
$filename = $outputDir . DIRECTORY_SEPARATOR . basename($file, '.xml') . '.ser';
if ($fp = fopen($filename, 'w')) {
fwrite($fp, serialize($content));
fclose($fp);
if ($args->isDefined('v')) {
echo 'Writing compiled data to: ' . $filename . "\n";
}
} else {
die('Could not write compiled file' . "\n");
}
}
}
?>