#!/usr/bin/perl

my $pofile = $ARGV[0];
my $dtdfile = $ARGV[1];

#First PO file

open (FILE, $pofile) || die "Cannot open $pofile!";

my $switch = 0;
my %pofile;
my $stringi;
my $stringf;

while (<FILE>) {

	if ($_=~/^\#\:\s+(\S+)/) {

		$stringi = $1;	
		$switch++;
	}

	if (($switch > 0) and ($_=~/^msgstr\s+\"(.*)\"\s*$/)){
		
		$stringf = $1;
		$switch = 0;
		$pofile{$stringi} = $stringf;

	}
}

close (FILE);

#Then DTD file

open (FILE, $dtdfile) || die "Cannot open $dtdfile!";

while (<FILE>) {

	if ($_=~/^\<\!ENTITY\s+(\S+)/) {

		print "<!ENTITY $1\t\"$pofile{$1}\">\n";
	}

	else {print;}
}

close (FILE);


