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
|
#!/usr/bin/perl
# Perlscript to complete AMSN language files
# by Patrick Kuijvenhoven <spantie_pet@users.sourceforge.net>
my $backupdir = "/tmp";
my $diff = "diff";
# These are standard on most distributions.
use File::Copy;
use File::Basename;
sub usage {
print STDERR "Usage: $0 <english langfile location> <your langfile location>\n";
exit 1;
}
sub langfiletohash {
$filename = shift;
undef $hash;
open(FILEHANDLE, $filename) or die("Could not open languagefile \"$filename\": $!");
while(<FILEHANDLE>) {
if (/^(.*?){1} (.*?)$/) {
$hash->{$1} = $2;
}
}
close(FILEHANDLE);
return $hash;
}
if($#ARGV < 1) {
usage();
}
$f_english = $ARGV[0];
$f_other = $ARGV[1];
if($ARGV[2] && -d $ARGV[2]) {
$backupdir = $ARGV[2];
}
$f_other_new = $backupdir."/".basename($f_other);
$f_other_old = $backupdir."/".basename($f_other).".old";
$f_other_diff= $backupdir."/".basename($f_other).".diff";
copy($f_other,$f_other_old) or die("[!] Failed to create backupfile $f_other_old: $!\n");
$english = langfiletohash($f_english);
$other = langfiletohash($f_other);
foreach $key (sort keys %$english) {
if(! $other->{$key} || $other->{$key} eq "") {
print "[E] ".$key.": ".$english->{$key}."\n";
print "[?] ".$key.": ";
undef $answer; do { $char = getc(STDIN); $answer .= $char } while ($char ne "\n"); chomp($answer);
if($answer ne "") {
$other->{$key} = $answer;
}
print "\n";
$i++;
}
}
if($i == 0) {
print "[i] No missing keys :)\n";
exit;
}
open(NEWLANGFILE, "> $f_other_new");
print NEWLANGFILE "amsn_lang_version ".$other->{"amsn_lang_version"}."\n";
foreach $key (sort keys %$other) {
if($key ne "amsn_lang_version") {
print NEWLANGFILE $key." ".$other->{$key}."\n";
}
}
close(NEWLANGFILE);
$cmd = "$diff -u $f_other_old $f_other_new > $f_other_diff";
system($cmd);
print qq {
If you like $f_other_diff, just move $f_other_new to
$f_other.
To help the amsn project, please refer to the LANG-HOWTO file
};
exit 0;
|