source: main/tags/2.51-jcdl/gsdl/macros/Chktrans.pl@ 25200

Last change on this file since 25200 was 3422, checked in by jrm21, 22 years ago

Added new languages to be checked.

Cleaned up reg exps as some whitespace isn't necessary.

Use package names as well, as some macros are duplicated in different
packages.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1#! /usr/bin/perl -w
2
3use strict;
4
5my @languages = ("chinese", "french", "german", "maori", "spanish", "turkish");
6
7print "
8Chktrans.pl
9
10This file checks english.dm and english2.dm against
11translations 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
17Current languages:
18";
19
20foreach my $l (@languages) {
21 print " $l\n";
22}
23
24print "\nReading english.dm\n";
25
26open(E, "<english.dm");
27
28my $line;
29my $count = 0;
30my %macro;
31my $package="";
32while (<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
46print "Read $count macros.\n\n";
47
48my $file;
49
50foreach 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}
Note: See TracBrowser for help on using the repository browser.