forked from emoncms/emoncms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_langjs_builder.php
More file actions
68 lines (60 loc) · 1.65 KB
/
Copy pathprocess_langjs_builder.php
File metadata and controls
68 lines (60 loc) · 1.65 KB
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
<?php
// CLI only
if (php_sapi_name() !== 'cli') {
echo "This script is for CLI use only.\n";
die;
}
echo "//START";
$dir = '../Modules/process';
$filejs = array();
function get_js_file($dir)
{
global $filejs;
$dirs = array_diff(scandir($dir), array(".", ".."));
foreach ($dirs as $d) {
if (is_dir($dir . "/" . $d))
get_js_file($dir . "/" . $d);
elseif (pathinfo($d, PATHINFO_EXTENSION) == 'js')
$filejs[] = $dir . "/" . $d;
}
//return $dir_array;
}
function extract_translation($filejs)
{
$translation = array();
foreach ($filejs as $file) {
$lines = explode("\n", file_get_contents($file));
$tr = array();
foreach ($lines as $line) {
$pos = strpos($line, '_Tr(');
if ($pos !== false) {
$r = explode('_Tr("', $line);
unset($r[0]);
foreach ($r as $key => $val) {
$rr = explode('")', $val);
$tr[] = $rr[0];
}
}
}
$tr = array_unique($tr);
if (count($tr) > 0) {
$a = explode('/', $file);
$name = array_pop($a);
natcasesort($tr);
$translation[$name] = $tr;
}
}
return $translation;
}
get_js_file($dir);
//echo "<pre>".print_r($filejs,true)."</pre>";
$translation = extract_translation($filejs);
// echo "<pre>".print_r($translation,true)."</pre>";
foreach ($translation as $file => $tr) {
echo "\n// " . $file . "\n";
foreach ($tr as $t) {
echo "LANG_JS[\"$t\"] = '<?php echo addslashes(ctx_tr('process_messages','$t')); ?>';\n";
}
}
?>
//END