Don't die on opendir() failure. Index .mp2 files too.
[kugel-rb.git] / tools / uplang
blob4e581f600e8c154c59aecef18504f4938dd4c8f5
1 #!/usr/bin/perl
3 if(!$ARGV[0]) {
4 print <<MOO
5 Usage: lang.pl <english file> <translated file>
6 MOO
8 exit;
11 my %ids;
12 open(ENG, "<$ARGV[0]");
13 while(<ENG>) {
14 if($_ =~ /^ *\#/) {
15 # comment
16 next;
18 $_ =~ s/\r//g;
19 if($_ =~ /^ *([a-z]+): *(.*)/) {
20 ($var, $value) = ($1, $2);
21 # print "$var => $value\n";
23 $set{$var} = $value;
25 if($var eq "new") {
26 # the last one for a single phrase
27 $all{$set{'id'}, 'desc'}=$set{'desc'};
28 $all{$set{'id'}, 'eng'}=$set{'eng'};
29 $all{$set{'id'}, 'voice'}=$set{'voice'};
31 $ids{$set{'id'}}=1;
32 undef %set;
36 close(ENG);
38 undef %set;
39 open(NEW, "<$ARGV[1]");
40 while(<NEW>) {
41 if($_ =~ /^ *\#/) {
42 # comment
43 next;
45 $_ =~ s/\r//g;
47 if($_ =~ /^ *([a-z]+): *(.*)/) {
48 ($var, $value) = ($1, $2);
50 $set{$var} = $value;
52 if($var eq "new") {
53 # the last one for a single phrase
55 if(!$ids{$set{'id'}}) {
56 print "### ".$set{'id'}." was not found in the english file!\n";
57 next;
60 print "\nid: ".$set{'id'}."\n";
62 if($set{'desc'} ne $all{$set{'id'}, 'desc'}) {
63 print "### Description changed! Previous description was:\n",
64 "### \"".$set{'desc'}."\"\n";
65 $set{'desc'} = $all{$set{'id'}, 'desc'};
67 print "desc: ".$set{'desc'}."\n";
69 if($set{'eng'} ne $all{$set{'id'}, 'eng'}) {
70 print "### English phrase was changed! Previous translation was made on:\n",
71 "### ".$set{'eng'}."\n";
72 $set{'eng'} = $all{$set{'id'}, 'eng'};
74 print "eng: ".$set{'eng'}."\n";
76 if($set{'voice'} ne $all{$set{'id'}, 'voice'}) {
77 print "### Voice string was changed! Previous version was:\n",
78 "### ".$set{'voice'}."\n";
79 $set{'voice'} = $all{$set{'id'}, 'voice'};
81 print "voice: ".$set{'voice'}."\n";
83 print "new: ".$set{'new'}."\n";
85 $ids{$set{'id'}}=0;
89 close(NEW);
91 # output new phrases not already translated
92 for(sort keys %ids) {
93 if($ids{$_}) {
94 my $id=$_;
95 print "\nid: $_\n";
96 print "desc: ".$all{$id, 'desc'}."\n";
97 print "eng: ".$all{$id, 'eng'}."\n";
98 print "### Not previously translated\n";
99 print "new: \n";