| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Post-process the texinfo template to remove some entries which should not be |
| 4 |
# translated. Add translator notes to cross references. |
| 5 |
|
| 6 |
use strict; |
| 7 |
use warnings; |
| 8 |
use Text::Wrap 'wrap'; |
| 9 |
|
| 10 |
*OUT = *STDOUT; |
| 11 |
if (@ARGV and $ARGV[0] =~ /^-o(.*)/) |
| 12 |
{ |
| 13 |
shift; |
| 14 |
my $out = $1 || shift || die "$0: missing output file\n"; |
| 15 |
open OUT, '>', $out or die "$0: can't open $out ($!)\n"; |
| 16 |
} |
| 17 |
|
| 18 |
$/ = ''; # read paragraphs |
| 19 |
while (<>) |
| 20 |
{ |
| 21 |
# Path name for dir entry. Corrected by fixup-texi-trans. |
| 22 |
next if /^#\. type: menuentry/m |
| 23 |
and /^msgid "help2man: \(help2man\)"/m; |
| 24 |
|
| 25 |
# "Top" node is special to texinfo. |
| 26 |
next if /^#\. type: node/m |
| 27 |
and /^msgid "Top"/m; |
| 28 |
|
| 29 |
# Macro commands, and parameters. |
| 30 |
next if /^msgid "\@unmacro/m; |
| 31 |
next if /^msgid "\\\\text\\\\"/m; |
| 32 |
|
| 33 |
# Options. |
| 34 |
next if /^msgid "-[a-zA-Z]"/m; |
| 35 |
next if /^msgid "--[a-z-]+"/m; |
| 36 |
|
| 37 |
# Other untranslatable strings. |
| 38 |
next if /^#\. type: author/ and /^msgid "[^@]*\@email\{[^}]*\}"/m; |
| 39 |
next if /^msgid "help2man"/m; |
| 40 |
next if /^msgid "\@url\{[^}]*\}(\\n)?"/m; |
| 41 |
next if /^msgid "\@documentencoding UTF-8"/m; |
| 42 |
|
| 43 |
# Find cross references and add a note to translators. |
| 44 |
/^msgid "(.*)/sm or next; |
| 45 |
my @refs = $1 =~ /\@(?:p?x)?ref\{([^,}]*)\}/g; |
| 46 |
if (@refs) |
| 47 |
{ |
| 48 |
for (@refs) |
| 49 |
{ |
| 50 |
s/"\n"//g; # remove line breaks |
| 51 |
$_ = qq/"$_",/; # add quotes and comma |
| 52 |
} |
| 53 |
|
| 54 |
$refs[-1] =~ s/,$//; |
| 55 |
my $plural = ''; |
| 56 |
if (@refs > 1) |
| 57 |
{ |
| 58 |
$plural = 's'; |
| 59 |
splice @refs, -1, 0, 'and'; |
| 60 |
} |
| 61 |
|
| 62 |
my $note = wrap "#. Translators: ", "#. ", |
| 63 |
"the translated cross-reference$plural @refs here must match the " . |
| 64 |
" target (type: node) translation$plural elsewhere in this file."; |
| 65 |
$_ = $note . "\n" . $_; |
| 66 |
} |
| 67 |
|
| 68 |
print OUT; |
| 69 |
} |