mirror of
https://github.com/bitbaum/evig.git
synced 2026-12-04 15:17:59 +01:00
Until now, the /workshops list and the "what we need" cards on
/projects/upcycling showed German DB content (workshop titles, durations,
levels, categories, need titles + descriptions) regardless of locale —
because those fields were single TEXT columns with one German value.
Migration 088 adds sibling JSONB columns `<field>_i18n` of shape
{ en, fr, es, it, ja, ko, ru → translated string } on:
- workshops: title, description, short_description, duration, level, category
- project_needs: title, description, target_unit
Each column nullable, no default — empty = the helper falls back to the
canonical DE column. Idempotent (ADD COLUMN IF NOT EXISTS), already
applied to Neon production.
New helper src/lib/i18n/db-content.ts → `pickI18n(canonical, jsonb, locale)`
encapsulates the picking strategy in ONE place (SSOT). `de` → canonical.
Other locales → JSONB[locale] if present, else canonical. NULL safety
built in so callers pass raw rows.
Two consumers updated at the data boundary so the client never touches
JSONB:
- src/app/[locale]/workshops/page.tsx — accepts params.locale, selects
all the *_i18n columns, runs each row through pickI18n before passing
to WorkshopBrowseClient
- src/app/api/projects/[slug]/needs/route.ts — resolves visitor locale
from URL prefix or NEXT_LOCALE cookie, applies pickI18n on the way
out, same shape as before
Seed data:
- scripts/db/seeds/001_workshops_and_needs_i18n.sql — hand-translates
all 6 active workshops (Linux/Open-Source/Computerreparatur/
Bitcoin/AI/Kreatives Programmieren) and all 7 open project_needs
(CE engineer, electronics, sheltered workshop, facility mgmt, 24"+
monitors, LCA funding, per-model docs) into 7 locales. Applied
to production immediately.
Result: /ru/workshops now reads "Семинар по Linux · 2 дня · От начинающего
до продвинутого", /fr/workshops reads "Atelier Linux · 2 jours · Débutant
à avancé", etc. /ru/projects/upcycling needs cards read in Russian.
CI gate: any future locale missing here means the visitor sees DE — not
a leak (the schema permits it intentionally as a fallback). New rows
inserted via admin UI need translations entered alongside; future admin-
UI work can surface the seven locale fields per text column. Out of scope.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
63 lines
3.2 KiB
SQL
63 lines
3.2 KiB
SQL
-- Migration 088: Add i18n JSONB columns to workshops + project_needs
|
||
--
|
||
-- Problem: workshop.title / workshop.description / project_needs.title /
|
||
-- project_needs.description are TEXT columns holding GERMAN-ONLY content.
|
||
-- Non-DE visitors see German prose mixed with the otherwise-translated
|
||
-- site chrome — credibility-damaging for a multilingual product.
|
||
--
|
||
-- Solution (chosen for KISS + zero-rewrite of existing reads):
|
||
-- - Keep the canonical TEXT column as the DE source.
|
||
-- - Add a sibling JSONB column `<field>_i18n` of shape
|
||
-- { "en": "…", "fr": "…", "es": "…", "it": "…", "ja": "…", "ko": "…", "ru": "…" }
|
||
-- - A frontend helper `pickI18n(canonical, jsonb, locale)` returns the
|
||
-- localised string (or falls back to canonical when key is missing).
|
||
--
|
||
-- Why JSONB and not a translations table?
|
||
-- 1. Small number of rows × small number of locales → no scale issue.
|
||
-- 2. Single SELECT keeps fetch helpers simple — no JOINs in workshop list,
|
||
-- no N+1 in project_needs.
|
||
-- 3. Drizzle has first-class JSONB support; admin UI work is trivial.
|
||
-- 4. If we ever grow to many entities + many languages, splitting to a
|
||
-- <table>_translations side table is a mechanical refactor.
|
||
--
|
||
-- Backfill: leaving the JSONB columns NULL post-migration is fine — the
|
||
-- helper falls back to the canonical TEXT column (DE) until translations
|
||
-- arrive. Translations land via a separate seed commit per entity.
|
||
--
|
||
-- Idempotent: ADD COLUMN IF NOT EXISTS. Safe to re-run.
|
||
|
||
-- ----------------------------------------------------------------------
|
||
-- workshops
|
||
-- ----------------------------------------------------------------------
|
||
|
||
ALTER TABLE workshops
|
||
ADD COLUMN IF NOT EXISTS title_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS description_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS short_description_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS duration_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS level_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS category_i18n JSONB;
|
||
|
||
COMMENT ON COLUMN workshops.title_i18n IS
|
||
'Locale → translated string (e.g. {"en":"Linux Workshop","fr":"Atelier Linux"}). Falls back to title (DE) if locale absent.';
|
||
COMMENT ON COLUMN workshops.description_i18n IS
|
||
'Locale → translated description. Falls back to description (DE) if locale absent.';
|
||
COMMENT ON COLUMN workshops.duration_i18n IS
|
||
'Locale → translated free-form duration ("2 Tage" → "2 days"). Falls back to duration column.';
|
||
|
||
-- ----------------------------------------------------------------------
|
||
-- project_needs
|
||
-- ----------------------------------------------------------------------
|
||
|
||
ALTER TABLE project_needs
|
||
ADD COLUMN IF NOT EXISTS title_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS description_i18n JSONB,
|
||
ADD COLUMN IF NOT EXISTS target_unit_i18n JSONB;
|
||
|
||
COMMENT ON COLUMN project_needs.title_i18n IS
|
||
'Locale → translated title (e.g. {"en":"CE conformity engineer","fr":"Ingénieur·e conformité CE"}). Fallback to title (DE).';
|
||
COMMENT ON COLUMN project_needs.description_i18n IS
|
||
'Locale → translated description. Fallback to description (DE).';
|
||
COMMENT ON COLUMN project_needs.target_unit_i18n IS
|
||
'Locale → translated unit suffix ("70 Monitor" → "70 monitors"). Fallback to target_unit.';
|