Skip to content

Commit

Permalink
fix the fix for mquinson#416 :-)
Browse files Browse the repository at this point in the history
This takes into account:

 * variables in the index entry
 * quoted index entries
  • Loading branch information
jnavila committed Jun 10, 2023
1 parent 9fed8e2 commit 19b44af
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
38 changes: 28 additions & 10 deletions lib/Locale/Po4a/AsciiDoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1176,18 +1176,36 @@ sub do_paragraph {
my $pattern = qr/\(\(\(([^\)]+)\)\)\)/;
if ( my @indexes = ($paragraph =~ m/$pattern/g ) ) {
for my $index (@indexes) {
my @trans_list = map {$self->translate(
$_,
$self->{ref},
"Index entry",
"wrap" => 1,
"wrapcol" => 0);} split(/,/, $index);

$paragraph =~ s/\(\(\($index\)\)\)\n?//;
$self->pushline("(((" . join (",", @trans_list) . ")))");
my @terms = ();
while (
$index =~ m/\G(
"(?:[^"\\])+" # quoted term
| (?:[^,\\])+ # unquoted term
)(,\s*+)?/gx
)
{
my $term = $1;
if ( $term =~ /^"(.*)"$/ ) {
push @terms, '"' . ($self->translate(
$1,
$self->{ref},
"Index entry",
"wrap" => 1,
"wrapcol" => 0)) . '"';
} else {
push @terms, $self->translate(
$term,
$self->{ref},
"Index entry",
"wrap" => 1,
"wrapcol" => 0);
}
}
$paragraph =~ s/\(\(\(\Q$index\E\)\)\)\n?//;
$self->pushline("(((" . join (",", @terms) . ")))");

}
}

my $t = $self->translate(
$paragraph,
$self->{ref},
Expand Down
4 changes: 2 additions & 2 deletions t/fmt/asciidoc/IndexEntries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ a paragraph preceded by an entry in the index

a paragraph followed by an entry in the index(((index entry 2)))

(((index entry 3)))(((index entry 4)))
(((index entry 3)))(((index {entry} 4)))
a paragraph preceded by two entries in the index

(((index entry 3,subentry 1)))(((index entry 5,subentry 2)))
(((index entry 3,subentry 1)))((("index entry 5","subentry 2, with comma")))
a paragraph with entry and subentry
4 changes: 2 additions & 2 deletions t/fmt/asciidoc/IndexEntries.norm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

(((index entry 2)))a paragraph followed by an entry in the index

(((index entry 3)))(((index entry 4)))a paragraph preceded by two entries in the index
(((index entry 3)))(((index {entry} 4)))a paragraph preceded by two entries in the index

(((index entry 3,subentry 1)))(((index entry 5,subentry 2)))a paragraph with entry and subentry
(((index entry 3,subentry 1)))((("index entry 5","subentry 2, with comma")))a paragraph with entry and subentry
8 changes: 4 additions & 4 deletions t/fmt/asciidoc/IndexEntries.po
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ msgstr "INDEX ENTRY 3"

#. type: Index entry
#: IndexEntries.adoc:8
msgid "index entry 4"
msgstr "INDEX ENTRY 4"
msgid "index {entry} 4"
msgstr "INDEX {ENTRY} 4"

#. type: Plain text
#: IndexEntries.adoc:8
Expand All @@ -62,8 +62,8 @@ msgstr "INDEX ENTRY 5"

#. type: Index entry
#: IndexEntries.adoc:10
msgid "subentry 2"
msgstr "SUBENTRY 2"
msgid "subentry 2, with comma"
msgstr "SUBENTRY 2, WITH COMMA"

#. type: Plain text
#: IndexEntries.adoc:10
Expand Down
4 changes: 2 additions & 2 deletions t/fmt/asciidoc/IndexEntries.pot
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ msgstr ""

#. type: Index entry
#: IndexEntries.adoc:8
msgid "index entry 4"
msgid "index {entry} 4"
msgstr ""

#. type: Plain text
Expand All @@ -63,7 +63,7 @@ msgstr ""

#. type: Index entry
#: IndexEntries.adoc:10
msgid "subentry 2"
msgid "subentry 2, with comma"
msgstr ""

#. type: Plain text
Expand Down
4 changes: 2 additions & 2 deletions t/fmt/asciidoc/IndexEntries.trans
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

(((INDEX ENTRY 2)))A PARAGRAPH FOLLOWED BY AN ENTRY IN THE INDEX

(((INDEX ENTRY 3)))(((INDEX ENTRY 4)))A PARAGRAPH PRECEDED BY TWO ENTRIES IN THE INDEX
(((INDEX ENTRY 3)))(((INDEX {ENTRY} 4)))A PARAGRAPH PRECEDED BY TWO ENTRIES IN THE INDEX

(((INDEX ENTRY 3,SUBENTRY 1)))(((INDEX ENTRY 5,SUBENTRY 2)))A PARAGRAPH WITH ENTRY AND SUBENTRY
(((INDEX ENTRY 3,SUBENTRY 1)))((("INDEX ENTRY 5","SUBENTRY 2, WITH COMMA")))A PARAGRAPH WITH ENTRY AND SUBENTRY

0 comments on commit 19b44af

Please sign in to comment.