summaryrefslogtreecommitdiff
path: root/tools/uplang
blob: 1cb3913c761f417b2a5b217554aae4d0a36bf287 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/perl

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

my %ids, @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'};
            $all{$set{'id'}, 'voice'}=$set{'voice'};

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

undef %set;
my $cblock = 1;
open(NEW, "<$ARGV[1]");
while(<NEW>) {
    $_ =~ s/\r//g;

    if($_ =~ /^ *\#/) {
        # comment
        if($_ !~ /^ *\#\#\#/) {
            # no special ### comment -> keep it
            if(!$cblock) {
                print "\n";
                $cblock = 1;
            }
            print $_;
        }
        next;
    }
    $cblock = 0;

    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 "\n### ".$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";
                print "desc: ".$all{$set{'id'}, 'desc'}."\n";
            }
            else {
                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";
                print "eng: ".$all{$set{'id'}, 'eng'}."\n";
            }
            else {
                print "eng: ".$set{'eng'}."\n";
            }

            if($set{'id'} =~ /^VOICE_/) { # voice only, compare desc:
                if($set{'desc'} ne $all{$set{'id'}, 'desc'}) {
                    print "### Voice only: description changed! Voice set to english. Previous voice was:\n",
                    "### ".$set{'voice'}."\n";
                    $set{'voice'} = $all{$set{'id'}, 'voice'};
                }
            }
            else { # standard entry, compare eng:
                if($set{'eng'} ne $all{$set{'id'}, 'eng'}
                   #only if either original or translated voice: is non-empty
                   and ($set{'voice'} !~ /^(\"\")? *$/
                        or $all{$set{'id'}, 'voice'} !~ /^(\"\")? *$/)) {
                    print "### English phrase was changed! Voice set to english. Previous voice was:\n",
                    "### ".$set{'voice'}."\n";
                    $set{'voice'} = $all{$set{'id'}, 'voice'};
                }
            }
            if($set{'voice'} =~ /^(\"\")? *$/
               and $all{$set{'id'}, 'voice'} !~ /^(\"\")? *$/) {
                print "### Voice not found in previous translation. Set to english.\n";
                $set{'voice'} = $all{$set{'id'}, 'voice'};
            }
            print "voice: ".$set{'voice'}."\n";

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

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

# output new phrases not already translated , in english.lang order
for(@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 "voice: ".$all{$id, 'voice'}."\n";
        print "new: \n";
    }
}