wiki.pl: Port some fixes from upstream
[Orgmuse.git] / oddtrans
blobe23f44ed03aea66096f489bbdd39b8c2150caebf
1 #!/usr/bin/perl
2 # Based on umtrans.pl version 1.0 (April 8, 2001) by Clifford Adams.
3 # Extracts translation strings from wiki script and extensions.
5 binmode(STDIN, ':utf8');
6 binmode(STDOUT, ':utf8');
8 $help = q{
9 NAME
10 oddtrans - complement translation tables for Oddmuse
12 SYNOPSIS
13 oddtrans [OPTIONS]... [FILE]...
15 DESCRIPTION
17 Read all the calls to T(), Ts(), and Tss() from all FILEs, and print
18 them on standard output, followed by their translation (usually the
19 empty string unless you use -l to load a library).
22 load a library from a previous run; you can use multiple -l
24 EXAMPLES
26 oddtrans -l german-utf8.pl wiki.pl modules/*.pl > new-german-utf8.pl
30 %Translate = ();
32 $arg = shift;
33 while ($arg =~ /^-l/) {
34 $file = substr($arg, 3);
35 $file = shift unless $file;
36 die $help unless -f $file;
37 %backup = %Translate;
38 do $file or die "Cannot do $file";
39 foreach $key (keys %Translate) {
40 $backup{$key} = $Translate{$key};
42 %Translate = %backup;
43 $arg = shift;
45 unshift(@ARGV,$arg); # shove the last one back because it is not -l!
47 my %seen = ();
49 sub trans {
50 my ($string) = @_;
51 my ($result);
52 $result = '';
53 $result = $Translate{$string} if (defined($Translate{$string}));
54 return ' ' if ($seen{$string});
55 $seen{$string} = 1;
56 print $string . "\n" . $result . "\n";
57 return ' ';
60 print '%Translate = split(/\n/,<<END_OF_TRANSLATION);' . "\n";
61 foreach (<>) {
62 s/Ts?s?\(\'([^']+)/&trans($1)/ge;
63 s/Ts?s?\(\"([^"]+)/&trans($1)/ge;
66 print "END_OF_TRANSLATION\n";