Imported Upstream version 1.47.9
[platform/upstream/help2man.git] / build-aux / fixup-texi-pot
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
42     # Find cross references and add a note to translators.
43     /^msgid "(.*)/sm or next;
44     my @refs = $1 =~ /\@(?:p?x)?ref\{([^,}]*)\}/g;
45     if (@refs)
46     {
47         for (@refs)
48         {
49             s/"\n"//g;       # remove line breaks
50             $_ = qq/"$_",/;  # add quotes and comma
51         }
52
53         $refs[-1] =~ s/,$//;
54         my $plural = '';
55         if (@refs > 1)
56         {
57             $plural = 's';
58             splice @refs, -1, 0, 'and';
59         }
60
61         my $note = wrap "#. Translators: ", "#. ",
62             "the translated cross-reference$plural @refs here must match the " .
63             " target (type: node) translation$plural elsewhere in this file.";
64         $_ = $note . "\n" . $_;
65     }
66
67     print OUT;
68 }