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

bisitz lon-capa-cvs-allow@mail.lon-capa.org
Thu, 10 Jul 2008 19:10:26 -0000


bisitz		Thu Jul 10 15:10:26 2008 EDT

  Modified files:              
    /loncom/localize/localize	synch.pl 
  Log:
  - Added some comments to explain what's going on.
  - Corrected matching operation for the search of already existing translations.
  Now, words aren't considered as regular expressions anymore (which could have caused the script aborted) and execution time is much shorter now.
  Execution works fine with UTF-8 encoded language files.
  
  Thanks to Stefan Dröschler for his help!
  Nevertheless, more testing is recommended.
  
  
Index: loncom/localize/localize/synch.pl
diff -u loncom/localize/localize/synch.pl:1.7 loncom/localize/localize/synch.pl:1.8
--- loncom/localize/localize/synch.pl:1.7	Thu Nov 27 21:12:05 2003
+++ loncom/localize/localize/synch.pl	Thu Jul 10 15:10:26 2008
@@ -52,6 +52,7 @@
     open(IN,$fn.'.original');
     open(OUT,'>'.$fn);
     my $found=0;
+    # Rebuild current translation file until SYNCMARKER:
     while (<IN>) {
 	if ($_=~/\#\s*SYNCMARKER/) { $found=1; last; } 
 	print OUT $_;
@@ -59,13 +60,15 @@
     if ($found) {
 	$i=0;
 	print OUT "\n\#SYNC ".localtime()."\n";
+        # 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/$_/$lang{$_}/gsi;
+		    $copytrans=~s/\Q$_\E/$lang{$_}/gsi; # \Q \E: escape meta characters
 		}
 		if (lc($copytrans) ne lc($key)) {
 		    $comment='# '.$copytrans;