--- loncom/localize/localize/synch.pl 2009/01/13 12:31:13 1.9 +++ loncom/localize/localize/synch.pl 2009/01/13 16:46:35 1.10 @@ -15,6 +15,10 @@ my $numbered=0; # 1: add, 0: don't add my $helper=0; +# Debug Mode +# Displays additional output for debugging purposes +my $debug=0; + # ---------------------------------------------------------------- # ----- Sub Routines ----- @@ -40,6 +44,7 @@ sub readnew { while (my $line=) { chomp($line); $lexicon{$line}=$line; + print " New entry: $line\n" if $debug; } close(IN); return %lexicon; @@ -48,40 +53,61 @@ sub readnew { # ---------------------------------------------------------------- # ----- Main Program ----- - -my %master=&readnew(); my $i; my $num; my $dlm; my $comment; + +print "*** Synching Translation Files ***\n"; + +# Create master hash for the entire set of all translations +print "Building master hash:\n"; + +# Initialy fill master hash with phrases which are additionally needed/wanted. +print " Adding new phrases... "; +my %master=&readnew(); +print "ok.\n"; +# Add all the different phrases of all translation files to master hash foreach (<*.pm>) { - print "Reading: ".$_."\n"; + print " Reading ".$_." ... "; %master=(%master,&readlexicon($_)); + print "ok.\n"; } -# Remove obsolete from synch -# Ignore all phrases in removephrases.txt for current synchronization +# Ignore all phrases found in removephrases.txt for current synchronization. +# These phrases would not be removed from a translation file, if they existed in the file. +# But the phrases will not be added to any translation file even if they were missing in it. +# Remove these obsolete phrases from master hash +print " Removing obsolete phrases... "; open(IN,'removephrases.txt'); while (my $line=) { chomp($line); delete $master{$line}; } close(IN); +print "ok.\n"; +print "Synchronization:\n"; foreach my $fn (<*.pm>) { - print "Synching: ".$fn."\n"; + print " Synching ".$fn." ... "; + # Build hash with all translations of current translation file my %lang=&readlexicon($fn); + # Copy current translation file so that the old file could be overwritten with the new content + # while the copy is used to read from. system ("cp $fn $fn.original"); open(IN,$fn.'.original'); + # Rebuild current translation file + # by writing all exisiting entries until SYNCMARKER open(OUT,'>'.$fn); my $found=0; - # Rebuild current translation file until SYNCMARKER: while () { if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } print OUT $_; } + # Append missing phrases to new version of current translation file + # by synching old version of current translation file with master hash if ($found) { $i=0; print OUT "\n\#SYNC ".localtime()."\n"; @@ -89,6 +115,7 @@ foreach my $fn (<*.pm>) { foreach my $key (sort keys %master) { unless ($key) { next; } unless ($lang{$key}) { + print " Found to be added: $key\n" if $debug; if ($helper) { $comment=''; my $copytrans=$key; @@ -135,4 +162,7 @@ ENDNEW } close (IN); close (OUT); + print"ok.\n"; } +print "Synchronization completed.\n"; +