From 9100973576f87adcadaf6c8b331df7e729aeb117 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 28 Jul 2026 19:03:15 +0200 Subject: i18n: make all UI chrome user-translatable via ui/.ini The interface chrome (version labels, TUI keybar/messages, CLI banner words, web control labels, section-heading words) was English/Polish hardcoded in Go. It is now data: the English and Polish tables ship as embedded lang/en.ini and lang/pl.ini, and any language is user-overridable at /ui/.ini, resolved per key with an English fallback. With ui_language = plus a names/.ini, the WHOLE interface -- chrome, day names, saint names -- is translatable without a rebuild. - i18n.Get loads the embedded English baseline, overlays the embedded/user language file, caches per lang; field <-> INI-key mapping is by reflection (lang.go) so the tables and files stay in sync automatically. Edge-space values (e.g. "error: ") are double-quoted so the INI trim keeps them. The Go tables move to golden_test.go; TestGoldenMatchesEmbedded asserts the embedded files still parse back to them, and TestGenerateLangFiles regenerates them (LECTIO_GEN=1). - config.UIDir(); wire i18n.SetUserDir in the CLI, TUI and web entry points. - README/config: document ui/.ini alongside names/.ini. --- internal/i18n/override_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 internal/i18n/override_test.go (limited to 'internal/i18n/override_test.go') diff --git a/internal/i18n/override_test.go b/internal/i18n/override_test.go new file mode 100644 index 0000000..bac5e2c --- /dev/null +++ b/internal/i18n/override_test.go @@ -0,0 +1,28 @@ +package i18n + +import ( + "os" + "path/filepath" + "testing" +) + +func TestUserOverridePartialAndMap(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "fr.ini"), + []byte("banner_gospel = Évangile\nversion.vul = Vulgate (latin)\n"), 0o644) + SetUserDir(dir) + t.Cleanup(func() { SetUserDir("") }) + u := Get("fr") + if u.BannerGospel != "Évangile" { + t.Errorf("scalar override: BannerGospel = %q", u.BannerGospel) + } + if u.Version["vul"] != "Vulgate (latin)" { + t.Errorf("map override: version.vul = %q", u.Version["vul"]) + } + if u.Version["drb"] != "Douay-Rheims (English)" { + t.Errorf("map fallback: version.drb = %q (want English baseline)", u.Version["drb"]) + } + if u.BannerReadings != "Readings" { + t.Errorf("scalar fallback: BannerReadings = %q (want English)", u.BannerReadings) + } +} -- cgit v1.3