Annotation of loncom/localize/localize/synch.pl, revision 1.8
1.7 www 1: #$numbered=1;
1.3 www 2:
1.1 www 3: sub readlexicon {
4: my $fn=shift;
5: open(IN,$fn);
6: my %lexicon=();
7: my $contents=join('',<IN>);
8: close(IN);
9: $contents=~s/package Apache\:[^\;]+//;
10: $contents=~s/use base[^\;]+//;
11: eval($contents.'; %lexicon=%Lexicon;');
12: delete $lexicon{'_AUTO'};
13: delete $lexicon{'char_encoding'};
14: delete $lexicon{'language_code'};
15: return %lexicon;
16: }
17:
1.5 www 18: sub readnew {
19: open(IN,'newphrases.txt');
20: my %lexicon='';
21: while (my $line=<IN>) {
22: chomp($line);
23: $lexicon{$line}=$line;
24: }
25: close(IN);
26: return %lexicon;
27: }
28:
29: # ==== Main Program
30:
31: my %master=&readnew();
32:
1.2 www 33: foreach (<*.pm>) {
34: print "Reading: ".$_."\n";
35: %master=(%master,&readlexicon($_));
36: }
1.4 www 37:
1.6 www 38: # Remove obsolete from synch
39:
40: open(IN,'removephrases.txt');
41: while (my $line=<IN>) {
42: chomp($line);
43: delete $master{$line};
44: }
45: close(IN);
46:
47:
1.4 www 48: foreach my $fn (<*.pm>) {
1.3 www 49: print "Synching: ".$fn."\n";
1.4 www 50: my %lang=&readlexicon($fn);
51: system ("cp $fn $fn.original");
1.2 www 52: open(IN,$fn.'.original');
53: open(OUT,'>'.$fn);
54: my $found=0;
1.8 ! bisitz 55: # Rebuild current translation file until SYNCMARKER:
1.4 www 56: while (<IN>) {
1.2 www 57: if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; }
58: print OUT $_;
59: }
60: if ($found) {
1.7 www 61: $i=0;
1.4 www 62: print OUT "\n\#SYNC ".localtime()."\n";
1.8 ! bisitz 63: # Sync master with current translation file:
1.5 www 64: foreach my $key (sort keys %master) {
65: unless ($key) { next; }
66: unless ($lang{$key}) {
67: my $comment='';
68: my $copytrans=$key;
1.8 ! bisitz 69: # Create comment based on already existing translations:
1.5 www 70: foreach (reverse sort keys %lang) {
1.8 ! bisitz 71: $copytrans=~s/\Q$_\E/$lang{$_}/gsi; # \Q \E: escape meta characters
1.5 www 72: }
73: if (lc($copytrans) ne lc($key)) {
74: $comment='# '.$copytrans;
75: }
1.7 www 76: if ($numbered) {
77: $i++;
78: $num=' ('.$i.')';
79: } else {
80: $num='';
81: }
82: if ($key=~/\'/) {
83: $del='"';
84: } else {
85: $del="'";
86: }
1.4 www 87: print OUT (<<ENDNEW);
1.7 www 88: $del$key$del
89: => $del$key$num$del,
1.5 www 90: $comment
1.4 www 91: ENDNEW
92: }
93: }
1.2 www 94:
95: print OUT "\n\#SYNCMARKER\n";
96: foreach (<IN>) {
97: print OUT $_;
98: }
99: }
100: close (IN);
101: close (OUT);
102: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>