From 65892898780d7598229767638d6912a3c03c703b Mon Sep 17 00:00:00 2001 From: Do Siki Date: Thu, 10 Sep 2026 13:07:36 +0200 Subject: [PATCH] =?UTF-8?q?feat(cms):=20enable=20Payload=20localization=20?= =?UTF-8?q?=E2=80=94=20hu=20default=20+=20en=20(MITHOME-110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit payload.config.ts: localization: { locales: ['hu','en'], defaultLocale: 'hu', fallback: true }. URL/routing side is separate (MITHOME-114). Proved the mechanism on a real field rather than a throwaway one: Common.buttons.* (contact/learnMore/webmail/sendMessage) marked localized: true — these are genuinely translatable UI labels, so this doubles as a first, correct slice of the full MITHOME-111 retrofit instead of being disposable test scaffolding. Gotcha discovered and documented in the migration script: marking an existing field `localized: true` after data was already written non- localized makes that value unreadable via `locale: defaultLocale` (the storage shape changed) — the migration script must be re-run so it gets rewritten under the localized shape. This will matter again for the full MITHOME-111/112 retrofit. Verified: Local API round-trip (set en, defaultLocale/hu re-seeded via re-running the migration script) — hu reads "Kapcsolatfelvétel", en reads "Contact". Real browser: admin UI locale switcher (hu/en) in the top bar, fields show "— hu"/"— en" per-locale labels, switching locale swaps the visible value correctly on the Common global editor. build/lint/tsc/test (58 passed) all clean. Co-Authored-By: Claude Sonnet 5 --- proto/scripts/migrate-content-to-payload.ts | 8 ++++++++ proto/src/globals/Common.ts | 18 +++++++++++++----- proto/src/payload.config.ts | 12 ++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/proto/scripts/migrate-content-to-payload.ts b/proto/scripts/migrate-content-to-payload.ts index 384c755..5bb54f4 100644 --- a/proto/scripts/migrate-content-to-payload.ts +++ b/proto/scripts/migrate-content-to-payload.ts @@ -11,6 +11,14 @@ * többször futtatható — mindig a JSON az aktuális "forrás igazság", felül- * írja a Payload-ban lévő korábbi állapotot. NEM törli/nem érinti a JSON * fájlokat. + * + * MITHOME-110 tapasztalat: ha egy mezőt utólag `localized: true`-ra + * állítasz (MITHOME-111/112 retrofit), a korábban beírt érték a régi, + * nem-lokalizált tárolási alakban marad, és `locale: defaultLocale`-lal + * nem olvasható vissza (üresnek látszik) — ilyenkor ezt a scriptet újra + * kell futtatni, hogy a defaultLocale (hu) alá újra beírja az értéket a + * lokalizált alakban. Explicit `locale` paramétert egyik updateGlobal/ + * update hívás sem ad meg itt, ezért mindig a `defaultLocale` (hu) alá ír. */ import path from 'path' import { fileURLToPath } from 'url' diff --git a/proto/src/globals/Common.ts b/proto/src/globals/Common.ts index 93b0674..2258482 100644 --- a/proto/src/globals/Common.ts +++ b/proto/src/globals/Common.ts @@ -1,6 +1,14 @@ import type { GlobalConfig } from 'payload' -/** Mirrors CommonContent (proto/src/content/types.ts) — MITHOME-87. */ +/** + * Mirrors CommonContent (proto/src/content/types.ts) — MITHOME-87. + * + * `buttons.*` localized: true (MITHOME-110) — ez a lokalizáció-mechanizmus + * bizonyítéka (admin nyelvváltó + Local/REST API locale param), és egyben + * előremutató, helyes darabja a MITHOME-111 teljes retrofitnak: ezek + * ténylegesen fordítandó UI-feliratok. A többi mező itt még nem lokalizált, + * azt a MITHOME-111 teljes körűen elvégzi. + */ export const Common: GlobalConfig = { slug: 'common', admin: { @@ -11,10 +19,10 @@ export const Common: GlobalConfig = { name: 'buttons', type: 'group', fields: [ - { name: 'contact', type: 'text', required: true }, - { name: 'learnMore', type: 'text', required: true }, - { name: 'webmail', type: 'text', required: true }, - { name: 'sendMessage', type: 'text', required: true }, + { name: 'contact', type: 'text', required: true, localized: true }, + { name: 'learnMore', type: 'text', required: true, localized: true }, + { name: 'webmail', type: 'text', required: true, localized: true }, + { name: 'sendMessage', type: 'text', required: true, localized: true }, ], }, { diff --git a/proto/src/payload.config.ts b/proto/src/payload.config.ts index 628abcc..7759263 100644 --- a/proto/src/payload.config.ts +++ b/proto/src/payload.config.ts @@ -11,6 +11,9 @@ * feltetelek). * MITHOME-89: Partners + Media collection (MVP — feltöltés, a vágás/ * áttetszővé tétel szerkesztő külön, MITHOME-118). + * MITHOME-110: lokalizáció bekapcsolva (hu alapértelmezett, en). A mezőnkénti + * `localized: true` retrofit a Globals/LegalPages configokon külön ticket + * (MITHOME-111/112) — ez a ticket csak magát a mechanizmust kapcsolja be. */ import path from 'path' import { fileURLToPath } from 'url' @@ -45,6 +48,15 @@ export default buildConfig({ globals: [Home, About, Services, Contact, Common], + // MITHOME-109/110: hu alapértelmezett (URL-prefix nélkül), en /en/ alatt + // (Next.js routing oldala: MITHOME-114). fallback:true -> amíg egy mezőnek + // nincs angol fordítása, a magyar érték jelenik meg — nem üres oldal. + localization: { + locales: ['hu', 'en'], + defaultLocale: 'hu', + fallback: true, + }, + secret: process.env.PAYLOAD_SECRET || '', typescript: {