Package: po4a
Version: 0.47-2
Severity: normal
Tags: patch

Thanks for the tbl text block handling in po4a's man module!  However,
it doesn't quite handle tables that use tbl's feature to select an
alternate tab character, such as those in man-db (e.g. mandb(8)).
Here's a patch that fixes it up.

Cheers,

-- 
Colin Watson                                       [cjwat...@debian.org]
>From 49e79f980921f31d18358166aee4f5f00087a8a8 Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwat...@debian.org>
Date: Sun, 11 Dec 2016 12:37:04 +0000
Subject: [PATCH] man: Support tab() tbl option

Add support for the tab(<character>) global option inside .TS/.TE.

While we're at it, tidy up trailing newline handling in text blocks a
little.  Since text blocks must be terminated by a newline to be
syntactically valid, the trailing newline shouldn't be translatable.
---
 lib/Locale/Po4a/Man.pm         |  36 +++++++++----
 t/23-man.t                     |  10 +++-
 t/data-23/tbl-option-tab.1     |  20 ++++++++
 t/data-23/tbl-option-tab.fr.1  |  20 ++++++++
 t/data-23/tbl-option-tab.fr.po | 112 ++++++++++++++++++++++++++++++++++++++++
 t/data-23/tbl-option-tab.pot   | 113 +++++++++++++++++++++++++++++++++++++++++
 t/data-23/tbl-textblock.pot    |   4 +-
 7 files changed, 302 insertions(+), 13 deletions(-)
 create mode 100644 t/data-23/tbl-option-tab.1
 create mode 100644 t/data-23/tbl-option-tab.fr.1
 create mode 100644 t/data-23/tbl-option-tab.fr.po
 create mode 100644 t/data-23/tbl-option-tab.pot

