Files
tajniak81andClaude Opus 5.5 c98b127f1e
CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
Add columns, suggesting mode, verified pages, scanned PDF search and server translations
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged
  between them; they stack on phones. HTML export and import keep them
  (also Notion column lists and Confluence page layouts).
- Suggesting mode: edits become suggested insertions and deletions that
  editors accept or reject one by one or all at once. Text only.
- Verified pages: editors verify a page for a while or without end; the
  verifier is notified when it runs out (migration 1764700000).
- Scanned PDFs attached to pages are read by AI for search where a
  workspace turns it on.
- The server writes error messages, emails, digests and phone
  notifications in English, Polish, German, French and Spanish; the apps
  send their language with each request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:38:08 +01:00

57 lines
1.8 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package httpapi
import (
"context"
"net/http"
"time"
"docwell/server/internal/auth"
"docwell/server/internal/i18n"
)
// Languages: the apps send the language they show in Accept-Language. Each
// response says its language in Content-Language, error messages are
// translated into it (writeError), and the request's context carries it for
// text written while handling it (invite emails). A signed-in person's last
// language is stored for the emails and notifications they get later.
// withLang sets a request's language on its context and response.
func withLang(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
lang := i18n.Match(r.Header.Get("Accept-Language"))
w.Header().Set("Content-Language", lang)
next.ServeHTTP(w, r.WithContext(i18n.WithLang(r.Context(), lang)))
})
}
// responseLang is the language withLang chose for a response.
func responseLang(w http.ResponseWriter) string {
if l := w.Header().Get("Content-Language"); i18n.IsSupported(l) {
return l
}
return i18n.Default
}
// rememberLocale stores the language a signed-in person uses when it
// changed (in the background; once per user and language per process).
func (a *api) rememberLocale(r *http.Request, u auth.User) {
lang, ok := i18n.MatchOK(r.Header.Get("Accept-Language"))
if !ok || u.ID == "" || lang == u.Locale {
return
}
if prev, seen := a.locales.Load(u.ID); seen && prev == lang {
return
}
a.locales.Store(u.ID, lang)
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := a.auth.SetLocale(ctx, u.ID, lang); err != nil {
a.locales.Delete(u.ID)
a.log.Warn("remember locale", "user", u.ID, "err", err)
}
}()
}