Lift locale maps before ProjectWritableFields so a Journal-shaped save can persist the default host scalar and non-default locales through TranslationWriter without dropping nested JSON. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
853 B
TypeScript
25 lines
853 B
TypeScript
/** Window event that keeps every ML control on one active locale. */
|
|
export const ML_LOCALE_CHANGE = 'summer:ml-locale'
|
|
|
|
/** Broadcast the locale the administrator selected on any ML control. */
|
|
export function broadcastMLLocale(locale: string): void {
|
|
if (typeof window === 'undefined' || locale === '') {
|
|
return
|
|
}
|
|
window.dispatchEvent(new CustomEvent(ML_LOCALE_CHANGE, { detail: locale }))
|
|
}
|
|
|
|
/** Locale → text map as it is sent on save: only string values. */
|
|
export function localeRecord(value: unknown): Record<string, string> {
|
|
const out: Record<string, string> = {}
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
return out
|
|
}
|
|
for (const [locale, text] of Object.entries(value as Record<string, unknown>)) {
|
|
if (typeof text === 'string') {
|
|
out[locale] = text
|
|
}
|
|
}
|
|
return out
|
|
}
|