src/content/translations/en.json is a reviewable hu -> en memory built from the live staging content (179 texts). Tests guard every entry: placeholders, HTML, legal markup and e-mail/URL literals must survive. fillEnglishDraft() fills only empty English values whose Hungarian text exactly matches a memory key (lists all-or-nothing) and moves the page status none -> ai-draft; it never sets "approved" or overwrites English. The 20260929_en_ai_draft migration applies it to every global and legal page (published doc + latest version), reports untranslated texts, and wraps legacy values first so it does not depend on migration order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.2 KiB
TypeScript
77 lines
3.2 KiB
TypeScript
/**
|
|
* MITHOME-113: AI-draft angol tartalom importja a fordítási memóriából
|
|
* (src/content/translations/en.json) minden Globalra és jogi oldalra.
|
|
*
|
|
* Csak üres angol értéket tölt ki, pontos magyar egyezés esetén (lásd
|
|
* src/lib/english-draft.ts); a kitöltött oldalak állapota `ai-draft` lesz,
|
|
* így a publikus /en oldal jóváhagyásig továbbra is magyar (readGated).
|
|
*
|
|
* WHY csak a legutóbbi verzió (+ a publikált dokumentum): az admin a
|
|
* legutóbbi verziót tölti be szerkesztéskor; a régebbi verziók történeti
|
|
* rekordok, azokat egy tartalmi import nem írja át.
|
|
*
|
|
* WHY előbb wrapLocalized: így független a lokalizációs migrációk
|
|
* sorrendjétől — a prodMigrations utánuk futtatja, a Payload CLI viszont
|
|
* fájlnév szerint (ábécé) rendez, és ott ez futna elsőként.
|
|
*/
|
|
import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-mongodb'
|
|
import { randomBytes } from 'crypto'
|
|
|
|
import { Home } from '../globals/Home'
|
|
import { About } from '../globals/About'
|
|
import { Services } from '../globals/Services'
|
|
import { Contact } from '../globals/Contact'
|
|
import { Common } from '../globals/Common'
|
|
import { LegalPages } from '../collections/LegalPages'
|
|
import translations from '../content/translations/en.json'
|
|
import { fillEnglishDraft } from '../lib/english-draft'
|
|
import { collectLocalizedPaths, topLevelKeys, wrapLocalized } from '../lib/localize-paths'
|
|
import { rewriteDocs, type DocTarget } from '../lib/migrate-global-docs'
|
|
|
|
const MEMORY: Record<string, string> = translations
|
|
const TARGETS: readonly { target: DocTarget; fields: unknown[] }[] = [
|
|
...[Home, About, Services, Contact, Common].map((g) => ({
|
|
target: { kind: 'global', slug: g.slug } as const,
|
|
fields: g.fields,
|
|
})),
|
|
{ target: { kind: 'collection', slug: LegalPages.slug }, fields: LegalPages.fields },
|
|
]
|
|
|
|
// Array row ids are stored as 24-hex strings (ObjectId-shaped), like Payload's own.
|
|
const newId = () => randomBytes(12).toString('hex')
|
|
|
|
export async function up(args: MigrateUpArgs): Promise<void> {
|
|
for (const { target, fields } of TARGETS) {
|
|
const paths = collectLocalizedPaths(fields as never)
|
|
const unmatched = new Set<string>()
|
|
let filled = 0
|
|
await rewriteDocs(
|
|
args,
|
|
target,
|
|
[...topLevelKeys(paths), 'enTranslationStatus'],
|
|
(data) => {
|
|
const wrapped = wrapLocalized(data, paths)
|
|
const report = fillEnglishDraft(data, paths, MEMORY, newId)
|
|
report.unmatched.forEach((text) => unmatched.add(text))
|
|
filled += report.filled
|
|
return wrapped + report.filled
|
|
},
|
|
{ versions: 'latest' },
|
|
)
|
|
args.payload.logger.info(
|
|
`MITHOME-113 English AI draft: ${target.slug} — ${filled} value(s) filled, ${unmatched.size} Hungarian text(s) without translation`,
|
|
)
|
|
for (const text of unmatched) {
|
|
args.payload.logger.warn(`MITHOME-113 no translation (${target.slug}): ${text.slice(0, 120)}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* DECISION: no automatic down — English values cannot be told apart from
|
|
* later human edits. Roll back by restoring the pre-deploy DB dump.
|
|
*/
|
|
export async function down(args: MigrateDownArgs): Promise<void> {
|
|
args.payload.logger.warn('MITHOME-113 English AI draft: down is a no-op — restore the pre-deploy dump instead')
|
|
}
|