Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 07e41378ea
Fetching contributors…

Cannot retrieve contributors at this time

executable file 97 lines (89 sloc) 2.221 kb
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 94 95 96 97
#!/usr/local/bin/perl
# Converts a module's zh_CN (simplified chinese) strings to zh_TW.Big5
# (traditional)

use Encode::HanConvert;

foreach $m (@ARGV) {
# Convert lang file
-d "$m/lang" || die "$m is not a module directory";
local %zh;
&read_file("$m/lang/zh_CN", \%zh);
foreach $k (keys %zh) {
$zh{$k} = gb_to_big5($zh{$k});
}
&write_file_diff("$m/lang/zh_TW.Big5", \%zh);

# Translate the module.info file
local %minfo;
&read_file("$m/module.info", \%minfo);
local %ominfo = %minfo;
if ($minfo{'desc_zh_CN'}) {
$minfo{'desc_zh_TW.Big5'} = gb_to_big5($minfo{'desc_zh_CN'});
&write_file_diff("$m/module.info", \%minfo);
}

# Translate the config.info file
local %cinfo;
if (&read_file("$m/config.info.zh_CN", \%cinfo)) {
local %ocinfo = %cinfo;
foreach $k (keys %cinfo) {
$cinfo{$k} = gb_to_big5($cinfo{$k});
}
&write_file_diff("$m/config.info.zh_TW.Big5", \%cinfo);
}

# Translate any help files
opendir(DIR, "$m/help");
foreach $h (readdir(DIR)) {
if ($h =~ /(\S+)\.zh_CN\.html$/) {
open(IN, "$m/help/$h");
open(OUT, ">$m/help/$1.zh_TW.Big5.html");
while(<IN>) {
print OUT gb_to_big5($_);
}
close(OUT);
close(IN);
}
}
closedir(DIR);
}

# read_file(file, &assoc, [&order], [lowercase])
# Fill an associative array with name=value pairs from a file
sub read_file
{
open(ARFILE, $_[0]) || return 0;
while(<ARFILE>) {
s/\r|\n//g;
        if (!/^#/ && /^([^=]+)=(.*)$/) {
$_[1]->{$_[3] ? lc($1) : $1} = $2;
push(@{$_[2]}, $1) if ($_[2]);
         }
        }
close(ARFILE);
return 1;
}
 
# write_file_diff(file, array)
# Write out the contents of an associative array as name=value lines
sub write_file_diff
{
local(%old, @order);
&read_file($_[0], \%old, \@order);
return if (!&diff(\%old, $_[1]));
open(ARFILE, ">$_[0]");
foreach $k (@order) {
        print ARFILE $k,"=",$_[1]->{$k},"\n" if (exists($_[1]->{$k}));
}
foreach $k (keys %{$_[1]}) {
        print ARFILE $k,"=",$_[1]->{$k},"\n" if (!exists($old{$k}));
        }
close(ARFILE);
print "Wrote $_[0]\n";
}

sub diff
{
if (scalar(keys %{$_[0]}) != scalar(keys %{$_[1]})) {
return 1;
}
foreach $k (keys %{$_[0]}) {
if ($_[0]->{$k} ne $_[1]->{$k}) {
return 1;
}
}
return 0;
}
Something went wrong with that request. Please try again.