File: verifyTranslationKeys.pl

package info (click to toggle)
openrocket 12.03-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,220 kB
  • sloc: java: 69,764; xml: 1,400; php: 198; perl: 38; sh: 36; makefile: 18
file content (67 lines) | stat: -rwxr-xr-x 1,456 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl

#
# Verify that keys used in Java files are present in the translation file.
# 
# Usage:
#    verifyTranslationKeys.pl <property file> <Java files...>
#
# For example:
#    find src/ -name "*.java" -exec ./scripts/verifyTranslationKeys.pl l10n/messages.properties {} +
#



# Read the translation file
my %keys;
print "Reading translation keys...\n";
while ($str = <>) {
    if ($ARGV!~/\.properties/) {
	last;
    }

    if ($str=~/^\s*($|[#!])/) {
	next;
    }

    if ($str=~/^([a-zA-Z0-9._-]+)\s*=/) {
	$keys{$1} = 1;
    } else {
	print "ERROR:  Invalid line in $ARGV: $str";
    }
}


# Read Java files
my $oldFile = $ARGV;
my $class="";
print "Reading Java files...\n";
while ($str = <>) {

    # Check for new file
    if ($ARGV != $oldFile) {
	$class = "";
    }
    
    # Check for irregular translator definition (exclude /l10n/ and /startup/)
    if ($str =~ / Translator / &&
	$str !~ /private static final Translator trans = Application.getTranslator\(\);/ &&
	$ARGV !~ /\/(l10n|startup)\//) {
	print "ERROR:  Unusual translator usage in file $ARGV: $str";
    }

    # Check for new class definition
    if ($str =~ /^[\sa-z]*class ([a-zA-Z0-9]+) /) {
	$class = $1;
    }

    # Check for translator usage
    if ($str =~ /trans\.get\(\"([^\"]+)\"\)/) {
	$key = $1;
	if (!(exists $keys{$key}) && 
	    !(exists $keys{$class . "." . $key})) {
	    print "ERROR:  Missing translation for '$key' in file $ARGV\n";
	}
    }

}