[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lon-capa-cvs
Subject:    [LON-CAPA-cvs] cvs: loncom /localize/localize checkuntranslated.pl
From:       bisitz <bisitz () source ! lon-capa ! org>
Date:       2009-11-25 13:36:56
Message-ID: cvsbisitz1259156216 () cvsserver
[Download RAW message or body]

bisitz		Wed Nov 25 13:36:56 2009 EDT

  Added files:                 
    /loncom/localize/localize	checkuntranslated.pl 
  Log:
  New tool to find untranslated phrases in LON-CAPA translation files.
  Call: perl checkuntranslated.pl translationfile.pm
  All phrases which have an identical key and value are listed.
  Phrases which should have the translation identical to the original English phrase \
are not filtered and are listed, too.  
  

Index: loncom/localize/localize/checkuntranslated.pl
+++ loncom/localize/localize/checkuntranslated.pl
#!/usr/bin/perl
# The LearningOnline Network with CAPA
# $Id: checkuntranslated.pl,v 1.1 2009/11/25 13:36:56 bisitz Exp $

# 25.11.2009 Stefan Bisitz

use strict;
use warnings;

my $man = "
checkuntranslated - Checks if a translation file contains untranslated phrases. All \
untranslated phrases are listed.


SYNOPSIS:\tcheckuntranslated -h 
\t\tcheckuntranslated FILE

OPTIONS:
-h\t\tDisplay this help and exit.

";

my $filename; 
die "Use option -h for help.\n" unless exists $ARGV[0];
#analyze options
if ( $ARGV[0] =~ m/^\s*-h/ ) {
	print $man;
	exit();
} else {
	$filename = ($ARGV[0]);
	die "$filename is not a file.\n" unless -f $ARGV[0];
}


# ----------------------------------------------------------------
# Start Analysis
print "checkuntranslated is searching for untranslated phrases in $filename...\n";

# Read translation file row by row and try to find matching keys and values.
# It is assumed that all keys are followed by a value using the following syntax:
#    'key'
# => 'value',
#
# Optional comment rows and/or comments at the end of each row
# and white spaces are allowed and will be ignored.
#
# Compare key and value: identical? -> untranslated!
my $counter = 0;
my $line;
my $key = '';
my $mode = 'key';
open( FH, "<", $filename ) or die "$filename cannot be opened\n";
while ( !eof(FH) ) {
    $line = readline(FH);
    # Ignore comments
    next if $line=~/^\s*#/;
    # Key?
    if ($mode eq 'key') {
        # Search for key
        if ($line =~ m/^\s+["'](.*)["']/) {
            $key = $1;
            $mode = 'value';
        }
    # Value?
    } else { # $mode eq 'value'
        # Search for value
        if ($line =~ m/^\s*=>\s*["'](.*)["']/) {
            if ($key eq $1) { # key = value?
                print $key."\n";
                $counter++;
            }
            $mode = 'key';
        }
    }
}
close(FH);


# Display summary message
if ($counter == 0) {
    print "Be happy - No untranslated phrases found.\n";
} else {
    print "Found $counter untranslated phrases in $filename.\n";
    print "Please ignore all phrases which should have the same translation as the \
English phrase.\n"; }

# ----------------------------------------------------------------



_______________________________________________
LON-CAPA-cvs mailing list
LON-CAPA-cvs@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic