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.
|
|
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
2015-10-23 00:21:20 +03:00
|
|
|
use v5.10;
|
|
|
|
|
use utf8;
|
2015-09-30 17:35:02 +02:00
|
|
|
|
2015-07-08 14:53:49 +02:00
|
|
|
binmode(STDOUT, ":encoding(UTF-8)");
|
2012-07-19 08:28:51 -04:00
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
my $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
|
|
|
};
|
|
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
our %Translate = ();
|
2005-03-06 16:29:44 +00:00
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
my $arg = shift;
|
2005-03-06 16:29:44 +00:00
|
|
|
while ($arg =~ /^-l/) {
|
2015-09-30 17:35:02 +02:00
|
|
|
my $file;
|
|
|
|
|
$file = substr($arg, 3) if length($arg) > 2;
|
2005-03-06 16:29:44 +00:00
|
|
|
$file = shift unless $file;
|
|
|
|
|
die $help unless -f $file;
|
2015-09-30 17:35:02 +02:00
|
|
|
my %backup = %Translate;
|
|
|
|
|
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";
|
2015-09-30 17:35:02 +02:00
|
|
|
foreach my $key (keys %Translate) {
|
2005-03-06 16:29:44 +00:00
|
|
|
$backup{$key} = $Translate{$key};
|
|
|
|
|
}
|
|
|
|
|
%Translate = %backup;
|
|
|
|
|
$arg = shift;
|
2004-06-28 21:04:42 +00:00
|
|
|
}
|
2015-10-23 00:21:20 +03:00
|
|
|
unshift(@ARGV, $arg); # shove the last one back because it is not -l!
|
2004-06-28 21:04:42 +00:00
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
print "our \%Translate = grep(!/^#/, split(/\\n/,<<'END_OF_TRANSLATION'));\n";
|
2015-06-28 00:10:43 +02:00
|
|
|
undef $/; # slurp
|
2015-07-08 14:53:49 +02:00
|
|
|
foreach my $file (@ARGV) {
|
|
|
|
|
open(my $fh, "<:encoding(UTF-8)", $file) or die "Cannot open $file: $!";
|
|
|
|
|
$_ = <$fh>;
|
2015-06-28 00:10:43 +02:00
|
|
|
# join split strings
|
|
|
|
|
s/'\s*\.\s*'//g;
|
2015-06-28 00:53:24 +02:00
|
|
|
s/"\s*\.\s*"//g;
|
2015-06-28 00:10:43 +02:00
|
|
|
# extract calls to T, Ts and Tss
|
2015-09-30 17:35:02 +02:00
|
|
|
while(/Ts?s?\(\'([^']+)/g) { trans($file, $1); }
|
|
|
|
|
while(/Ts?s?\(\"([^"]+)/g) { trans($file, $1); }
|
2014-08-24 08:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-23 00:21:20 +03:00
|
|
|
print "#\nEND_OF_TRANSLATION\n";
|
2014-08-24 08:44:31 +02:00
|
|
|
|
2004-06-28 22:07:13 +00:00
|
|
|
my %seen = ();
|
2015-09-30 17:35:02 +02:00
|
|
|
my %read = ();
|
2004-06-28 22:07:13 +00:00
|
|
|
|
2004-06-28 21:04:42 +00:00
|
|
|
sub trans {
|
2015-09-30 17:35:02 +02:00
|
|
|
my ($file, $string) = @_;
|
2004-06-28 21:04:42 +00:00
|
|
|
my ($result);
|
|
|
|
|
$result = '';
|
|
|
|
|
$result = $Translate{$string} if (defined($Translate{$string}));
|
|
|
|
|
return ' ' if ($seen{$string});
|
2015-09-30 17:35:02 +02:00
|
|
|
marker($file) unless $read{$file};
|
2004-06-28 21:04:42 +00:00
|
|
|
$seen{$string} = 1;
|
|
|
|
|
print $string . "\n" . $result . "\n";
|
|
|
|
|
return ' ';
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-30 17:35:02 +02:00
|
|
|
sub marker {
|
|
|
|
|
my $file = shift;
|
|
|
|
|
$read{$file} = 1;
|
|
|
|
|
# place marker
|
|
|
|
|
print "#" x 80, "\n";
|
|
|
|
|
print "# $file\n";
|
|
|
|
|
print "#" x 80, "\n";
|
|
|
|
|
}
|
2014-08-24 08:44:31 +02:00
|
|
|
my $header = 0;
|
2004-06-28 21:04:42 +00:00
|
|
|
|
2015-10-23 00:21:20 +03:00
|
|
|
sub header_info_extract {
|
2014-08-24 08:44:31 +02:00
|
|
|
return if $header++;
|
2015-09-30 17:35:02 +02:00
|
|
|
my $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>) {
|
2015-06-28 00:10:43 +02:00
|
|
|
last if (/^our %Translate = /);
|
2014-08-24 08:44:31 +02:00
|
|
|
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.
|
|
|
|
|
}
|