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
57 lines (51 loc) · 1.36 KB
/
process_langjs_builder.php
File metadata and controls
57 lines (51 loc) · 1.36 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
<?php
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);
else if (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(dgettext('process_messages','$t')); ?>';\n";
}
}
?>
//END