| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
# translate english F*EX files into locale languange, debian special |
| 4 |
|
| 5 |
use File::Basename; |
| 6 |
use File::Copy; |
| 7 |
|
| 8 |
@trfiles = qw( |
| 9 |
lib/fex.pp |
| 10 |
cgi-bin/foc |
| 11 |
cgi-bin/fop |
| 12 |
cgi-bin/fuc |
| 13 |
cgi-bin/fup |
| 14 |
cgi-bin/fur |
| 15 |
cgi-bin/rup |
| 16 |
cgi-bin/pup |
| 17 |
); |
| 18 |
|
| 19 |
@cpfiles = qw( |
| 20 |
htdocs/index.html |
| 21 |
htdocs/FAQ.html |
| 22 |
lib/fup.pl |
| 23 |
lang.html |
| 24 |
); |
| 25 |
|
| 26 |
$source = shift; |
| 27 |
$FEXHOME = shift; |
| 28 |
$dest = shift; |
| 29 |
|
| 30 |
$tr = "$source/locale/translations"; |
| 31 |
|
| 32 |
mkdirp($dest); |
| 33 |
unless (-l "$dest/english") { |
| 34 |
symlink '..',"$dest/english" |
| 35 |
or die "$0: cannot symlink $dest/english - $!\n"; |
| 36 |
} |
| 37 |
|
| 38 |
foreach $lang (glob "$source/locale/*/lib/fup.pl") { |
| 39 |
$lang =~ s:.*/locale/::; |
| 40 |
$lang =~ s:/.*::; |
| 41 |
next if $lang eq 'english'; |
| 42 |
next if $lang eq 'swabian'; |
| 43 |
next if $lang =~ /_$/; |
| 44 |
|
| 45 |
print "\n$lang:\n"; |
| 46 |
open $tr,$tr or die "$0: cannot open $tr - $!\n"; |
| 47 |
%T = (); |
| 48 |
$n = $ll = 0; |
| 49 |
|
| 50 |
while (<$tr>) { |
| 51 |
$n++; |
| 52 |
last if /^\s*$/; |
| 53 |
if (/^#\s*([\w-]+):/ and $lang eq $1) { |
| 54 |
$ll = $n; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
next unless $ll; |
| 59 |
|
| 60 |
while (<$tr>) { |
| 61 |
next if /^#/; |
| 62 |
next if /^\s*$/; |
| 63 |
chomp; |
| 64 |
unless (/[a-z]/i) { |
| 65 |
die "$0: syntax error in $tr line $. : no text\n"; |
| 66 |
} |
| 67 |
$e = $_; |
| 68 |
for my $l (2 .. $ll) { |
| 69 |
$_ = <$tr>||''; |
| 70 |
chomp; |
| 71 |
unless (/[a-z]/i) { |
| 72 |
die "$0: syntax error in $tr line $. : no text\n"; |
| 73 |
} |
| 74 |
} |
| 75 |
$T{$e} = $_; |
| 76 |
while (<$tr>) { last if /^\s*$/ } |
| 77 |
} |
| 78 |
|
| 79 |
close $tr; |
| 80 |
@E = sort {length $b <=> length $a} keys %T; |
| 81 |
|
| 82 |
foreach $file (@trfiles) { |
| 83 |
local $/; |
| 84 |
mkdirp("$dest/$lang/".dirname($file)); |
| 85 |
$fe = "$source/$file"; |
| 86 |
$ft = "$dest/$lang/$file"; |
| 87 |
open $fe,"<$fe" or die "$0: cannot read $fe - $!\n"; |
| 88 |
open $ft,">$ft" or die "$0: cannot write $ft - $!\n"; |
| 89 |
$_ = <$fe>; |
| 90 |
close $fe; |
| 91 |
foreach $e (@E) { |
| 92 |
s/\Q$e/$T{$e}/g; |
| 93 |
} |
| 94 |
print {$ft} $_; |
| 95 |
close $ft; |
| 96 |
chmod((stat $fe)[2],$ft); |
| 97 |
print "$ft written\n"; |
| 98 |
} |
| 99 |
|
| 100 |
foreach $file (@cpfiles) { |
| 101 |
$fs = "$source/locale/$lang/$file"; |
| 102 |
$fd = "$dest/$lang/$file"; |
| 103 |
mkdirp(dirname($fd)); |
| 104 |
$fd .= '_new' if -f $fd; |
| 105 |
if (copy($fs,$fd)) { |
| 106 |
chmod((stat $fs)[2],$fd); |
| 107 |
print "$fd written\n"; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
foreach $fs (qw(dop fex.ph)) { |
| 112 |
$fd = "$dest/$lang/lib/$fs"; |
| 113 |
symlink "$FEXHOME/lib/$fs",$fd or die "$0: cannot symlink $fd - $!\n"; |
| 114 |
print "$fd linked\n"; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
# emulate mkdir -p |
| 119 |
sub mkdirp { |
| 120 |
my $dir = shift; |
| 121 |
my $pdir; |
| 122 |
|
| 123 |
return if -d $dir; |
| 124 |
$dir =~ s:/+$::; |
| 125 |
die "$0: cannot mkdir /\n" unless $dir; |
| 126 |
$pdir = $dir; |
| 127 |
if ($pdir =~ s:/[^/]+$::) { |
| 128 |
mkdirp($pdir) unless -d $pdir; |
| 129 |
} |
| 130 |
unless (-d $dir) { |
| 131 |
mkdir $dir,0755 or die "$0: mkdir $dir - $!\n"; |
| 132 |
} |
| 133 |
} |