From 4c776396115c8120c3e1cb8fda993449fcdcd326 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Thu, 23 Jul 2026 21:51:40 +0200 Subject: i18n: ui_language config (default en) for UI chrome across cli/tui/web; version labels localised --- internal/render/render_test.go | 82 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 5 deletions(-) (limited to 'internal/render/render_test.go') diff --git a/internal/render/render_test.go b/internal/render/render_test.go index 1b338a0..b016d6b 100644 --- a/internal/render/render_test.go +++ b/internal/render/render_test.go @@ -12,7 +12,7 @@ func TestGatherPLDedup(t *testing.T) { Heading: "Psalm (Ps 1)", Paragraphs: [][]string{{"stanza one"}, {"refrain"}, {"stanza two"}, {"refrain"}}, } - _, blocks := GatherVersion("pl", sec, "new") + _, blocks := GatherVersion("pl", sec, "new", "pl") n := 0 for _, b := range blocks { if b == "refrain" { @@ -26,7 +26,7 @@ func TestGatherPLDedup(t *testing.T) { func TestGatherBible(t *testing.T) { sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"} - label, blocks := GatherVersion("wuj", sec, "new") + label, blocks := GatherVersion("wuj", sec, "new", "pl") if !strings.Contains(label, "Wujek") { t.Errorf("label = %q", label) } @@ -37,12 +37,45 @@ func TestGatherBible(t *testing.T) { func TestGatherTraditional(t *testing.T) { sec := liturgy.Section{Citation: "Luke 7:36-50"} - _, blocks := GatherVersion("vul", sec, "traditional") + _, blocks := GatherVersion("vul", sec, "traditional", "pl") if len(blocks) == 0 || !strings.HasPrefix(blocks[0], "7:36") { t.Errorf("first block = %q", blocks) } } +// TestGatherVersionLabelLang checks that the label's language follows the +// lang parameter -- pl reproduces today's Polish labels exactly, en gives +// the English set from internal/i18n. +func TestGatherVersionLabelLang(t *testing.T) { + sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"} + + label, _ := GatherVersion("vul", sec, "new", "pl") + if label != "Wulgata (lac.)" { + t.Errorf(`GatherVersion(..., "pl") label = %q, want "Wulgata (lac.)"`, label) + } + + label, _ = GatherVersion("vul", sec, "new", "en") + if label != "Vulgate (Latin)" { + t.Errorf(`GatherVersion(..., "en") label = %q, want "Vulgate (Latin)"`, label) + } +} + +// TestCompareLabelLang checks Compare's column-header row follows lang, +// same as GatherVersion (which it wraps via compareSection). +func TestCompareLabelLang(t *testing.T) { + sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"} + + out := Compare([]liturgy.Section{sec}, []string{"vul"}, 80, "new", "pl") + if !strings.Contains(out, "Wulgata (lac.)") { + t.Errorf(`Compare(..., "pl") = %q, want it to contain "Wulgata (lac.)"`, out) + } + + out = Compare([]liturgy.Section{sec}, []string{"vul"}, 80, "new", "en") + if !strings.Contains(out, "Vulgate (Latin)") { + t.Errorf(`Compare(..., "en") = %q, want it to contain "Vulgate (Latin)"`, out) + } +} + func TestOfflineVersions(t *testing.T) { got := OfflineVersions([]string{"pl", "wuj", "vul"}) for _, v := range got { @@ -54,7 +87,7 @@ func TestOfflineVersions(t *testing.T) { func TestGatherVersesBible(t *testing.T) { sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"} - label, verses, versified := GatherVerses("wuj", sec, "new") + label, verses, versified := GatherVerses("wuj", sec, "new", "pl") if !strings.Contains(label, "Wujek") { t.Errorf("label = %q", label) } @@ -74,7 +107,7 @@ func TestGatherVersesPL(t *testing.T) { Heading: "Psalm (Ps 1)", Paragraphs: [][]string{{"stanza one"}}, } - _, verses, versified := GatherVerses("pl", sec, "new") + _, verses, versified := GatherVerses("pl", sec, "new", "pl") if versified { t.Error("versified = true, want false for pl (paragraph text, no verse numbers)") } @@ -82,3 +115,42 @@ func TestGatherVersesPL(t *testing.T) { t.Errorf("verses = %+v, want nil for pl", verses) } } + +// TestGatherVersesLabelLang checks GatherVerses' label also follows lang, +// same as GatherVersion. +func TestGatherVersesLabelLang(t *testing.T) { + sec := liturgy.Section{Heading: "Ewangelia (J 20, 1. 11-18)"} + label, _, _ := GatherVerses("vul", sec, "new", "en") + if label != "Vulgate (Latin)" { + t.Errorf(`GatherVerses(..., "en") label = %q, want "Vulgate (Latin)"`, label) + } +} + +// TestLocalizeHeading covers render.LocalizeHeading's part-label swap +// (brief §3b): the pl label prefix of a modern (niedziela.pl) heading is +// 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 TestLocalizeHeading(t *testing.T) { + cases := []struct { + name, heading, partID, lang, want string + }{ + {"gospel en", "Ewangelia (J 20, 1. 11-18)", "ewangelia", "en", "Gospel (J 20, 1. 11-18)"}, + {"first reading en", "1. czytanie (Dz 2, 14. 22-33)", "pierwsze_czytanie", "en", "1st reading (Dz 2, 14. 22-33)"}, + {"psalm en", "Psalm (Ps 15)", "psalm", "en", "Psalm (Ps 15)"}, + {"acclamation en", "Aklamacja (Alleluja)", "aklamacja", "en", "Acclamation (Alleluja)"}, + {"pl unchanged", "Ewangelia (J 20, 1. 11-18)", "ewangelia", "pl", "Ewangelia (J 20, 1. 11-18)"}, + {"unknown partID unchanged", "Coś innego (X 1)", "", "en", "Coś innego (X 1)"}, + {"already-English heading unchanged (traditional lectionary, no pl prefix to match)", "Gospel (Luke 7:36-50)", "ewangelia", "en", "Gospel (Luke 7:36-50)"}, + {"prefix mismatch unchanged", "Nieoczekiwany tytuł (J 1)", "ewangelia", "en", "Nieoczekiwany tytuł (J 1)"}, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got := LocalizeHeading(c.heading, c.partID, c.lang) + if got != c.want { + t.Errorf("LocalizeHeading(%q, %q, %q) = %q, want %q", c.heading, c.partID, c.lang, got, c.want) + } + }) + } +} -- cgit v1.3