File:  [LON-CAPA] / loncom / localize / localize / synch.pl
Revision 1.6: download - view: text, annotated - select for diffs
Tue Oct 14 17:34:04 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: version_1_0_99, HEAD
Remove obsolete phrases from synch.

    1: 
    2: 
    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: 
   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: 
   33: foreach (<*.pm>) {
   34:     print "Reading: ".$_."\n";
   35:     %master=(%master,&readlexicon($_));
   36: }
   37: 
   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: 
   48: foreach my $fn (<*.pm>) {
   49:     print "Synching: ".$fn."\n";
   50:     my %lang=&readlexicon($fn);
   51:     system ("cp $fn $fn.original");
   52:     open(IN,$fn.'.original');
   53:     open(OUT,'>'.$fn);
   54:     my $found=0;
   55:     while (<IN>) {
   56: 	if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } 
   57: 	print OUT $_;
   58:     }
   59:     if ($found) {
   60: 	print OUT "\n\#SYNC ".localtime()."\n";
   61: 	foreach my $key (sort keys %master) {
   62: 	    unless ($key) { next; }
   63: 	    unless ($lang{$key}) {
   64: 		my $comment='';
   65: 		my $copytrans=$key;
   66: 		foreach (reverse sort keys %lang) {
   67: 		    $copytrans=~s/$_/$lang{$_}/gsi;
   68: 		}
   69: 		if (lc($copytrans) ne lc($key)) {
   70: 		    $comment='# '.$copytrans;
   71:                 }
   72: 		print OUT (<<ENDNEW);
   73:    '$key'
   74: => '$key',
   75: $comment
   76: ENDNEW
   77: 	    }
   78: 	}
   79: 
   80: 	print OUT "\n\#SYNCMARKER\n";
   81: 	foreach (<IN>) {
   82: 	    print OUT $_;
   83: 	}
   84:     }
   85:     close (IN);
   86:     close (OUT);
   87: }

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