summaryrefslogtreecommitdiffstats
path: root/tools/uplang
blob: 41730fb3d324c54451e1c9a33c7c161b8a3e09f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl

if(!$ARGV[0]) {
    print <<MOO
Usage: lang.pl <english file> <translated file>
MOO
;
    exit;
}

my %ids;
open(ENG, "<$ARGV[0]");
while(<ENG>) {
    if($_ =~ /^ *\#/) {
        # comment
        next;
    }
    $_ =~ s/\r//g;
    if($_ =~ /^ *([a-z]+): *(.*)/) {
        ($var, $value) = ($1, $2);
  #      print "$var => $value\n";

        $set{$var} = $value;

        if($var eq "new") {
            # the last one for a single phrase
            $all{$set{'id'}, 'desc'}=$set{'desc'};
            $all{$set{'id'}, 'eng'}=$set{'eng'};

            $ids{$set{'id'}}=1;
            undef %set;
        }
    }
}
close(ENG);

undef %set;
open(NEW, "<$ARGV[1]");
while(<NEW>) {
    if($_ =~ /^ *\#/) {
        # comment
        next;
    }
    $_ =~ s/\r//g;

    if($_ =~ /^ *([a-z]+): *(.*)/) {
        ($var, $value) = ($1, $2);

        $set{$var} = $value;

        if($var eq "new") {
            # the last one for a single phrase

            if(!$ids{$set{'id'}}) {
                print "### ".$set{'id'}." was not found in the english file!\n";
                next;
            }

            print "\nid: ".$set{'id'}."\n";


            if($set{'desc'} ne $all{$set{'id'}, 'desc'}) {
                print "### Description changed! Previous description was:\n",
                "### \"".$set{'desc'}."\"\n";
                $set{'desc'} = $all{$set{'id'}, 'desc'};
            }

            print "desc: ".$set{'desc'}."\n";
            if($set{'eng'} ne $all{$set{'id'}, 'eng'}) {
                print "### English phrase was changed! Previous translation was made on:\n",
                "### ".$set{'eng'}."\n";
                $set{'eng'} = $all{$set{'id'}, 'eng'};
            }
            print "eng: ".$set{'eng'}."\n";
            print "new: ".$set{'new'}."\n";

            $ids{$set{'id'}}=0;
        }
    }
}
close(NEW);

# output new phrases not already translated
for(sort keys %ids) {
    if($ids{$_}) {
        my $id=$_;
        print "\nid: $_\n";
        print "desc: ".$all{$id, 'desc'}."\n";
        print "eng: ".$all{$id, 'eng'}."\n";
        print "### Not previously translated\n";
        print "new: \n";
    }
}