File:  [LON-CAPA] / loncom / localize / localize / synch.pl
Revision 1.5: download - view: text, annotated - select for diffs
Fri Sep 26 21:04:26 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Can now also add contents of a plain text file with phrases (separated by
newlines), and does provide copy/paste help with translations



sub readlexicon {
    my $fn=shift;
    open(IN,$fn);
    my %lexicon=();
    my $contents=join('',<IN>);
    close(IN);
    $contents=~s/package Apache\:[^\;]+//;
    $contents=~s/use base[^\;]+//;
    eval($contents.'; %lexicon=%Lexicon;');
    delete $lexicon{'_AUTO'};
    delete $lexicon{'char_encoding'};
    delete $lexicon{'language_code'};
    return %lexicon;
}

sub readnew {
    open(IN,'newphrases.txt');
    my %lexicon='';
    while (my $line=<IN>) {
	chomp($line);
	$lexicon{$line}=$line;
    }
    close(IN);
    return %lexicon;
}

# ==== Main Program

my %master=&readnew();

foreach (<*.pm>) {
    print "Reading: ".$_."\n";
    %master=(%master,&readlexicon($_));
}

foreach my $fn (<*.pm>) {
    print "Synching: ".$fn."\n";
    my %lang=&readlexicon($fn);
    system ("cp $fn $fn.original");
    open(IN,$fn.'.original');
    open(OUT,'>'.$fn);
    my $found=0;
    while (<IN>) {
	if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } 
	print OUT $_;
    }
    if ($found) {
	print OUT "\n\#SYNC ".localtime()."\n";
	foreach my $key (sort keys %master) {
	    unless ($key) { next; }
	    unless ($lang{$key}) {
		my $comment='';
		my $copytrans=$key;
		foreach (reverse sort keys %lang) {
		    $copytrans=~s/$_/$lang{$_}/gsi;
		}
		if (lc($copytrans) ne lc($key)) {
		    $comment='# '.$copytrans;
                }
		print OUT (<<ENDNEW);
   '$key'
=> '$key',
$comment
ENDNEW
	    }
	}

	print OUT "\n\#SYNCMARKER\n";
	foreach (<IN>) {
	    print OUT $_;
	}
    }
    close (IN);
    close (OUT);
}

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