feat(cms): English translation status with a public gate (MITHOME-113)

Every page global and legal page gets a shared "English translation
status" sidebar field (none / AI draft awaiting review / approved).
The content adapter reads through readGated(): an English page renders
English text only when its translation is approved, otherwise the
Hungarian text of the same page, while links keep resolving to /en/...

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 10:58:07 +02:00
co-authored by Claude Opus 5.5
parent 0eb6594acc
commit 32b6643fbc
12 changed files with 160 additions and 13 deletions
+18 -11
View File
@@ -7,11 +7,16 @@
* Ezek a getterek visszaadaptálják az eredeti alakra, hogy a page
* komponensek JSX-e (ami a régi content/types.ts formát várja) NE
* változzon — csak az adatforrás.
*
* MITHOME-113: minden olvasás a fordítási kapun megy át (readGated) — az
* angol oldal csak jóváhagyott angol fordítást mutat, különben a magyart.
* A `locale` paraméter a linkfeloldáshoz (CTA) változatlanul a kért nyelv.
*/
import { getPayload } from 'payload'
import config from '@payload-config'
import type { Locale } from './i18n'
import { resolveCtaHref, type CtaLink } from './cta-link'
import { readGated } from './translation-gate'
let cached: ReturnType<typeof getPayload> | undefined
@@ -31,12 +36,12 @@ function unwrap(items: readonly { value: string }[] | null | undefined): string[
export async function getCommonContent(locale: Locale) {
const payload = await payloadClient()
return payload.findGlobal({ slug: 'common', locale })
return readGated(locale, (l) => payload.findGlobal({ slug: 'common', locale: l }))
}
export async function getHomeContent(locale: Locale) {
const payload = await payloadClient()
const home = await payload.findGlobal({ slug: 'home', locale })
const home = await readGated(locale, (l) => payload.findGlobal({ slug: 'home', locale: l }))
return {
...home,
hero: {
@@ -59,7 +64,7 @@ export async function getHomeContent(locale: Locale) {
export async function getAboutContent(locale: Locale) {
const payload = await payloadClient()
const about = await payload.findGlobal({ slug: 'about', locale })
const about = await readGated(locale, (l) => payload.findGlobal({ slug: 'about', locale: l }))
return {
...about,
story: { ...about.story, paragraphs: unwrap(about.story?.paragraphs) },
@@ -69,7 +74,7 @@ export async function getAboutContent(locale: Locale) {
export async function getServicesContent(locale: Locale) {
const payload = await payloadClient()
const services = await payload.findGlobal({ slug: 'services', locale })
const services = await readGated(locale, (l) => payload.findGlobal({ slug: 'services', locale: l }))
return {
...services,
details: {
@@ -84,18 +89,20 @@ export async function getServicesContent(locale: Locale) {
export async function getContactContent(locale: Locale) {
const payload = await payloadClient()
return payload.findGlobal({ slug: 'contact', locale })
return readGated(locale, (l) => payload.findGlobal({ slug: 'contact', locale: l }))
}
export async function getLegalPage(slug: 'adatvedelem' | 'hasznalati-feltetelek', locale: Locale) {
const payload = await payloadClient()
const result = await payload.find({
collection: 'legal-pages',
where: { slug: { equals: slug } },
locale,
limit: 1,
return readGated(locale, async (l) => {
const result = await payload.find({
collection: 'legal-pages',
where: { slug: { equals: slug } },
locale: l,
limit: 1,
})
return result.docs[0]
})
return result.docs[0]
}
export type PartnerView = { name: string; url: string; logo: { url: string; alt: string } }
+42
View File
@@ -0,0 +1,42 @@
import { contentLocale, readGated } from './translation-gate'
describe('contentLocale (MITHOME-113)', () => {
it('should show English only when the translation is approved', () => {
expect(contentLocale('en', 'approved')).toBe('en')
})
it.each(['ai-draft', 'none', null, undefined])('should fall back to Hungarian for status %s', (status) => {
expect(contentLocale('en', status)).toBe('hu')
})
it('should never change a Hungarian request', () => {
expect(contentLocale('hu', 'ai-draft')).toBe('hu')
expect(contentLocale('hu', 'approved')).toBe('hu')
})
})
describe('readGated', () => {
const store = {
en: { title: 'Contact', enTranslationStatus: 'ai-draft' },
hu: { title: 'Kapcsolat', enTranslationStatus: 'ai-draft' },
}
it('should re-read in Hungarian when the English translation is not approved', async () => {
const read = jest.fn(async (locale: 'hu' | 'en') => store[locale])
await expect(readGated('en', read)).resolves.toEqual(store.hu)
expect(read.mock.calls.map(([l]) => l)).toEqual(['en', 'hu'])
})
it('should read once when approved or when Hungarian is requested', async () => {
const approved = { title: 'Contact', enTranslationStatus: 'approved' }
const read = jest.fn(async () => approved)
await expect(readGated('en', read)).resolves.toBe(approved)
await readGated('hu', read)
expect(read).toHaveBeenCalledTimes(2)
})
it('should pass a missing document through', async () => {
const read = jest.fn(async () => undefined)
await expect(readGated('en', read)).resolves.toBeUndefined()
})
})
+33
View File
@@ -0,0 +1,33 @@
/**
* MITHOME-113: public gate for English content.
*
* An English page renders English content only when its translation status
* is "approved"; otherwise it renders the Hungarian content of the same
* page. Only the text source changes — callers keep the requested locale
* for routing (CTA/nav links stay /en/...).
*/
import { DEFAULT_LOCALE, type Locale } from './i18n'
export const EN_TRANSLATION_STATUSES = ['none', 'ai-draft', 'approved'] as const
export type EnTranslationStatus = (typeof EN_TRANSLATION_STATUSES)[number]
type Gated = { enTranslationStatus?: string | null }
/** The locale whose stored text should be shown for `locale`. */
export function contentLocale(locale: Locale, status: string | null | undefined): Locale {
return locale === 'en' && status !== 'approved' ? DEFAULT_LOCALE : locale
}
/**
* Reads a document in `locale` and, if its English translation is not
* approved, reads it again in the default locale.
* TRADEOFF: a second in-process Local API read for unapproved English pages.
*/
export async function readGated<T extends Gated | undefined>(
locale: Locale,
read: (locale: Locale) => Promise<T>,
): Promise<T> {
const doc = await read(locale)
const source = contentLocale(locale, doc?.enTranslationStatus)
return source === locale ? doc : read(source)
}