5 KiB
server_debteliminator.md — addendum §0f (paste after §0e)
0f. Legal documents in multiple languages (built 2026-10-20/21, package legal-translations-v2.1.27.tar.gz, built against the v2.1.26 QA backup)
What it does
- Terms of Use, Privacy Statement and Affiliate Disclosure can each be written in every language the Blog supports (admin picks the language, then edits/publishes, like the Blog editor).
- Every language is its own document with its own version counter. English stays in
legal_documents(untouched); other languages are in new tablelegal_document_translations(doc_type, lang, version, content_html, based_on_en_version, requires_acceptance, published_at, published_by_user_id). - Who is asked to accept what (
legal_i18n.py): a user is shown the document in their saved locale's language (users.locale), or English when that language has no translation yet. They must accept when (a) they have never accepted that document in any language, or (b) their accepted version in the language they are shown is below the newest version in that language that requires acceptance.- Publish English v5 → only readers of English, and of languages with no translation, are asked.
- Publish Spanish v3 → only Spanish readers are asked (in Spanish).
- A language that gets its first translation later: readers are asked once in their language unless the publisher unticks "re-accept".
- "Ask everyone to re-accept" checkbox (default ticked = the old behaviour): untick for typos/formatting; the text changes immediately, nobody is prompted. New column
legal_documents.requires_acceptance(default TRUE, added byALTER … IF NOT EXISTSinmain.py; existing rows = TRUE). - Acceptance record: new table
legal_acceptances(user_id, doc_type, lang, version, accepted_at, unique per user/doc/lang). English is still also written tousers.accepted_terms_version/accepted_privacy_version. The Accept button posts thelang+versionthe screen showed, so an admin publishing mid-read cannot change what was agreed to. - Admin → User Accounts → Legal Documents: document picker; status-by-language table (published version, "based on English vN", Current / English is newer — review / Not translated, users waiting to accept); language buttons; English text shown read-only beside the translation; "Start from the English text"; earlier-version loader; confirmation text says exactly who will be prompted. Languages not yet launched can be drafted.
- Reader side: gate overlays and the footer viewer fetch
/legal/{doc}?lang=xx. Notes above the text: translation shown → "This is a translation… the English version controls"; fallback → existing "shown in English" note (now only when the visitor's language ≠ English); English reader → no note. The text container getslang= the language of the text (WCAG 3.1.2). - Force-reset (Re-Accept Terms / Privacy) now clears the user's acceptances in every language. Deleting a user removes their
legal_acceptancesrows and nullspublished_by_user_idon translations.
Endpoints — public: GET /legal/{doc_type}?lang= (adds lang, requested_lang, is_fallback), POST /legal/{doc_type}/accept (optional body {lang, version}), /auth/accept-terms and /auth/accept-privacy (same optional body). Admin (legal.manage): GET /admin/legal-documents/languages, …/{doc}/overview, …/{doc}/history?lang=, GET …/{doc}?lang=&version=, POST /admin/legal-documents (body adds lang, requires_acceptance; a translation requires an English version to exist first).
Files: new legal_i18n.py; changed models.py, schemas.py, security.py, main.py, routers/legal.py, routers/admin.py, routers/auth.py, static/shared.js, static/admin/accounts.html, static/i18n/{es,fr}/common.json + manifest.json (rev refreshed; one new string). Cache marker ?v=1.9.15 on every page that loads shared.css/js (this also unifies blog.py, which was on 1.9.10). No new dependencies, no compose changes → restart-only.
Verified (real app, fresh Postgres 16, headless Chromium): English+Spanish publish through the admin screen; Spanish user not prompted by an English update, prompted by a Spanish update; French user (no translation) sees English with the note in French; signed-out footer viewer in Spanish; stale warning; history. Logic + API tests are in tools/legal_i18n_tests/. Not run: a11y_audit.py and the manual keyboard/screen-reader pass on the new Legal Documents panel and the changed overlays (required before Deploy to Prod — accessibility_standards.md §3).
Open / decisions
- Have translations of legal text reviewed (counsel / native speaker) before turning them on for real users.
- The "English version controls" sentence now also appears above translations (same wording the site already used for the English fallback). Remove it if counsel prefers.
- Reminder still open:
APP_SECRET_KEYunset (also absent from QA compose); Privacy Statement analytics disclosure.