2004-06-28 21:04:42 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
# Based on umtrans.pl version 1.0 (April 8, 2001) by Clifford Adams.
|
|
|
|
|
# Extracts translation strings from wiki script and extensions.
|
|
|
|
|
|
2012-07-19 08:28:51 -04:00
|
|
|
binmode(STDIN, ':utf8');
|
|
|
|
|
binmode(STDOUT, ':utf8');
|
|
|
|
|
|
2005-03-06 16:29:44 +00:00
|
|
|
$help = q{
|
2004-06-28 21:04:42 +00:00
|
|
|
NAME
|
2004-06-28 22:07:13 +00:00
|
|
|
oddtrans - complement translation tables for Oddmuse
|
2004-06-28 21:04:42 +00:00
|
|
|
|
|
|
|
|
SYNOPSIS
|
2004-06-28 22:07:13 +00:00
|
|
|
oddtrans [OPTIONS]... [FILE]...
|
2004-06-28 21:04:42 +00:00
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
|
|
2004-06-28 22:07:13 +00:00
|
|
|
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).
|
2004-06-28 21:04:42 +00:00
|
|
|
|
2004-06-28 22:07:13 +00:00
|
|
|
-l
|
2005-03-06 16:29:44 +00:00
|
|
|
load a library from a previous run; you can use multiple -l
|
2004-06-28 21:04:42 +00:00
|
|
|
|
|
|
|
|
EXAMPLES
|
|
|
|
|
|
|
|
|
|
oddtrans -l german-utf8.pl wiki.pl modules/*.pl > new-german-utf8.pl
|
|
|
|
|
|
2005-03-06 16:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
%Translate = ();
|
|
|
|
|
|
|
|
|
|
$arg = shift;
|
|
|
|
|
while ($arg =~ /^-l/) {
|
|
|
|
|
$file = substr($arg, 3);
|
|
|
|
|
$file = shift unless $file;
|
|
|
|
|
die $help unless -f $file;
|
|
|
|
|
%backup = %Translate;
|
2014-08-24 08:44:31 +02:00
|
|
|
&header_info_extract($file); # keep the header information of the translation files
|
2005-10-07 23:21:14 +00:00
|
|
|
do $file or die "Cannot do $file";
|
2005-03-06 16:29:44 +00:00
|
|
|
foreach $key (keys %Translate) {
|
|
|
|
|
$backup{$key} = $Translate{$key};
|
|
|
|
|
}
|
|
|
|
|
%Translate = %backup;
|
|
|
|
|
$arg = shift;
|
2004-06-28 21:04:42 +00:00
|
|
|
}
|
2005-03-06 16:29:44 +00:00
|
|
|
unshift(@ARGV,$arg); # shove the last one back because it is not -l!
|
2004-06-28 21:04:42 +00:00
|
|
|
|
2014-08-24 08:44:31 +02:00
|
|
|
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";
|
|
|
|
|
|
2004-06-28 22:07:13 +00:00
|
|
|
my %seen = ();
|
|
|
|
|
|
2004-06-28 21:04:42 +00:00
|
|
|
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 ' ';
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 08:44:31 +02:00
|
|
|
my $header = 0;
|
2004-06-28 21:04:42 +00:00
|
|
|
|
2014-08-24 08:44:31 +02:00
|
|
|
sub header_info_extract{
|
|
|
|
|
return if $header++;
|
|
|
|
|
$file = shift;
|
2014-08-24 12:37:48 +02:00
|
|
|
open(FILE, "<:encoding(utf8)", $file) or die "Can't open $file because: $!";
|
2014-08-24 08:44:31 +02:00
|
|
|
foreach (<FILE>) {
|
|
|
|
|
last if (/^%/);
|
|
|
|
|
print;
|
|
|
|
|
}
|
|
|
|
|
close FILE;
|
|
|
|
|
}
|
2014-08-24 12:37:48 +02:00
|
|
|
|
|
|
|
|
sub AddModuleDescription {
|
|
|
|
|
# Do nothin; this function is just there such that the translation
|
|
|
|
|
# files can be run.
|
|
|
|
|
}
|