1 | #! /usr/bin/perl -w
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 |
|
---|
5 | my @languages = ("chinese", "french", "german", "maori", "spanish", "turkish");
|
---|
6 |
|
---|
7 | print "
|
---|
8 | Chktrans.pl
|
---|
9 |
|
---|
10 | This file checks english.dm and english2.dm against
|
---|
11 | translations made in other languages. It outputs
|
---|
12 | whether the translation exists in each language,
|
---|
13 | what macros override the English (default) macros
|
---|
14 | what macros have not been translated,
|
---|
15 | what additional macros exist.
|
---|
16 |
|
---|
17 | Current languages:
|
---|
18 | ";
|
---|
19 |
|
---|
20 | foreach my $l (@languages) {
|
---|
21 | print " $l\n";
|
---|
22 | }
|
---|
23 |
|
---|
24 | print "\nReading english.dm\n";
|
---|
25 |
|
---|
26 | open(E, "<english.dm");
|
---|
27 |
|
---|
28 | my $line;
|
---|
29 | my $count = 0;
|
---|
30 | my %macro;
|
---|
31 | my $package="";
|
---|
32 | while (<E>) {
|
---|
33 | chomp;
|
---|
34 | $line = $_;
|
---|
35 | if ($line =~ /^package\s+(\w+)/) {
|
---|
36 | $package="$1:";
|
---|
37 | next;
|
---|
38 | }
|
---|
39 | next unless ($line =~ /^_\w+_ *\{/);
|
---|
40 | # don't necessarily have space between macro and { - eg _macro_{content}
|
---|
41 | $line =~ s/_\s*\{.*/_/;
|
---|
42 | $macro{"$package$line"} = 1;
|
---|
43 | $count++;
|
---|
44 | }
|
---|
45 |
|
---|
46 | print "Read $count macros.\n\n";
|
---|
47 |
|
---|
48 | my $file;
|
---|
49 |
|
---|
50 | foreach my $l (@languages) {
|
---|
51 | $file = "$l.dm";
|
---|
52 |
|
---|
53 | print "=============================================\nLanguage: $l\n";
|
---|
54 |
|
---|
55 | # make sure thwere is a translation for the language
|
---|
56 | if (!-e "$file") {
|
---|
57 | print "$file doesn't exist\n\n";
|
---|
58 | next;
|
---|
59 | }
|
---|
60 |
|
---|
61 | # read the macros in this language
|
---|
62 | print "Reading $file\n";
|
---|
63 | open(L, "<$file");
|
---|
64 | my (%lm, %lmnew, %lr, %lrnew);
|
---|
65 | my $lc = 0;
|
---|
66 | $package = "";
|
---|
67 | while (<L>) {
|
---|
68 | chomp;
|
---|
69 | $line = $_;
|
---|
70 |
|
---|
71 | if ($line =~ /^package\s+(\w+)/) {
|
---|
72 | $package="$1:";
|
---|
73 | next;
|
---|
74 | }
|
---|
75 | next unless ($line =~ /^_\w+_/);
|
---|
76 | next unless ($line =~ /\{/);
|
---|
77 |
|
---|
78 | $line =~ s/_\s*\{.*/_/;
|
---|
79 | # There are four types of macro, the combos of:
|
---|
80 | # With or without macro country code
|
---|
81 | # Present or not present in %macro
|
---|
82 | if ($line =~ /\[/) {
|
---|
83 | # don't need a space between macro and arg (_macro_[args])
|
---|
84 | # $line =~ s/\s.*//;
|
---|
85 | $line =~ s/\s*\[.*//;
|
---|
86 | my $thismacro="$package$line";
|
---|
87 | if (defined($macro{$thismacro})) {
|
---|
88 | $lm{$thismacro} = $thismacro;
|
---|
89 | } else {
|
---|
90 | $lmnew{$thismacro} = $thismacro;
|
---|
91 | }
|
---|
92 | } else {
|
---|
93 | my $thismacro="$package$line";
|
---|
94 | if (defined($macro{$thismacro})) {
|
---|
95 | $lr{$thismacro} = $thismacro;
|
---|
96 | } else {
|
---|
97 | $lrnew{$thismacro} = $thismacro;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | $lc++;
|
---|
101 | }
|
---|
102 | close L;
|
---|
103 | print "Read $lc macros.\n\n";
|
---|
104 |
|
---|
105 | # How many macros operate correctly
|
---|
106 | print (scalar keys %lm);
|
---|
107 | print" macros are translated from english to $l\n\n";
|
---|
108 |
|
---|
109 | # What are the new macros?
|
---|
110 | if (scalar keys %lmnew) {
|
---|
111 | print (scalar keys %lmnew);
|
---|
112 | print" macros are new $l macros with no eqivalents in english.dm:\n";
|
---|
113 | foreach my $m (sort (keys (%lmnew))) {
|
---|
114 | print "$m ";
|
---|
115 | }
|
---|
116 | print "\n\n";
|
---|
117 | }
|
---|
118 |
|
---|
119 | # What are the new macros?
|
---|
120 | if (scalar keys %lrnew) {
|
---|
121 | print (scalar keys %lrnew);
|
---|
122 | print" macros are new macros in english that do not appear in english.dm:\n";
|
---|
123 | foreach my $m (sort (keys (%lrnew))) {
|
---|
124 | print "$m ";
|
---|
125 | }
|
---|
126 | print "\n\n";
|
---|
127 | }
|
---|
128 |
|
---|
129 | # Which languages override their english counterparts?
|
---|
130 | if (scalar keys %lr) {
|
---|
131 | print (scalar keys %lr);
|
---|
132 | print" macros override equivalents in english.dm ";
|
---|
133 | print"(It doesn't matter if you override macros like widths, heights, and URLs):\n";
|
---|
134 | foreach my $m (sort (keys (%lr))) {
|
---|
135 | print "$m ";
|
---|
136 | }
|
---|
137 | print "\n\n";
|
---|
138 | }
|
---|
139 |
|
---|
140 | # Which macros in english.dm do not appear in the newfile?
|
---|
141 | my @missing = ();
|
---|
142 | foreach my $m (sort (keys (%macro))) {
|
---|
143 | next if defined($lm{$m});
|
---|
144 | push @missing, $m;
|
---|
145 | }
|
---|
146 | if (scalar @missing) {
|
---|
147 | print (scalar @missing);
|
---|
148 | print " macros in english.dm have no entry in $l.dm:\n";
|
---|
149 | foreach my $m (sort @missing) {
|
---|
150 | print "$m ";
|
---|
151 | }
|
---|
152 | print "\n\n";
|
---|
153 | }
|
---|
154 |
|
---|
155 | print "\n";
|
---|
156 |
|
---|
157 | }
|
---|