--- loncom/localize/localize/synch.pl 2008/07/10 19:10:26 1.8 +++ loncom/localize/localize/synch.pl 2009/01/13 12:31:13 1.9 @@ -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 readlexicon { sub readnew { open(IN,'newphrases.txt'); - my %lexicon=''; + my %lexicon=(); while (my $line=) { chomp($line); $lexicon{$line}=$line; @@ -26,17 +45,23 @@ sub readnew { 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=) { chomp($line); @@ -64,14 +89,16 @@ foreach my $fn (<*.pm>) { 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 @@ foreach my $fn (<*.pm>) { $num=''; } if ($key=~/\'/) { - $del='"'; + $dlm='"'; } else { - $del="'"; + $dlm="'"; } - print OUT (< $del$key$num$del, + if ($helper) { + print OUT (< $dlm$key$num$dlm, $comment + ENDNEW + } else { + print OUT (< $dlm$key$num$dlm, + +ENDNEW + } } }