[LON-CAPA-cvs] cvs: loncom /localize/localize mtarguments
bisitz
bisitz@source.lon-capa.org
Tue, 13 Jan 2009 12:42:55 -0000
bisitz Tue Jan 13 12:42:55 2009 EDT
Modified files:
/loncom/localize/localize mtarguments
Log:
- Don't rewrite file but append new entries to newtranslations.txt. Keep exisiting entries, e.g. additions from other scripts. Changed documentation accordingly.
- Display start message
- Display of file written info after actual closure now.
- Bugfix: Don't write " or ' at beginning and end of each entry to newphrases.txt anymore. Needed for synch.pl.
- Display info about total amount of found entries.
Index: loncom/localize/localize/mtarguments
diff -u loncom/localize/localize/mtarguments:1.1 loncom/localize/localize/mtarguments:1.2
--- loncom/localize/localize/mtarguments:1.1 Tue Dec 30 20:45:38 2008
+++ loncom/localize/localize/mtarguments Tue Jan 13 12:42:55 2009
@@ -3,8 +3,8 @@
use strict;
use warnings;
-my $man =
-"mtarguments - searches a single file or all files in a directory and its subdirectory for occurence of calls to the subroutine &mt. Arguments of &mt are written to the file newphrases.txt. In addition, arguments and locations where such calls appear are written to the file newphraseslocations.txt.
+my $man = "
+mtarguments - searches a single file or all files in a directory and its subdirectory for occurence of calls to the subroutine &mt. Arguments of &mt are appended to the file newphrases.txt. In addition, arguments and locations where such calls appear are written to the file newphraseslocations.txt.
mtarguments is particularly useful for detecting new arguments to mt which consequently need to be translated for non-English users of loncapa. Detection of such arguments is most easily done by comparing newphrases.txt with an earlier version of this file via unix's diff. Detected new phrases can then be incorporated into localization files using sync.pl.
@@ -36,6 +36,10 @@
die "$files[0] is not a file.\n" unless -f $ARGV[0];
}
+
+# Start Analysis
+print "mtarguments is searching...\n";
+
# expression for nested parantheses
my $rep;
$rep = qr{ \( ((?: (?> [^()]+ ) | (??{ $rep }) )*) \) }x;
@@ -70,18 +74,26 @@
}
#write outputfiles
-open(NP,'>','newphrases.txt');
+open(NP,'>>','newphrases.txt'); # Keep existing entries and append new phrases. synch.pl will care about entries which occur more than one time.
open(NPL,'>','newphraseslocations.txt');
+my $counter=0;
my $warnings=0;
+my $exprNP="";
foreach my $expr (sort keys %mtArgInFile){
- print NP "$expr\n";
+ $exprNP=$expr;
+ $exprNP=~s/^["'](.*)["']$/$1/; # Remove " and ' at beginning and end for newphrases.txt
+ print NP "$exprNP\n";
print NPL "$expr\n\tFOUND IN: $mtArgInFile{$expr}\n";
+ $counter++;
$warnings++ if($expr=~/\$|@|&/);
}
-close(NPL);
close(NP);
-print "Wrote newphrases.txt.\nWrote newphraseslocations.txt.\n";
-print "WARNING: Found $warnings case(s) where argument of &mt is a perl variable.\n" if $warnings;
+print "Wrote newphrases.txt.\n";
+close(NPL);
+print "Wrote newphraseslocations.txt.\n";
+
+print "WARNING: Found $warnings case(s) where argument of &mt contains a perl variable.\n" if $warnings;
+print "Found $counter new phrases.\n";
sub recursivefilelist {
my ($currentpath) = @_;