File:  [LON-CAPA] / loncom / localize / localize / checkuntranslated.pl
Revision 1.1: download - view: text, annotated - select for diffs
Wed Nov 25 13:36:56 2009 UTC (14 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_9_99_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
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.

#!/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";
}

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


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>