--- loncom/localize/localize/synch.pl 2003/09/26 18:39:48 1.4 +++ loncom/localize/localize/synch.pl 2008/07/10 19:10:26 1.8 @@ -1,4 +1,4 @@ - +#$numbered=1; sub readlexicon { my $fn=shift; @@ -15,12 +15,36 @@ sub readlexicon { return %lexicon; } -my %master=(); +sub readnew { + open(IN,'newphrases.txt'); + my %lexicon=''; + while (my $line=) { + chomp($line); + $lexicon{$line}=$line; + } + close(IN); + return %lexicon; +} + +# ==== Main Program + +my %master=&readnew(); + foreach (<*.pm>) { print "Reading: ".$_."\n"; %master=(%master,&readlexicon($_)); } +# Remove obsolete from synch + +open(IN,'removephrases.txt'); +while (my $line=) { + chomp($line); + delete $master{$line}; +} +close(IN); + + foreach my $fn (<*.pm>) { print "Synching: ".$fn."\n"; my %lang=&readlexicon($fn); @@ -28,18 +52,42 @@ foreach my $fn (<*.pm>) { open(IN,$fn.'.original'); open(OUT,'>'.$fn); my $found=0; + # Rebuild current translation file until SYNCMARKER: while () { if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } print OUT $_; } if ($found) { + $i=0; print OUT "\n\#SYNC ".localtime()."\n"; - foreach (sort keys %master) { - unless ($lang{$_}) { + # Sync master with current translation file: + foreach my $key (sort keys %master) { + unless ($key) { next; } + unless ($lang{$key}) { + my $comment=''; + my $copytrans=$key; + # Create comment based on already existing translations: + foreach (reverse sort keys %lang) { + $copytrans=~s/\Q$_\E/$lang{$_}/gsi; # \Q \E: escape meta characters + } + if (lc($copytrans) ne lc($key)) { + $comment='# '.$copytrans; + } + if ($numbered) { + $i++; + $num=' ('.$i.')'; + } else { + $num=''; + } + if ($key=~/\'/) { + $del='"'; + } else { + $del="'"; + } print OUT (< '$_', - + $del$key$del +=> $del$key$num$del, +$comment ENDNEW } }