From e14a4250efb828262347f5a4bbc4067cd71d885f Mon Sep 17 00:00:00 2001 From: grm Date: Mon, 14 Sep 2026 01:32:25 +0300 Subject: Add languages: English and Greek, chosen per blog on the Settings tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every blog and its dashboard were hard-wired to English. A blogger can now pick the language of their blog; it switches the whole dashboard and the blog's fixed text — post dates, archive months, the RSS link, the pager, the 404 page — while what the blogger wrote is left alone. The new internal/i18n package keys translations by the English string, so an untranslated key renders as English rather than blank, and TestGreekCatalogComplete scans the templates and handlers to fail when the Greek catalog misses a key or keeps a stale one. Templates are compiled once per language with t/tf/date/postdate/month closed over the language, so they need no data plumbing. The language lives in settings.language (blog migration 00002), not in the theme, so "Reset design" does not touch it. Public pages use the blog's language; management pages use the logged-in user's own blog's, so a superadmin editing someone else's blog keeps theirs; the login page follows Accept-Language. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/web/layout.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'internal/web/layout.go') diff --git a/internal/web/layout.go b/internal/web/layout.go index 521cb63..ad55e82 100644 --- a/internal/web/layout.go +++ b/internal/web/layout.go @@ -2,10 +2,10 @@ package web import ( "net/url" - "strconv" "strings" "time" + "github.com/gramanas/blogspace/internal/i18n" "github.com/gramanas/blogspace/internal/store" ) @@ -20,7 +20,7 @@ var moduleKinds = map[string][]string{ "footer": {"text", "rss", "sitemap", "html"}, } -// Friendly names for the dashboard. +// Friendly names for the dashboard (English; translate with t / s.tr at the point of use). var moduleNames = map[string]string{ "title": "Blog title & tagline", "logo": "Logo", @@ -60,28 +60,28 @@ func moduleHasSettings(kind string) bool { } // moduleSummary is the one-liner the Layout page shows next to a module's name. -func moduleSummary(m store.Module) string { +func moduleSummary(lang string, m store.Module) string { switch m.Kind { case "recent": - return strconv.Itoa(m.Count) + " posts" + headingNote(m) + return i18n.Tf(lang, "%d posts", m.Count) + headingNote(lang, m) case "html", "text": body := strings.Join(strings.Fields(m.Body), " ") if body == "" { - return "empty" + return i18n.T(lang, "empty") } if len(body) > 60 { body = body[:57] + "…" } return body } - return strings.TrimPrefix(headingNote(m), ", ") + return strings.TrimPrefix(headingNote(lang, m), ", ") } -func headingNote(m store.Module) string { +func headingNote(lang string, m store.Module) string { if m.Title == "" { return "" } - return ", heading “" + m.Title + "”" + return ", " + i18n.Tf(lang, "heading “%s”", m.Title) } // validLinkURL accepts what a menu link may point to: a web address, a mail @@ -174,7 +174,7 @@ func (l Layout) MaxRecent() int { // ---- archive --------------------------------------------------------------- type ArchiveMonth struct { - Name string // "September" + Month time.Month // named by the template in the blog's language Posts []store.PostRef } @@ -196,7 +196,7 @@ func groupArchive(posts []store.PostRef) []ArchiveYear { } yr := &years[len(years)-1] if len(yr.Months) == 0 || m != lastM { - yr.Months = append(yr.Months, ArchiveMonth{Name: time.Month(m).String()}) + yr.Months = append(yr.Months, ArchiveMonth{Month: time.Month(m)}) } mo := &yr.Months[len(yr.Months)-1] mo.Posts = append(mo.Posts, p) -- cgit v1.2.3