Annotation of loncom/localize/localize/checkuntranslated.pl, revision 1.1
1.1 ! bisitz 1: #!/usr/bin/perl
! 2: # The LearningOnline Network with CAPA
! 3: # $Id: checkuntranslated.pl,v 1.1 2009/11/25 15:10:22 bisitz Exp $
! 4:
! 5: # 25.11.2009 Stefan Bisitz
! 6:
! 7: use strict;
! 8: use warnings;
! 9:
! 10: my $man = "
! 11: checkuntranslated - Checks if a translation file contains untranslated phrases. All untranslated phrases are listed.
! 12:
! 13:
! 14: SYNOPSIS:\tcheckuntranslated -h
! 15: \t\tcheckuntranslated FILE
! 16:
! 17: OPTIONS:
! 18: -h\t\tDisplay this help and exit.
! 19:
! 20: ";
! 21:
! 22: my $filename;
! 23: die "Use option -h for help.\n" unless exists $ARGV[0];
! 24: #analyze options
! 25: if ( $ARGV[0] =~ m/^\s*-h/ ) {
! 26: print $man;
! 27: exit();
! 28: } else {
! 29: $filename = ($ARGV[0]);
! 30: die "$filename is not a file.\n" unless -f $ARGV[0];
! 31: }
! 32:
! 33:
! 34: # ----------------------------------------------------------------
! 35: # Start Analysis
! 36: print "checkuntranslated is searching for untranslated phrases in $filename...\n";
! 37:
! 38: # Read translation file row by row and try to find matching keys and values.
! 39: # It is assumed that all keys are followed by a value using the following syntax:
! 40: # 'key'
! 41: # => 'value',
! 42: #
! 43: # Optional comment rows and/or comments at the end of each row
! 44: # and white spaces are allowed and will be ignored.
! 45: #
! 46: # Compare key and value: identical? -> untranslated!
! 47: my $counter = 0;
! 48: my $line;
! 49: my $key = '';
! 50: my $mode = 'key';
! 51: open( FH, "<", $filename ) or die "$filename cannot be opened\n";
! 52: while ( !eof(FH) ) {
! 53: $line = readline(FH);
! 54: # Ignore comments
! 55: next if $line=~/^\s*#/;
! 56: # Key?
! 57: if ($mode eq 'key') {
! 58: # Search for key
! 59: if ($line =~ m/^\s+["'](.*)["']/) {
! 60: $key = $1;
! 61: $mode = 'value';
! 62: }
! 63: # Value?
! 64: } else { # $mode eq 'value'
! 65: # Search for value
! 66: if ($line =~ m/^\s*=>\s*["'](.*)["']/) {
! 67: if ($key eq $1) { # key = value?
! 68: print $key."\n";
! 69: $counter++;
! 70: }
! 71: $mode = 'key';
! 72: }
! 73: }
! 74: }
! 75: close(FH);
! 76:
! 77:
! 78: # Display summary message
! 79: if ($counter == 0) {
! 80: print "Be happy - No untranslated phrases found.\n";
! 81: } else {
! 82: print "Found $counter untranslated phrases in $filename.\n";
! 83: print "Please ignore all phrases which should have the same translation as the English phrase.\n";
! 84: }
! 85:
! 86: # ----------------------------------------------------------------
! 87:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>