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

bisitz bisitz@source.lon-capa.org
Tue, 13 Jan 2009 12:31:13 -0000


bisitz		Tue Jan 13 12:31:13 2009 EDT

  Modified files:              
    /loncom/localize/localize	synch.pl 
  Log:
  - Changed to strict mode and added needed declarations
  - Added more comments
  - Added proper configuration to configure numbering and translation help comments
  - Disabled translation help comments by default
  - Changed delimiter variable name from del to dlm (del=delete?!?)
  
  Note:
  Script seems to add new translations from newphrases.txt even if they already existed in the translation file.
  
  
  
Index: loncom/localize/localize/synch.pl
diff -u loncom/localize/localize/synch.pl:1.8 loncom/localize/localize/synch.pl:1.9
--- loncom/localize/localize/synch.pl:1.8	Thu Jul 10 19:10:26 2008
+++ loncom/localize/localize/synch.pl	Tue Jan 13 12:31:13 2009
@@ -1,4 +1,23 @@
-#$numbered=1;
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# ----------------------------------------------------------------
+# Configuration
+
+#  Add a ascending number after each new translation
+# 1: add, 0: don't add
+my $numbered=0;
+
+# Add a comment after each new translation.
+# This comment contains a combination of translations which are build by using already existing translations.
+# 1: add, 0: don't add
+my $helper=0; 
+
+
+# ----------------------------------------------------------------
+# ----- Sub Routines -----
 
 sub readlexicon {
     my $fn=shift;
@@ -17,7 +36,7 @@
 
 sub readnew {
     open(IN,'newphrases.txt');
-    my %lexicon='';
+    my %lexicon=();
     while (my $line=<IN>) {
 	chomp($line);
 	$lexicon{$line}=$line;
@@ -26,17 +45,23 @@
     return %lexicon;
 }
 
-# ==== Main Program
 
-my %master=&readnew();
+# ----------------------------------------------------------------
+# ----- Main Program -----
 
+my %master=&readnew();
+my $i;
+my $num;
+my $dlm;
+my $comment;
+  
 foreach (<*.pm>) {
     print "Reading: ".$_."\n";
     %master=(%master,&readlexicon($_));
 }
 
 # Remove obsolete from synch
-
+# Ignore all phrases in removephrases.txt for current synchronization
 open(IN,'removephrases.txt');
 while (my $line=<IN>) {
     chomp($line);
@@ -64,14 +89,16 @@
 	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 ($helper) {
+		    $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++;
@@ -80,15 +107,24 @@
 		    $num='';
 		}
 		if ($key=~/\'/) {
-		    $del='"';
+		    $dlm='"';
 		} else {
-		    $del="'";
+		    $dlm="'";
 		}
-		print OUT (<<ENDNEW);
-   $del$key$del
-=> $del$key$num$del,
+		if ($helper) {
+		    print OUT (<<ENDNEW);
+   $dlm$key$dlm
+=> $dlm$key$num$dlm,
 $comment
+
 ENDNEW
+		} else {
+		    print OUT (<<ENDNEW);
+   $dlm$key$dlm
+=> $dlm$key$num$dlm,
+
+ENDNEW
+		}
 	    }
 	}