[LON-CAPA-cvs] cvs: loncom /localize/localize synch.pl

bisitz bisitz@source.lon-capa.org
Tue, 13 Jan 2009 16:46:35 -0000


bisitz		Tue Jan 13 16:46:35 2009 EDT

  Modified files:              
    /loncom/localize/localize	synch.pl 
  Log:
  - Added more comments to explain what's going on
  - Added more output to show on the screen which steps were executed
  - Added debug mode which allows to display the data for debugging purposes
  
  
  
Index: loncom/localize/localize/synch.pl
diff -u loncom/localize/localize/synch.pl:1.9 loncom/localize/localize/synch.pl:1.10
--- loncom/localize/localize/synch.pl:1.9	Tue Jan 13 12:31:13 2009
+++ loncom/localize/localize/synch.pl	Tue Jan 13 16:46:35 2009
@@ -15,6 +15,10 @@
 # 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 @@
     while (my $line=<IN>) {
 	chomp($line);
 	$lexicon{$line}=$line;
+        print "    New entry: $line\n" if $debug;
     }
     close(IN);
     return %lexicon;
@@ -48,40 +53,61 @@
 
 # ----------------------------------------------------------------
 # ----- 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=<IN>) {
     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 (<IN>) {
 	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 $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 @@
     }
     close (IN);
     close (OUT);
+    print"ok.\n";
 }
+print "Synchronization completed.\n";
+