Annotation of loncom/localize/localize/synch.pl, revision 1.7

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.4       www        55:     while (<IN>) {
1.2       www        56: 	if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } 
                     57: 	print OUT $_;
                     58:     }
                     59:     if ($found) {
1.7     ! www        60: 	$i=0;
1.4       www        61: 	print OUT "\n\#SYNC ".localtime()."\n";
1.5       www        62: 	foreach my $key (sort keys %master) {
                     63: 	    unless ($key) { next; }
                     64: 	    unless ($lang{$key}) {
                     65: 		my $comment='';
                     66: 		my $copytrans=$key;
                     67: 		foreach (reverse sort keys %lang) {
                     68: 		    $copytrans=~s/$_/$lang{$_}/gsi;
                     69: 		}
                     70: 		if (lc($copytrans) ne lc($key)) {
                     71: 		    $comment='# '.$copytrans;
                     72:                 }
1.7     ! www        73: 		if ($numbered) {
        !            74: 		    $i++;
        !            75: 		    $num=' ('.$i.')';
        !            76: 		} else {
        !            77: 		    $num='';
        !            78: 		}
        !            79: 		if ($key=~/\'/) {
        !            80: 		    $del='"';
        !            81: 		} else {
        !            82: 		    $del="'";
        !            83: 		}
1.4       www        84: 		print OUT (<<ENDNEW);
1.7     ! www        85:    $del$key$del
        !            86: => $del$key$num$del,
1.5       www        87: $comment
1.4       www        88: ENDNEW
                     89: 	    }
                     90: 	}
1.2       www        91: 
                     92: 	print OUT "\n\#SYNCMARKER\n";
                     93: 	foreach (<IN>) {
                     94: 	    print OUT $_;
                     95: 	}
                     96:     }
                     97:     close (IN);
                     98:     close (OUT);
                     99: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>