#!/usr/bin/perl
# Test that each language file contains the same keys.

open( ENG, "../lib/gnump3d/lang/en.pm" ) or die "Cannot open en.pm - $!";
my @LINES = <ENG>;
close( ENG );


#
#  Keep a record of all translation keys.
#
my @KEYS = ();
foreach my $line ( @LINES )
{
    if ($line =~ /$TEXT\{([ \t]+)([a-zA-Z_]+)([ \t]+)\}/ )
    {
	push @KEYS, $2;
    }
}



#
#  Now make sure that each of the non-english language files contains
# all the keys.
#
foreach my $file ( glob( "../lib/gnump3d/lang/??.pm" ) )
{
	next if ( $file =~ /en\.pm$/ );
	&testFile( $file );
}
exit( 0 );



sub testFile( $ )
{
    my ( $lang ) = ( @_ );
    open( LANG, "<$lang" ) or die "Cannot open file $!";
    my @LANG = <LANG>;
    close( LANG );

    my $error = 0;

    my @TRAN = ( );

    foreach my $line ( @LANG )
    {
	if ($line =~ /$TEXT\{([ \t]+)([a-zA-Z_]+)([ \t]+)\}/ )
	{
	    push @TRAN, $2;
	}
    }

    my %seen; # lookup table
    my @lonly;# answer

    # build lookup table
    @seen{@TRAN} = ();

    foreach $item (@KEYS) {
	push(@lonly, $item) unless exists $seen{$item};
    }

    foreach my $i ( @lonly )
    {
	print "MISSING: $i\n";
	$error += 1;
    }

    if ( $error )
    {
	exit( 1 );
    }
       
}
