#!/usr/bin/perl
#
#
# Utility to check strings which need translation.
#
#

print <<EOF;
---------------------------------------------
Now checking translation for each language
EOF

#--------------------------------
# check strings in 'user-ja-conf'
#--------------------------------
sub printf_ ($@) {
	$msgid{$_[0]} = "user-ja-conf: $num";
}

open(FILE, "./user-ja-conf") || die "CANNOT OPEN user-ja-conf.\n";
$num = 0;
while($line=<FILE>) {
	$num++;
	if ($line !~ /&printf_/) {next;}
	
	$a = $line;
	if ($line !~ /\);\s$/) {
		while ($line = <FILE>) {
			$num++;
			$a .= $line;
			if ($line =~ /\);\s$/) {last;}
		}
	}
	eval($a);
	if ($@) {printf STDERR "$a\n...\n$@";}
}
close(FILE);

#---------------------------------------
# build a list of all support.*.pl files
#---------------------------------------
opendir(DIR, ".") || die "Cannot open this directory.\n";
@filelist1 = readdir(DIR);
closedir(DIR);
@filelist = sort(@filelist1);
foreach $filename (@filelist) {
	if ($filename !~ /^support\.(.*)\.pl.*$/) {next;}
	push(@supports,$filename);
}

#-----------------------------
# check all support.*.pl files
#-----------------------------
foreach $s (@supports) {
	%messages = undef;
	open(FILE, $s) || die "CANNOT OPEN $s\n";
	@file1 = <FILE>; close(FILE); $file = join("", @file1);
	eval($file);

	print "Checking $s ...\n";
	$ok = 1;
	foreach $m (keys %msgid) {
		if (exists $messages{$m}) {next;}
		print "**** WARNING **** : no translation for: $msgid{$m}\n";
		print "message = \"$m\"\n";
		$ok = 0;
	}
	if ($ok) {
		print "$s: check ok\n";
	}
}



