forked from MiniKeePass/MiniKeePass
-
Notifications
You must be signed in to change notification settings - Fork 2
/
find_localized.pl
executable file
·94 lines (70 loc) · 1.74 KB
/
find_localized.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
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl
use File::Find ();
use strict;
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name/;
*name = *File::Find::name;
my $print_unused = 1;
my %src_strings = ();
sub match_source;
sub match_localizable;
# Find all the localized strings in source files
File::Find::find({wanted => \&match_source}, '.');
# Find all the localized strings in Localizable.strings files
File::Find::find({wanted => \&match_localizable}, '.');
sub match_source {
my $filename = $_;
if ($filename =~ /\.m$/) {
process_source($filename);
}
}
sub match_localizable {
my $filename = $_;
if ($filename =~ /^Localizable.strings$/) {
print "Processing $name\n";
process_localizable($filename);
}
}
sub process_source {
my($file) = @_;
open(FILE, $file) or die("Failed to open file $file: $!");
my $lineno = 0;
while (<FILE>) {
my $line = $_;
chomp($line);
$line =~ s/^\s+//;
$line =~ s/\s+$//;
$lineno++;
while ($line =~ /NSLocalizedString\(@"([^"]*)"/g) {
my $string = $1;
$src_strings{$string} = 1;
}
}
close(FILE);
}
sub process_localizable {
my($file) = @_;
my %localized_strings = {};
open(FILE, "iconv -f UTF-8 $file |") or die("Failed to open file: $!");
my $lineno = 0;
while (<FILE>) {
my $line = $_;
chomp($line);
$line =~ s/^\s+//;
$line =~ s/\s+$//;
$lineno++;
if ($line =~ /^"([^"]*)"\s*=/) {
my $string = $1;
$localized_strings{$string} = 1;
if ($print_unused && $src_strings{$string} != 1) {
print " Unused $string\n";
}
}
}
close(FILE);
foreach my $string (keys(%src_strings)) {
if ($localized_strings{$string} != 1) {
print " Missing $string\n";
}
}
}