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/store/blogs.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'internal/store/blogs.go') diff --git a/internal/store/blogs.go b/internal/store/blogs.go index a2e88a8..3117154 100644 --- a/internal/store/blogs.go +++ b/internal/store/blogs.go @@ -22,6 +22,7 @@ type Blog struct { // from the blog database Title string Tagline string + Language string // i18n code, "en" by default ThemeJSON json.RawMessage UpdatedAt time.Time } @@ -38,7 +39,7 @@ func scanBlog(row interface{ Scan(...any) error }) (*Blog, error) { } func (bs *BlogStore) loadSettings(ctx context.Context, b *Blog) error { - err := bs.db.QueryRow(ctx, `SELECT title, tagline, theme, updated_at FROM settings`).Scan(&b.Title, &b.Tagline, &b.ThemeJSON, &b.UpdatedAt) + err := bs.db.QueryRow(ctx, `SELECT title, tagline, language, theme, updated_at FROM settings`).Scan(&b.Title, &b.Tagline, &b.Language, &b.ThemeJSON, &b.UpdatedAt) if errors.Is(err, pgx.ErrNoRows) { // registered, but the database is empty: not a 404 return fmt.Errorf("database %s of blog %q has no settings row (empty or wrong dump?)", b.DBName, b.Subdomain) } @@ -173,8 +174,8 @@ func (s *Store) DeleteBlog(ctx context.Context, b *Blog) error { return s.cluster.DropBlogDB(ctx, b.DBName) } -func (bs *BlogStore) UpdateSettings(ctx context.Context, title, tagline string) error { - _, err := bs.db.Exec(ctx, `UPDATE settings SET title=$1, tagline=$2, updated_at=now()`, title, tagline) +func (bs *BlogStore) UpdateSettings(ctx context.Context, title, tagline, language string) error { + _, err := bs.db.Exec(ctx, `UPDATE settings SET title=$1, tagline=$2, language=$3, updated_at=now()`, title, tagline, language) return err } -- cgit v1.2.3