summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorBrendan O'Dea <bod@debian.org>2014-07-26 21:58:42 +1000
committerBrendan O'Dea <bod@debian.org>2014-07-26 21:58:42 +1000
commit6b27ee17d1bebc50050081842d65b37c16295b2a (patch)
tree02f4f1df0fbd886041e86f8f55629fdc84bbf18f /build-aux
parent981ba44c57cae737209bee69245e55e80674994d (diff)
downloadhelp2man-6b27ee17d1bebc50050081842d65b37c16295b2a.tar.gz
Add helper scripts to clean up texinfo translations
Diffstat (limited to 'build-aux')
-rwxr-xr-xbuild-aux/fixup-texi-pot33
-rwxr-xr-xbuild-aux/fixup-texi-trans108
2 files changed, 141 insertions, 0 deletions
diff --git a/build-aux/fixup-texi-pot b/build-aux/fixup-texi-pot
new file mode 100755
index 0000000..0e6000b
--- /dev/null
+++ b/build-aux/fixup-texi-pot
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+# Post-process the texinfo template to remove some entries which should not be
+# translated.
+
+use strict;
+use warnings;
+
+*OUT = *STDOUT;
+if (@ARGV and $ARGV[0] =~ /^-o(.*)/)
+{
+ shift;
+ my $out = $1 || shift || die "$0: missing output file\n";
+ open OUT, '>', $out or die "$0: can't open $out ($!)\n";
+}
+
+$/ = ''; # read paragraphs
+while (<>)
+{
+ # Path name for dir entry. Corrected by fixup-texi-trans.
+ next if /^#\. type: menuentry/m
+ and /^msgid "help2man: \(help2man\)"/m;
+
+ # "Top" node is special to texinfo.
+ next if /^#\. type: node/m
+ and /^msgid "Top"/m;
+
+ # Macro commands, and parameters.
+ next if /^msgid "\@unmacro/m;
+ next if /^msgid "\\\\text\\\\"/m;
+
+ print OUT;
+}
diff --git a/build-aux/fixup-texi-trans b/build-aux/fixup-texi-trans
new file mode 100755
index 0000000..5e7979c
--- /dev/null
+++ b/build-aux/fixup-texi-trans
@@ -0,0 +1,108 @@
+#!/usr/bin/perl
+
+# Post-process the translated texinfo page to add the correct path for
+# install-info, and to correct the alignment of the main menu.
+
+use strict;
+use warnings;
+use open qw(:std :utf8); # assume utf8 encoding
+use Text::Wrap;
+
+$Text::Wrap::columns = 72;
+
+*OUT = *STDOUT;
+if (@ARGV and $ARGV[0] =~ /^-o(.*)/)
+{
+ shift;
+ my $out = $1 || shift || die "$0: missing output file\n";
+ open OUT, '>', $out or die "$0: can't open $out ($!)\n";
+}
+
+my %fixed;
+my $encoding = 'none';
+my $lang;
+my $last = '';
+
+$/ = ''; # read paragraphs
+while (<>)
+{
+ if (!$lang and /^This is help2man-(.*)\.info,/)
+ {
+ $lang = $1;
+ next;
+ }
+
+ if (!$fixed{menu} and $last =~ /^\* Menu:\n*$/)
+ {
+ my @entries;
+ my $width = 0;
+ for (split /\n/)
+ {
+ if (/^\* (.*)::\s+(.*)/)
+ {
+ my $w = length $1;
+ push @entries, [$w, $1, $2];
+ # Stash the largest width (within limits) to use when
+ # calculating the indent.
+ $width = $w if $w > $width and $w < 40;
+ }
+ else
+ {
+ # Append to previous entry.
+ s/^\s*//;
+ $entries[-1][-1] .= $_;
+ }
+ }
+
+ $_ = join "\n", (map {
+ my ($w, $node, $description) = @$_;
+ my $prefix = "* ${node}::";
+ # 6 for leading *, trailing ::, and spaces.
+ my $indent = ' ' x ($width + 6);
+ my $first;
+ if ($w > $width)
+ {
+ $first = $indent;
+ $prefix .= "\n";
+ }
+ else
+ {
+ $first = sprintf "%-*s", length $indent, $prefix;
+ $prefix = '';
+ }
+
+ $prefix . wrap $first, " $indent", $description;
+ } @entries), "\n";
+
+ $fixed{menu}++;
+ next;
+ }
+
+ if (!$fixed{info_dir} and /^START-INFO-DIR-ENTRY/m and $lang)
+ {
+ my $first = "* help2man-$lang: (help2man-$lang). ";
+ my $indent = ' ' x ((length $first) + 2);
+ s/^\* help2man: \(help2man\)\.\s*(.*)\nEND-INFO-DIR-ENTRY/
+ (my $t = $1) =~ s#\s+# #g; # normalise spaces
+ (wrap $first, $indent, $t) . "\nEND-INFO-DIR-ENTRY"/mse or next;
+
+ $fixed{info_dir}++;
+ next;
+ }
+
+ if (/^Local Variables:/m and /^coding: (\S+)/m)
+ {
+ $encoding = $1;
+ next;
+ }
+}
+continue
+{
+ $last = $_;
+ print OUT;
+}
+
+warn "$0: didn't find menu to correct\n" unless $fixed{menu};
+warn "$0: didn't find info dir entry to correct\n" unless $fixed{info_dir};
+warn "$0: expected utf-8 encoding, found $encoding\n"
+ unless $encoding eq 'utf-8';