#!/usr/bin/php
<?
foreach(file('MIMviewer.properties') as $l) {
	list($a,$b)=explode('#',$l,2);
	if(strlen($a)<=1) continue;
	list($k,$v)=explode('=',trim($l),2);
	if(strlen($k)<1) continue;
	$klist[$k]=0;
	$textlist[$k]=$v;
}
foreach(glob('MIMviewer_*.properties') as $filen){
print "Checking $filen\n";
foreach(file($filen) as $l) {
	list($a,$b)=explode('#',$l,2);
	if(strlen($a)<=1) continue;
	list($k,$v)=explode('=',trim($l),2);
	if(strlen($k)<1) continue;
	if(isset($klist[$k])) {
		$klist[$k]++;
		if($klist[$k]>1) {
		}
	} else {
		print "$k does NOT exist in MIMviewer.properties, but DOES exist in $filen... \n";
	}
}
$error=0;
foreach($klist as $k=>$v){
	if($v>1) { print "$k exists in $filen {$klist[$k]} times.. who does that\n"; $error++; }
	if($v==0) {
		print "$k does NOT exist in $filen {$klist[$k]}, must be added!!\n"; 
		print "\toriginal: $k={$textlist[$k]}\n";
		$error++;
	}
	
	$klist[$k]=0;
}
print "\t$filen : $error errors\n--------------\n";
}
$x=fopen('tools/translate.csv','w');
$wc=0;$lines=0;
foreach($textlist as $k=>$v){
	$wc+=str_word_count($v);
	$lines++;
	fwrite($x,"\"$k\",\"$v\"\n");
}
fclose($x); print "Spreadsheet written : $wc words in $lines lines : translate.csv\n";
?>
