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, 6 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.
1: #!/usr/bin/perl
2: # The LearningOnline Network with CAPA
3: # $Id: checkuntranslated.pl,v 1.1 2009/11/25 13:36:56 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>