create changelog entry
[debian/openrocket] / core / scripts / verifyTranslationKeys.pl
1 #!/usr/bin/perl
2
3 #
4 # Verify that keys used in Java files are present in the translation file.
5
6 # Usage:
7 #    verifyTranslationKeys.pl <property file> <Java files...>
8 #
9 # For example:
10 #    find src/ -name "*.java" -exec ./scripts/verifyTranslationKeys.pl l10n/messages.properties {} +
11 #
12
13
14
15 # Read the translation file
16 my %keys;
17 print "Reading translation keys...\n";
18 while ($str = <>) {
19     if ($ARGV!~/\.properties/) {
20         last;
21     }
22
23     if ($str=~/^\s*($|[#!])/) {
24         next;
25     }
26
27     if ($str=~/^([a-zA-Z0-9._-]+)\s*=/) {
28         $keys{$1} = 1;
29     } else {
30         print "ERROR:  Invalid line in $ARGV: $str";
31     }
32 }
33
34
35 # Read Java files
36 my $oldFile = $ARGV;
37 my $class="";
38 print "Reading Java files...\n";
39 while ($str = <>) {
40
41     # Check for new file
42     if ($ARGV != $oldFile) {
43         $class = "";
44     }
45     
46     # Check for irregular translator definition (exclude /l10n/ and /startup/)
47     if ($str =~ / Translator / &&
48         $str !~ /private static final Translator trans = Application.getTranslator\(\);/ &&
49         $ARGV !~ /\/(l10n|startup)\//) {
50         print "ERROR:  Unusual translator usage in file $ARGV: $str";
51     }
52
53     # Check for new class definition
54     if ($str =~ /^[\sa-z]*class ([a-zA-Z0-9]+) /) {
55         $class = $1;
56     }
57
58     # Check for translator usage
59     if ($str =~ /trans\.get\(\"([^\"]+)\"\)/) {
60         $key = $1;
61         if (!(exists $keys{$key}) && 
62             !(exists $keys{$class . "." . $key})) {
63             print "ERROR:  Missing translation for '$key' in file $ARGV\n";
64         }
65     }
66
67 }