From 539a7c71b60115144959f712ef5966f48c63f9f0 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 28 Jul 2026 18:15:29 +0200 Subject: naming: localise liturgical day names in any language MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add internal/naming, which renders temporal day names and celebration display names from the calendar engine's slugs in any language. English is the built-in baseline; a language is data -- an embedded lang/.ini (pl shipped) and/or a user file at /names/.ini that overrides it key by key. Names compose from a small vocabulary plus per-language format templates, so word order and grammatical case can differ (e.g. Polish genitive "3. Niedziela Okresu Zwykłego"); any string a language omits falls back to English. - Move day-name generation out of calendar (calendar.HumanizeSlug removed, calendar stays a pure engine) into naming.DayName; the English golden cases carry over verbatim. - naming.CelebrationName unifies the three duplicated resolvers (cli/readings/calfeed): name. -> English -> Latin -> humanized slug. Saint names stay in the calendar data (name.), overridable via calendar layers. - config: ui_language now accepts any code (lower-cased, not clamped to en/pl) so names/.ini applies; UI chrome still resolves en/pl and falls back to English. Add NamesDir(); wire naming.SetUserDir (and the previously unwired bible.SetUserCorporaDir) in the TUI and web mains too, so external corpora and name files work across all three binaries. --- internal/naming/naming_test.go | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 internal/naming/naming_test.go (limited to 'internal/naming/naming_test.go') diff --git a/internal/naming/naming_test.go b/internal/naming/naming_test.go new file mode 100644 index 0000000..a3bc49f --- /dev/null +++ b/internal/naming/naming_test.go @@ -0,0 +1,55 @@ +package naming + +import "testing" + +// English must reproduce exactly what calendar.HumanizeSlug produced before the +// name generation moved here (the golden cases carried over verbatim). +func TestDayNameEnglish(t *testing.T) { + cases := map[string]string{ + "ordinary-sunday-11": "11th Sunday in Ordinary Time", + "ordinary-11-tue": "Tuesday of the 11th Week in Ordinary Time", + "advent-2-mon": "Monday of the 2nd Week of Advent", + "advent-dec-17": "December 17", + "lent-after-ashes-wed": "Ash Wednesday", + "lent-after-ashes-thu": "Thursday after Ash Wednesday", + "triduum-fri": "Good Friday", + "easter-octave-mon": "Monday in the Octave of Easter", + "christmas-jan-2": "January 2", + "christmas-after-epiphany-mon": "Monday after the Epiphany", + "trinity-sunday": "The Most Holy Trinity", + "ef-time-after-pentecost-4-tue": "Tuesday of the 4th Week after Pentecost", + "ef-passiontide-0-thursday": "Thursday of Passion Week", + "ef-september-ember-wed": "Ember Wednesday of September", + } + for slug, want := range cases { + if got := DayName(slug, "en"); got != want { + t.Errorf("DayName(%q, en) = %q, want %q", slug, got, want) + } + } +} + +// Polish must localise both named days and composed names, using its own word +// order and genitive-case season names. +func TestDayNamePolish(t *testing.T) { + cases := map[string]string{ + "ordinary-sunday-11": "11. Niedziela Okresu Zwykłego", + "ordinary-11-tue": "Wtorek 11. tygodnia Okresu Zwykłego", + "advent-2-mon": "Poniedziałek 2. tygodnia Adwentu", + "advent-dec-17": "17 grudnia", + "triduum-fri": "Wielki Piątek", + "lent-after-ashes-wed": "Środa Popielcowa", + "ef-time-after-pentecost-4-tue": "Wtorek 4. tygodnia po Zesłaniu Ducha Świętego", + } + for slug, want := range cases { + if got := DayName(slug, "pl"); got != want { + t.Errorf("DayName(%q, pl) = %q, want %q", slug, got, want) + } + } +} + +// An unknown language falls back entirely to English. +func TestDayNameUnknownLangFallsBackToEnglish(t *testing.T) { + if got := DayName("ordinary-sunday-3", "xx"); got != "3rd Sunday in Ordinary Time" { + t.Errorf("unknown lang = %q", got) + } +} -- cgit v1.3