diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/cli/cli.go | 16 | ||||
| -rw-r--r-- | internal/cli/cli_test.go | 14 | ||||
| -rw-r--r-- | internal/cli/liturgy.go | 41 | ||||
| -rw-r--r-- | internal/cli/liturgy_test.go | 32 |
4 files changed, 89 insertions, 14 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go index eb01039..364e080 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -219,6 +219,9 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { fmt.Fprintln(stderr, "lectio:", err) return 1 } + if dir, err := config.CorporaDir(); err == nil { + bible.SetUserCorporaDir(dir) + } if offline { cfg.Offline = true } @@ -1031,8 +1034,12 @@ func lookupRef(cfg config.Config, tbl *bible.BookTable, ref string, versions []s } // runList handles --list: print every book of the sigla dialect (scriptural -// order) as "<shortcut> <name>". The shortcut column is padded by rune count -// so diacritics ("Łk") still line up. +// order) as "<shortcut> <name>", followed by a "Versions:" block listing +// every known bible corpus -- built-in and user/drop-in alike (see +// bible.Corpora, which SetUserCorporaDir keeps current) -- as "<code> +// <label>". A corpus with no localized i18n chrome label (any user corpus, +// e.g.) shows its sidecar Name instead (see versionDisplayName). The +// shortcut column is padded by rune count so diacritics ("Łk") still line up. func runList(tbl *bible.BookTable, dialect string, stdout io.Writer) int { const col = 8 for _, b := range tbl.Books(dialect) { @@ -1042,6 +1049,11 @@ func runList(tbl *bible.BookTable, dialect string, stdout io.Writer) int { } fmt.Fprintf(stdout, "%s%s%s\n", b.Shortcut, strings.Repeat(" ", pad), b.Name) } + fmt.Fprintln(stdout) + fmt.Fprintln(stdout, "Versions:") + for _, m := range bible.Corpora() { + fmt.Fprintf(stdout, " %-6s %s\n", m.Code, versionDisplayName(dialect, m.Code)) + } return 0 } diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 3b99562..b08ffba 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -318,6 +318,20 @@ func TestListFlag(t *testing.T) { } } +func TestListSurfacesUserCorpus(t *testing.T) { + bible.SetUserCorporaDir("../bible/testdata/corpora") + t.Cleanup(func() { bible.SetUserCorporaDir("") }) + + tbl, _ := bible.LoadBookTable(nil) + var out bytes.Buffer + if code := runList(tbl, "en", &out); code != 0 { + t.Fatalf("runList code=%d", code) + } + if s := out.String(); !strings.Contains(s, "good") || !strings.Contains(s, "Good Test Corpus") { + t.Errorf("--list did not surface the user fixture corpus:\n%s", s) + } +} + func TestRefEnglishDialect(t *testing.T) { var out, errb bytes.Buffer if code := Run([]string{"-p", "Jn 3:16", "-b", "vul"}, nil, &out, &errb); code != 0 { diff --git a/internal/cli/liturgy.go b/internal/cli/liturgy.go index bb250a5..ced23ae 100644 --- a/internal/cli/liturgy.go +++ b/internal/cli/liturgy.go @@ -61,18 +61,35 @@ func dayReadings(sel calendar.Selection, layers []calendar.Layer, date time.Time return nil } -// vernacularVersion is the COMPLETE offline corpus used to render reading text. -// The Wujek (wuj) corpus is intentionally NOT auto-selected here: it lacks the -// deuterocanonical Daniel/Esther additions and ~400 verses its builder dropped, -// so Polish renders from the complete Latin Vulgate until a properly-formatted -// Polish Bible is supplied as a user corpus (the national-bibles feature). wuj -// stays available for explicit `--ref -b wuj` and version comparison. English -// uses Douay-Rheims (complete after the deuterocanon backfill); bt is scraped. +// vernacularVersion is the corpus that renders reading text: the config's +// resolved reading corpus (Config.ReadingCorpus -- an explicit +// reading_version, else a reading_lang/ui_language match against +// autoselect-eligible corpora), else the complete Latin Vulgate. The +// built-in Wujek (wuj) sets autoselect=false in its sidecar (it lacks the +// deuterocanonical Daniel/Esther additions and ~400 verses its builder +// dropped), so Polish still falls back to Latin until a properly-formatted +// Polish Bible is supplied as a user corpus (the national-bibles feature); +// wuj stays available for explicit `--ref -b wuj` and version comparison. func vernacularVersion(cfg config.Config) string { - if cfg.TraditionalLang == "pl" || cfg.UILanguage == "pl" { - return "vul" // Latin: no complete Polish corpus yet (wuj is defective) + if code := cfg.ReadingCorpus(); code != "" { + return code } - return "drb" + return latinFallback // "vul" +} + +// versionDisplayName resolves a corpus code's display label for lang: the +// localized i18n chrome label (internal/i18n) when lang defines one for +// code, else the corpus's own sidecar Name (bible.Meta -- covers user and +// other registered corpora the built-in i18n tables don't know about), else +// the bare code. +func versionDisplayName(lang, code string) string { + if l, ok := i18n.Get(lang).Version[code]; ok { + return l + } + if m, ok := bible.Meta(code); ok && m.Name != "" { + return m.Name + } + return code } // latinFallback is the corpus used to render a passage the vernacular corpus @@ -138,8 +155,8 @@ func printLiturgicalDay(out io.Writer, cfg config.Config, tbl *bible.BookTable, continue } if used != vern { // the vernacular lacked it; fell back to Latin - names := i18n.Get("en").Version - fmt.Fprintf(out, " [%s has no text here -- showing %s]\n", names[vern], names[used]) + fmt.Fprintf(out, " [%s has no text here -- showing %s]\n", + versionDisplayName("en", vern), versionDisplayName("en", used)) } for _, line := range strings.Split(render.Wrap(txt, 72), "\n") { fmt.Fprintf(out, " %s\n", line) diff --git a/internal/cli/liturgy_test.go b/internal/cli/liturgy_test.go index 91e3974..67303f3 100644 --- a/internal/cli/liturgy_test.go +++ b/internal/cli/liturgy_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/lukaszkasprzak/lectio/internal/bible" "github.com/lukaszkasprzak/lectio/internal/config" ) @@ -55,6 +56,37 @@ func TestRunLiturgyTraditionalComputesEF(t *testing.T) { } } +func TestVernacularVersionResolver(t *testing.T) { + if got := vernacularVersion(config.Config{ReadingVersion: "drb"}); got != "drb" { + t.Fatalf("explicit: %q", got) + } + if got := vernacularVersion(config.Config{UILanguage: "pl"}); got != "vul" { + t.Fatalf("pl should fall back to Latin: %q", got) + } + if got := vernacularVersion(config.Config{UILanguage: "en"}); got != "drb" { + t.Fatalf("en should be drb: %q", got) + } +} + +func TestVersionDisplayNameFallsBackToCorpusMeta(t *testing.T) { + bible.SetUserCorporaDir("../bible/testdata/corpora") + t.Cleanup(func() { bible.SetUserCorporaDir("") }) + + // "good" is a user fixture with no i18n entry; its sidecar Name must + // surface instead of the bare code. + if got := versionDisplayName("en", "good"); got != "Good Test Corpus" { + t.Fatalf("expected sidecar Name fallback, got %q", got) + } + // a known i18n code still uses the localized chrome label. + if got := versionDisplayName("en", "drb"); got == "drb" { + t.Fatalf("expected localized label, got bare code %q", got) + } + // a totally unknown code with no sidecar falls back to the bare code. + if got := versionDisplayName("en", "zzz-nope"); got != "zzz-nope" { + t.Fatalf("expected bare-code fallback, got %q", got) + } +} + func TestRunLiturgyUserLayer(t *testing.T) { dir := t.TempDir() t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini")) |
