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/web/server.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'internal/web/server.go') diff --git a/internal/web/server.go b/internal/web/server.go index 10401ed..3b7102c 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -19,6 +19,7 @@ import ( "time" "github.com/lukaszkasprzak/lectio/internal/config" + "github.com/lukaszkasprzak/lectio/internal/i18n" "github.com/lukaszkasprzak/lectio/internal/liturgy" "github.com/lukaszkasprzak/lectio/internal/readings" "github.com/lukaszkasprzak/lectio/internal/render" @@ -183,6 +184,10 @@ type indexData struct { Display string Mono bool Reading template.HTML + // L holds the localised control labels (lectionary/layout/theme/...), + // set from i18n.Get(cfg.UILanguage) -- index.html references its + // fields (e.g. {{.L.Lectionary}}) instead of hardcoded Polish text. + L i18n.UI } type versionOpt struct { @@ -207,7 +212,7 @@ func indexHandler(cfg config.Config) http.HandlerFunc { } secs, loadVersions, err := loadSections(cfg, lectionary, date, all, versions) - reading := renderOrError(secs, loadVersions, lectionary, display, err) + reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, err) // Check the boxes for the versions actually rendered (loadVersions), // not the raw request: traditional/offline substitute pl->wuj, so the @@ -239,6 +244,7 @@ func indexHandler(cfg config.Config) http.HandlerFunc { Display: display, Mono: queryBool(r, "mono", cfg.WebMono), Reading: reading, + L: i18n.Get(cfg.UILanguage), } w.Header().Set("Content-Type", "text/html; charset=utf-8") @@ -255,7 +261,7 @@ func readingsHandler(cfg config.Config) http.HandlerFunc { date, lectionary, all, versions, display := resolveQuery(cfg, r) secs, loadVersions, err := loadSections(cfg, lectionary, date, all, versions) - reading := renderOrError(secs, loadVersions, lectionary, display, err) + reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, err) w.Header().Set("Content-Type", "text/html; charset=utf-8") io.WriteString(w, string(reading)) @@ -266,14 +272,14 @@ func readingsHandler(cfg config.Config) http.HandlerFunc { // error) a small escaped error paragraph -- readings.Load errors are // expected in normal operation (an unpublished date, no network while // online, ...) so the pane should show them, not 500. -func renderOrError(secs []liturgy.Section, versions []string, lectionary, display string, err error) template.HTML { +func renderOrError(secs []liturgy.Section, versions []string, lectionary, display, lang string, err error) template.HTML { if err != nil { return template.HTML(`

` + template.HTMLEscapeString(err.Error()) + `

`) } if len(secs) == 0 { return template.HTML(`

brak czytań na ten dzień

`) } - return RenderReadings(secs, versions, lectionary, display) + return RenderReadings(secs, versions, lectionary, display, lang) } // themeCSSHandler serves one theme's stylesheet: the requested name, or -- cgit v1.3