forked from chrisboyle/sgtpuzzles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18ncheck.pl
executable file
·81 lines (70 loc) · 2.08 KB
/
i18ncheck.pl
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
use strict;
my @sources = <jni/*.c AndroidManifest.xml res/menu/*.xml res/layout/*.xml res/values/arrays.xml src/name/boyle/chris/sgtpuzzles/*.java>;
my @stringsfiles = <res/values*/strings.xml>;
my %srcstrings;
my %resstrings;
sub mangle($)
{
my ($_) = ( @_ );
s/\%age/percentage/g;
s/','/comma/g;
s/\\n/_/g;
s/\%[0-9.]*[sd]/X/g;
s/[^A-Za-z0-9]+/_/g;
s/^([0-9])/_$1/;
s/_$//;
return $_;
}
my $problem = 0;
for my $lang ( @stringsfiles ) {
open(RES,$lang) or die "Can't open $lang: $!\n";
$_ = join('',<RES>);
close(RES);
while (/<string\s+name="([^"]+)"(?: formatted="false")?>(.*?)<\/string>/gs) {
$resstrings{$lang}->{$1} = [ $2, "$lang:$." ];
}
}
for my $source (@sources) {
my $isgame = 0;
open(SRC,$source) or die "Can't open $source: $!\n";
$_ = join('',<SRC>);
close(SRC);
s/\\"/''/g;
$isgame = 1 if /^#define\s+thegame\s+/m && $source ne 'jni/nullgame.c';
while (/_\(\s*"(.*?)"\s*\)/gs) {
my $quoted = $1;
for my $str ( $quoted =~ /^:/ ? split(/:/,substr($quoted,1)) : ( $quoted ) ) {
my $id = mangle($str);
# print "set \"$id\"\n";
$srcstrings{$id} = [ $str, "$source:$." ];
}
}
while (/(?:[^.]R\.string\.|\@string\/)([A-Za-z0-9_]+)/g) {
$srcstrings{$1} = [ undef, "$source:$." ];
}
if ($isgame) {
my $name = $source;
$name =~ s/jni\/(.*)\.c$/$1/;
$srcstrings{"name_$name"} = [ undef, "(filename)" ];
$srcstrings{"desc_$name"} = [ undef, "(filename)" ];
}
}
for my $id ( keys %srcstrings ) {
for my $lang ( keys %resstrings ) {
if ( ! defined $resstrings{$lang}->{$id} ) {
warn "No string resource in $lang for $id from $srcstrings{$id}[1]\n";
$problem = 1 unless $id =~ /^desc_/;
}
}
}
for my $lang ( keys %resstrings ) {
for my $id ( keys %{$resstrings{$lang}} ) {
if ( ! defined $srcstrings{$id} ) {
warn "String resource $lang:$id might be unused, from $resstrings{$lang}->{$id}[1]\n";
$problem = 1;
}
}
}
print( (scalar keys %srcstrings) . " source strings, " . (scalar keys %resstrings) . " languages: " . join(', ', map { $_."=".(scalar keys %{$resstrings{$_}}) } keys %resstrings )."\n");
exit $problem;