aboutsummaryrefslogtreecommitdiff
path: root/internal/bible/booktable.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 13:35:24 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 13:35:24 +0200
commit22bfec8fc13a20a8d95a4609b4a02bb48acede5a (patch)
tree6416eb2345df1885863063e931e72222fdd622bc /internal/bible/booktable.go
parent4c23ae5107690a77a4253eaecbb7dfa822bdffc3 (diff)
downloadlectio-22bfec8fc13a20a8d95a4609b4a02bb48acede5a.tar.gz
lectio-22bfec8fc13a20a8d95a4609b4a02bb48acede5a.zip
citation: render --citation/--week gospel ref in the configured sigla dialect (bible.FormatRef); v0.11.0
Diffstat (limited to 'internal/bible/booktable.go')
-rw-r--r--internal/bible/booktable.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/bible/booktable.go b/internal/bible/booktable.go
index eb3b4e4..007e75e 100644
--- a/internal/bible/booktable.go
+++ b/internal/bible/booktable.go
@@ -141,6 +141,38 @@ func (t *BookTable) ParseRef(dialect, input string) (string, bool) {
return "", false
}
+// shortcut returns the dialect's primary abbreviation (the first form) for a
+// canonical book, or "" when the dialect has no entry for it.
+func (t *BookTable) shortcut(dialect, canonical string) string {
+ if forms := t.forms[dialect][canonical]; len(forms) > 0 {
+ return forms[0]
+ }
+ return ""
+}
+
+// FormatRef renders a canonical English reference ("John 20:1,11-18") in the
+// dialect's sigla: the dialect's book shortcut plus its number style -- English
+// "Jn 20:1,11-18" (colon chapter:verse, comma groups); Polish "J 20, 1. 11-18"
+// (comma chapter, verse; period groups). It is the inverse of ParseRef's
+// normalizeSigla. If canonicalRef can't be parsed or the book is not in the
+// dialect, it is returned unchanged (a safe, still-readable fallback).
+func (t *BookTable) FormatRef(dialect, canonicalRef string) string {
+ m := refRe.FindStringSubmatch(strings.TrimSpace(canonicalRef))
+ if m == nil {
+ return canonicalRef
+ }
+ canon, chap, verses := m[1], m[2], m[3]
+ abbrev := t.shortcut(dialect, canon)
+ if abbrev == "" {
+ return canonicalRef
+ }
+ if dialect == "pl" {
+ verses = strings.ReplaceAll(verses, ",", ". ") // disjoint groups
+ return abbrev + " " + chap + ", " + verses
+ }
+ return abbrev + " " + chap + ":" + verses
+}
+
// normalizeSigla rewrites a dialect's verse-reference tail into the colon/comma
// form bible.Lookup expects: "<chap>:<groups>", groups comma-separated, ranges
// with "-". Polish uses a comma (with or without a space) as the chapter/verse