diff --git a/lib/Locale/Po4a/Man.pm b/lib/Locale/Po4a/Man.pm
index 68c09d8f..26275c0e 100644
--- a/lib/Locale/Po4a/Man.pm
+++ b/lib/Locale/Po4a/Man.pm
@@ -2190,9 +2190,10 @@ $macro{'ti'}=\&untranslated;
 ###
 $macro{'TS'}=sub {
     my $self=shift;
-    my ($in_headers,$buffer)=(1,"");
+    my ($in_headers,$tab,$buffer)=(1,"\t","");
     my ($in_textblock,$preline,$postline)=(0,"","");
     my ($line,$ref)=$self->shiftline();
+    my @options;
 
     # Push table start
     $self->pushmacro(@_);
@@ -2203,7 +2204,11 @@ $macro{'TS'}=sub {
             return;
         }
         if ($in_headers) {
-            if ($line =~ /\.$/) {
+            if ($line =~ /;$/) { # global options line
+                if ($line =~ /\btab\s*\((.)\)/) {
+                    $tab = $1;
+                }
+            } elsif ($line =~ /\.$/) {
                 $in_headers = 0;
             }
             $self->pushline($self->r($line));
@@ -2211,10 +2216,16 @@ $macro{'TS'}=sub {
             $in_textblock = 0;
             $preline = $&; # save the `T}' marker to be output later
             $line = $';    # save the remaing part of the line
+            # Drop any EOL from entry to be translated and save it for
+            # output below.
+            if (chomp $buffer) {
+                $postline .= "\n";
+            }
             $self->pushline($self->translate($buffer,
                                              $ref,
-                                            'tbl table'));
-            $buffer = "";
+                                            'tbl table')
+                            .$postline);
+            $buffer = $postline = "";
             next; # continue processing with the remaining part of the line
         } elsif ($in_textblock && $line =~ /^[.']/) {
             # TODO: properly handle macros inside text blocks, currently we mark them
@@ -2233,19 +2244,24 @@ $macro{'TS'}=sub {
             if ($line =~ s/\s*T\{\s*$//) { # start of text block
               $in_textblock = 1;
               $postline = $&; # save the `T{' to be outputed below
-            } elsif ($buffer eq "" && $line ne ""){ # single line data
-              chomp $line; # drop eol char from the entry to be translated
-              $postline = "\n"; # and save the eol for output below
             }
 
             $buffer .= $line;
-            # Arguments to translate are separated by \t
+            # Drop any EOL from entry to be translated and save it for
+            # output below.
+            if (chomp $buffer) {
+                $postline .= "\n";
+            }
+            # Arguments to translate are separated by the table's tab
+            # character (\t by default).  We must be careful to preserve
+            # empty trailing fields, since in particular a text block is
+            # likely to show up as an empty trailing field here.
             $self->pushline($preline
-                            .join("\t",
+                            .join($tab,
                                  map { $self->translate($_,
                                                         $ref,
                                                         'tbl table')
-                                     } split (/\t/,$buffer))
+                                     } split (/\Q$tab/,$buffer,-1))
                            .$postline);
 
             $buffer = $preline = $postline = "";
diff --git a/t/23-man.t b/t/23-man.t
index 6d08fddc..76fa08e4 100644
--- a/t/23-man.t
+++ b/t/23-man.t
@@ -137,6 +137,14 @@ push @tests, {
     'run'  => "LC_ALL=C perl ../po4a-gettextize -f #format# -m data-23/tbl-textblock.1 -p tmp/tbl-textblock.pot 2>/dev/null",
     'test' => "perl compare-po.pl data-23/tbl-textblock.pot tmp/tbl-textblock.pot",
     'doc'  => "Right handling of text blocs in tbl macros",
+}, {
+    'run'  => "LC_ALL=C perl ../po4a-gettextize -f #format# -m data-23/tbl-option-tab.1 -p tmp/tbl-option-tab.pot 2>/dev/null",
+    'test' => "perl compare-po.pl data-23/tbl-option-tab.pot tmp/tbl-option-tab.pot",
+    'doc'  => "Handle tab option in tab macros",
+}, {
+    'run'  => "perl ../po4a-translate -f #format# -m data-23/tbl-option-tab.1 -p data-23/tbl-option-tab.fr.po -l tmp/tbl-option-tab.fr.1",
+    'test' => "diff -u $diff_pod_flags data-23/tbl-option-tab.fr.1 tmp/tbl-option-tab.fr.1",
+    'doc'  => "translate this document",
 };
 
 # Mixed mdoc and roff format
@@ -204,7 +212,7 @@ push @tests, {
   'doc'  => "translate this document",
 };
 
-use Test::More tests => 72; # $formats * $tests * 2
+use Test::More tests => 76; # $formats * $tests * 2
 
 foreach my $format (@formats) {
     for (my $i=0; $i<scalar @tests; $i++) {
diff --git a/t/data-23/tbl-option-tab.1 b/t/data-23/tbl-option-tab.1
new file mode 100644
index 00000000..21681358
--- /dev/null
+++ b/t/data-23/tbl-option-tab.1
@@ -0,0 +1,20 @@
+.\" This chunk comes from mandb(8).
+
+.TS
+tab (@);
+l l l l.
+Name@Type@Async@Filename
+_
+Berkeley db@T{
+Binary tree
+T}@Yes@\fIindex.bt\fR
+GNU gdbm v >= 1.6@T{
+Hashed
+T}@Yes@\fIindex.db\fR
+GNU gdbm v <  1.6@T{
+Hashed
+T}@No@\fIindex.db\fR
+UNIX ndbm@T{
+Hashed
+T}@No@\fIindex.(dir|pag)\fR
+.TE
diff --git a/t/data-23/tbl-option-tab.fr.1 b/t/data-23/tbl-option-tab.fr.1
new file mode 100644
index 00000000..cc96d050
--- /dev/null
+++ b/t/data-23/tbl-option-tab.fr.1
@@ -0,0 +1,20 @@
+
+.\" This chunk comes from mandb(8).
+.TS
+tab (@);
+l l l l.
+Nom@Type@Async@Nom de fichier
+_
+Berkeley db@T{
+Arbre Binaire
+T}@Oui@\fIindex.bt\fP
+GNU gdbm v >= 1.6@T{
+Hachage
+T}@Oui@\fIindex.db\fP
+GNU gdbm v < 1.6@T{
+Hachage
+T}@Non@\fIindex.db\fP
+UNIX ndbm@T{
+Hachage
+T}@Non@\fIindex.(dir|pag)\fP
+.TE
diff --git a/t/data-23/tbl-option-tab.fr.po b/t/data-23/tbl-option-tab.fr.po
new file mode 100644
index 00000000..69670fd0
--- /dev/null
+++ b/t/data-23/tbl-option-tab.fr.po
@@ -0,0 +1,112 @@
+# SOME DESCRIPTIVE TITLE
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2016-12-11 11:35+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <l...@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Name"
+msgstr "Nom"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Type"
+msgstr "Type"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Async"
+msgstr "Async"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Filename"
+msgstr "Nom de fichier"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:7
+#, no-wrap
+msgid "_"
+msgstr "_"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:8
+#, no-wrap
+msgid "Berkeley db"
+msgstr "Berkeley db"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10
+#, no-wrap
+msgid "Binary tree"
+msgstr "Arbre Binaire"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10 data-23/tbl-option-tab.1:13
+#, no-wrap
+msgid "Yes"
+msgstr "Oui"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10
+#, no-wrap
+msgid "I<index.bt>"
+msgstr "I<index.bt>"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:11
+#, no-wrap
+msgid "GNU gdbm v E<gt>= 1.6"
+msgstr "GNU gdbm v E<gt>= 1.6"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:13 data-23/tbl-option-tab.1:16 data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "Hashed"
+msgstr "Hachage"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:13 data-23/tbl-option-tab.1:16
+#, no-wrap
+msgid "I<index.db>"
+msgstr "I<index.db>"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:14
+#, no-wrap
+msgid "GNU gdbm v E<lt>  1.6"
+msgstr "GNU gdbm v E<lt> 1.6"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:16 data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "No"
+msgstr "Non"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:17
+#, no-wrap
+msgid "UNIX ndbm"
+msgstr "UNIX ndbm"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "I<index.(dir|pag)>"
+msgstr "I<index.(dir|pag)>"
diff --git a/t/data-23/tbl-option-tab.pot b/t/data-23/tbl-option-tab.pot
new file mode 100644
index 00000000..2fabe06a
--- /dev/null
+++ b/t/data-23/tbl-option-tab.pot
@@ -0,0 +1,113 @@
+# SOME DESCRIPTIVE TITLE
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2016-12-11 11:35+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <l...@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Name"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Type"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Async"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:6
+#, no-wrap
+msgid "Filename"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:7
+#, no-wrap
+msgid "_"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:8
+#, no-wrap
+msgid "Berkeley db"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10
+#, no-wrap
+msgid "Binary tree"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10 data-23/tbl-option-tab.1:13
+#, no-wrap
+msgid "Yes"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:10
+#, no-wrap
+msgid "I<index.bt>"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:11
+#, no-wrap
+msgid "GNU gdbm v E<gt>= 1.6"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:13 data-23/tbl-option-tab.1:16 data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "Hashed"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:13 data-23/tbl-option-tab.1:16
+#, no-wrap
+msgid "I<index.db>"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:14
+#, no-wrap
+msgid "GNU gdbm v E<lt>  1.6"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:16 data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "No"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:17
+#, no-wrap
+msgid "UNIX ndbm"
+msgstr ""
+
+#. type: tbl table
+#: data-23/tbl-option-tab.1:19
+#, no-wrap
+msgid "I<index.(dir|pag)>"
+msgstr ""
diff --git a/t/data-23/tbl-textblock.pot b/t/data-23/tbl-textblock.pot
index 811320f9..26ffc8e4 100644
--- a/t/data-23/tbl-textblock.pot
+++ b/t/data-23/tbl-textblock.pot
@@ -35,7 +35,7 @@ msgid ""
 "cpu utilization of the process in \"##.#\" format.  It is the CPU time\n"
 "used divided by the time the process has been running (cputime/realtime\n"
 "ratio), expressed as a percentage. It will not add up to 100% unless you\n"
-"are lucky.  (alias\\ B<pcpu>).\n"
+"are lucky.  (alias\\ B<pcpu>)."
 msgstr ""
 
 #. type: tbl table
@@ -85,5 +85,5 @@ msgstr ""
 #. type: tbl table
 #: data-23/tbl-textblock.1:31
 #, no-wrap
-msgid "?       unknown value\n"
+msgid "?       unknown value"
 msgstr ""
-- 
2.11.0

Reply via email to