forked from github/kensanata.oddmuse
Add a fake AddModuleDescription such that the new translation files with the new module description call don't fail on "do". Also use :encoding(utf8) on opening the file as suggested by Ingo Belka on the wiki instead of calling utf8::decode on every line.
87 lines
2.0 KiB
Perl
Executable File
87 lines
2.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# Based on umtrans.pl version 1.0 (April 8, 2001) by Clifford Adams.
|
|
# Extracts translation strings from wiki script and extensions.
|
|
|
|
binmode(STDIN, ':utf8');
|
|
binmode(STDOUT, ':utf8');
|
|
|
|
$help = q{
|
|
NAME
|
|
oddtrans - complement translation tables for Oddmuse
|
|
|
|
SYNOPSIS
|
|
oddtrans [OPTIONS]... [FILE]...
|
|
|
|
DESCRIPTION
|
|
|
|
Read all the calls to T(), Ts(), and Tss() from all FILEs, and print
|
|
them on standard output, followed by their translation (usually the
|
|
empty string unless you use -l to load a library).
|
|
|
|
-l
|
|
load a library from a previous run; you can use multiple -l
|
|
|
|
EXAMPLES
|
|
|
|
oddtrans -l german-utf8.pl wiki.pl modules/*.pl > new-german-utf8.pl
|
|
|
|
};
|
|
|
|
%Translate = ();
|
|
|
|
$arg = shift;
|
|
while ($arg =~ /^-l/) {
|
|
$file = substr($arg, 3);
|
|
$file = shift unless $file;
|
|
die $help unless -f $file;
|
|
%backup = %Translate;
|
|
&header_info_extract($file); # keep the header information of the translation files
|
|
do $file or die "Cannot do $file";
|
|
foreach $key (keys %Translate) {
|
|
$backup{$key} = $Translate{$key};
|
|
}
|
|
%Translate = %backup;
|
|
$arg = shift;
|
|
}
|
|
unshift(@ARGV,$arg); # shove the last one back because it is not -l!
|
|
|
|
print q{%Translate = split(/\n/,<<'END_OF_TRANSLATION');
|
|
};
|
|
foreach (<>) {
|
|
s/Ts?s?\(\'([^']+)/&trans($1)/ge;
|
|
s/Ts?s?\(\"([^"]+)/&trans($1)/ge;
|
|
}
|
|
|
|
print "END_OF_TRANSLATION\n";
|
|
|
|
my %seen = ();
|
|
|
|
sub trans {
|
|
my ($string) = @_;
|
|
my ($result);
|
|
$result = '';
|
|
$result = $Translate{$string} if (defined($Translate{$string}));
|
|
return ' ' if ($seen{$string});
|
|
$seen{$string} = 1;
|
|
print $string . "\n" . $result . "\n";
|
|
return ' ';
|
|
}
|
|
|
|
my $header = 0;
|
|
|
|
sub header_info_extract{
|
|
return if $header++;
|
|
$file = shift;
|
|
open(FILE, "<:encoding(utf8)", $file) or die "Can't open $file because: $!";
|
|
foreach (<FILE>) {
|
|
last if (/^%/);
|
|
print;
|
|
}
|
|
close FILE;
|
|
}
|
|
|
|
sub AddModuleDescription {
|
|
# Do nothin; this function is just there such that the translation
|
|
# files can be run.
|
|
}
|