forked from refinedmods/refinedstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation-diff.pl
executable file
·51 lines (40 loc) · 1.28 KB
/
translation-diff.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
# Utility for comparing language translation keys of BASE_LANG and a given language.
# Usage: perl translation-diff.pl $lang
# Will output a translation-diff.diff file that compares the lang keys of BASE_LANG to $lang.
use constant {
BASE_LANG => "en_US",
OUTPUT_FILE => "translation-diff.diff"
};
my $lang = $ARGV[0] or die("Missing language to diff with");
sub lang_file {
my ($lang) = @_;
my $filename = "src/main/resources/assets/refinedstorage/lang/" . $lang . ".lang";
open(my $fh, $filename) or die("Couldn't open $filename");
return $fh;
}
sub write_keys {
my ($lang, $lang_keys) = @_;
my $filename = $lang . ".tmp";
open(my $fh, '>', $filename) or die("Couldn't open temp file $filename for $lang for writing");
print $fh $lang_keys;
close $fh;
return $filename;
}
sub lang_keys {
my ($lang_file) = @_;
my $keys = "";
while (my $line = <$lang_file>) {
my @p = split("=", $line);
$keys .= $p[0] . "\n";
}
return $keys;
}
my $f1 = lang_file(BASE_LANG);
my $f2 = lang_file($lang);
my $base_keys = lang_keys($f1);
my $t1 = write_keys(BASE_LANG, $base_keys);
my $lang_keys = lang_keys($f2);
my $t2 = write_keys($lang, $lang_keys);
system("diff -s -y $t1 $t2 > " . OUTPUT_FILE);
unlink($t1, $t2);
close($f1, $f2);