aboutsummaryrefslogtreecommitdiff
path: root/internal/render
diff options
context:
space:
mode:
Diffstat (limited to 'internal/render')
-rw-r--r--internal/render/render.go16
-rw-r--r--internal/render/render_test.go18
2 files changed, 34 insertions, 0 deletions
diff --git a/internal/render/render.go b/internal/render/render.go
index 7ba8ebd..6cdb939 100644
--- a/internal/render/render.go
+++ b/internal/render/render.go
@@ -65,6 +65,22 @@ func LocalizeHeading(heading, partID, lang string) string {
return heading
}
+// HeadingWithRef returns a section's localised heading with its scripture
+// reference appended in parentheses when the heading does not already carry
+// one. The modern (niedziela) heading already embeds its citation -- e.g.
+// "Ewangelia (J 20, 1. 11-18)" -- while the traditional (missalemeum) heading
+// is a bare label ("Gospel"/"Ewangelia") with the reference only in
+// sec.Citation; this appends it so every reading shows where it is from,
+// uniformly across cli/tui/web. The citation is source-form (like the modern
+// one), never translated.
+func HeadingWithRef(sec liturgy.Section, lang string) string {
+ heading := LocalizeHeading(sec.Heading, sec.PartID, lang)
+ if sec.Citation != "" && !strings.Contains(heading, "(") {
+ heading += " (" + sec.Citation + ")"
+ }
+ return heading
+}
+
// versionSystem maps a bible version to the Psalter system bible.ToEnglishRef
// expects: vul/grb/wuj follow the Vulgate/Septuagint numbering, drb follows
// the Hebrew chapter with the DRB title-fold verse shift. Ported from
diff --git a/internal/render/render_test.go b/internal/render/render_test.go
index 496dc23..e2a26fc 100644
--- a/internal/render/render_test.go
+++ b/internal/render/render_test.go
@@ -181,6 +181,24 @@ func TestGatherVersesLabelLang(t *testing.T) {
// replaced by its en label, the citation kept exactly as scraped, and every
// other case (pl, unknown/traditional partID, prefix mismatch) is a safe
// no-op that returns heading unchanged.
+func TestHeadingWithRef(t *testing.T) {
+ // Traditional-style: a bare label plus Citation -> reference appended.
+ trad := liturgy.Section{Heading: "Gospel", Citation: "Luke 16:1-9", PartID: "evangelium"}
+ if got := HeadingWithRef(trad, "en"); got != "Gospel (Luke 16:1-9)" {
+ t.Errorf("traditional heading = %q, want %q", got, "Gospel (Luke 16:1-9)")
+ }
+ // Modern-style: heading already carries "(...)" -> not doubled; the pl label
+ // is still localised to en.
+ modern := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)", Citation: "J 20, 1. 11-18", PartID: "ewangelia"}
+ if got := HeadingWithRef(modern, "en"); got != "Gospel (J 20, 1. 11-18)" {
+ t.Errorf("modern heading = %q", got)
+ }
+ // No citation -> unchanged.
+ if got := HeadingWithRef(liturgy.Section{Heading: "Gospel", PartID: "evangelium"}, "en"); got != "Gospel" {
+ t.Errorf("no-citation heading = %q", got)
+ }
+}
+
func TestLocalizeHeading(t *testing.T) {
cases := []struct {
name, heading, partID, lang, want string