feat(cms): localize translatable Globals fields with lossless migration (MITHOME-111)

Mark every translatable text/textarea field of the Home, About, Services,
Contact and Common globals as localized. Icons, row ids, the external
flag and the postal address stay shared; CTA hrefs are localized because
internal routes differ per locale. String lists (paragraphs, bullets,
features, spec items) are localized at array level so locales can have
different item counts; structured rows share order/icons and localize
only their inner text.

Existing data is not re-seeded (that would overwrite admin edits): a
Payload migration wraps legacy values into { hu: value } on the published
global and every draft/version record, idempotently, and runs on
production startup via prodMigrations. Paths are derived from the Global
configs themselves so the migration cannot drift from the schema.

OpenSpec change: openspec/changes/localize-globals-mithome-111

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 00:52:26 +02:00
co-authored by Claude Opus 5.5
parent 9b5ca94030
commit 829f543962
21 changed files with 839 additions and 111 deletions
@@ -0,0 +1,20 @@
import { stringArrayField } from './stringArray'
describe('stringArrayField', () => {
it('should build an optional, non-localized array of { value } rows by default', () => {
const field = stringArrayField('paragraphs', 'Paragraphs')
expect(field).toMatchObject({ name: 'paragraphs', type: 'array', label: 'Paragraphs', required: false })
expect(field).not.toHaveProperty('localized')
expect(field.fields).toEqual([{ name: 'value', type: 'text', required: true }])
})
it('should localize the array itself, not the inner value, when localized is set', () => {
const field = stringArrayField('paragraphs', 'Paragraphs', { localized: true })
expect(field.localized).toBe(true)
expect(field.fields[0]).not.toHaveProperty('localized')
})
it('should pass the required flag through', () => {
expect(stringArrayField('items', undefined, { required: true }).required).toBe(true)
})
})
+15 -1
View File
@@ -1,5 +1,14 @@
import type { ArrayField } from 'payload'
type StringArrayOptions = {
required?: boolean
/**
* MITHOME-111: localizes the whole array (not the inner `value`), so each
* locale can have its own number of items (e.g. 3 hu paragraphs, 2 en).
*/
localized?: boolean
}
/**
* Payload has no native "array of plain strings" field — the closest
* built-in shape is an array of one-field objects. Used for every
@@ -7,11 +16,16 @@ import type { ArrayField } from 'payload'
* features, spec items, …) so the JSON -> Payload migration script has a
* single, consistent shape to transform into.
*/
export function stringArrayField(name: string, label?: string, required = false): ArrayField {
export function stringArrayField(
name: string,
label?: string,
{ required = false, localized = false }: StringArrayOptions = {},
): ArrayField {
return {
name,
type: 'array',
label,
...(localized ? { localized: true } : {}),
fields: [
{
name: 'value',