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

1.3       www         1: 
                      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: 
                     38: foreach my $fn (<*.pm>) {
1.3       www        39:     print "Synching: ".$fn."\n";
1.4       www        40:     my %lang=&readlexicon($fn);
                     41:     system ("cp $fn $fn.original");
1.2       www        42:     open(IN,$fn.'.original');
                     43:     open(OUT,'>'.$fn);
                     44:     my $found=0;
1.4       www        45:     while (<IN>) {
1.2       www        46: 	if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } 
                     47: 	print OUT $_;
                     48:     }
                     49:     if ($found) {
1.4       www        50: 	print OUT "\n\#SYNC ".localtime()."\n";
1.5     ! www        51: 	foreach my $key (sort keys %master) {
        !            52: 	    unless ($key) { next; }
        !            53: 	    unless ($lang{$key}) {
        !            54: 		my $comment='';
        !            55: 		my $copytrans=$key;
        !            56: 		foreach (reverse sort keys %lang) {
        !            57: 		    $copytrans=~s/$_/$lang{$_}/gsi;
        !            58: 		}
        !            59: 		if (lc($copytrans) ne lc($key)) {
        !            60: 		    $comment='# '.$copytrans;
        !            61:                 }
1.4       www        62: 		print OUT (<<ENDNEW);
1.5     ! www        63:    '$key'
        !            64: => '$key',
        !            65: $comment
1.4       www        66: ENDNEW
                     67: 	    }
                     68: 	}
1.2       www        69: 
                     70: 	print OUT "\n\#SYNCMARKER\n";
                     71: 	foreach (<IN>) {
                     72: 	    print OUT $_;
                     73: 	}
                     74:     }
                     75:     close (IN);
                     76:     close (OUT);
                     77: }

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