Skip to content

Commit

Permalink
asciidoc: process transparent index entries in their own segment
Browse files Browse the repository at this point in the history
This patch addresses the issue of keeping transparent index entries in
paragraphs. It does not address "visible" index entries, which are
formatted with ((...)).

This addresses GH mquinson#416.
  • Loading branch information
jnavila committed Jun 7, 2023
1 parent 5766962 commit 8bd88bc
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/Locale/Po4a/AsciiDoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,22 @@ sub do_paragraph {
$end = $2 || "";
}

# Detect index entries and translate them separately
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 $t = $self->translate(
$paragraph,
$self->{ref},
Expand Down
2 changes: 1 addition & 1 deletion t/fmt-asciidoc.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Testhelper;
my @tests;

foreach my $t (
qw(Titles BlockTitles BlockId Paragraphs DelimitedBlocks Lists Footnotes Callouts Comments Tables TablesImageText Attributes StyleMacro MacroIncludesHugo)
qw(Titles BlockTitles BlockId Paragraphs DelimitedBlocks Lists Footnotes Callouts Comments Tables TablesImageText Attributes StyleMacro MacroIncludesHugo IndexEntries)
)
{
push @tests, { 'format' => 'asciidoc', 'input' => "fmt/asciidoc/$t.adoc" };
Expand Down
10 changes: 10 additions & 0 deletions t/fmt/asciidoc/IndexEntries.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(((index entry 1)))
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)))
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
7 changes: 7 additions & 0 deletions t/fmt/asciidoc/IndexEntries.norm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(((index entry 1)))a paragraph preceded by an entry in the index

(((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,subentry 1)))(((index entry 5,subentry 2)))a paragraph with entry and subentry
71 changes: 71 additions & 0 deletions t/fmt/asciidoc/IndexEntries.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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: 2023-06-07 21:17+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#. type: Index entry
#: IndexEntries.adoc:3
msgid "index entry 1"
msgstr "INDEX ENTRY 1"

#. type: Plain text
#: IndexEntries.adoc:3
msgid "a paragraph preceded by an entry in the index"
msgstr "A PARAGRAPH PRECEDED BY AN ENTRY IN THE INDEX"

#. type: Index entry
#: IndexEntries.adoc:5
msgid "index entry 2"
msgstr "INDEX ENTRY 2"

#. type: Plain text
#: IndexEntries.adoc:5
msgid "a paragraph followed by an entry in the index"
msgstr "A PARAGRAPH FOLLOWED BY AN ENTRY IN THE INDEX"

#. type: Index entry
#: IndexEntries.adoc:8 IndexEntries.adoc:10
msgid "index entry 3"
msgstr "INDEX ENTRY 3"

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

#. type: Plain text
#: IndexEntries.adoc:8
msgid "a paragraph preceded by two entries in the index"
msgstr "A PARAGRAPH PRECEDED BY TWO ENTRIES IN THE INDEX"

#. type: Index entry
#: IndexEntries.adoc:10
msgid "subentry 1"
msgstr "SUBENTRY 1"

#. type: Index entry
#: IndexEntries.adoc:10
msgid "index entry 5"
msgstr "INDEX ENTRY 5"

#. type: Index entry
#: IndexEntries.adoc:10
msgid "subentry 2"
msgstr "SUBENTRY 2"

#. type: Plain text
#: IndexEntries.adoc:10
msgid "a paragraph with entry and subentry"
msgstr "A PARAGRAPH WITH ENTRY AND SUBENTRY"
72 changes: 72 additions & 0 deletions t/fmt/asciidoc/IndexEntries.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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: 2023-06-07 21:17+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#. type: Index entry
#: IndexEntries.adoc:3
msgid "index entry 1"
msgstr ""

#. type: Plain text
#: IndexEntries.adoc:3
msgid "a paragraph preceded by an entry in the index"
msgstr ""

#. type: Index entry
#: IndexEntries.adoc:5
msgid "index entry 2"
msgstr ""

#. type: Plain text
#: IndexEntries.adoc:5
msgid "a paragraph followed by an entry in the index"
msgstr ""

#. type: Index entry
#: IndexEntries.adoc:8 IndexEntries.adoc:10
msgid "index entry 3"
msgstr ""

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

#. type: Plain text
#: IndexEntries.adoc:8
msgid "a paragraph preceded by two entries in the index"
msgstr ""

#. type: Index entry
#: IndexEntries.adoc:10
msgid "subentry 1"
msgstr ""

#. type: Index entry
#: IndexEntries.adoc:10
msgid "index entry 5"
msgstr ""

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

#. type: Plain text
#: IndexEntries.adoc:10
msgid "a paragraph with entry and subentry"
msgstr ""
7 changes: 7 additions & 0 deletions t/fmt/asciidoc/IndexEntries.trans
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(((INDEX ENTRY 1)))A PARAGRAPH PRECEDED BY AN ENTRY IN THE INDEX

(((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,SUBENTRY 1)))(((INDEX ENTRY 5,SUBENTRY 2)))A PARAGRAPH WITH ENTRY AND SUBENTRY

0 comments on commit 8bd88bc

Please sign in to comment.