The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
// Deep-merge helpers for catalogs. Same semantics as apps/shared/src/i18n.ts
// `mergeTranslations`, kept local because that module touches `document`
// (applyDocumentLocale) and the TUI compiles without the DOM lib.
export type TranslationOverride<T> = T extends (...args: never[]) => string
? T
: T extends readonly unknown[]
? T
: T extends string
? string
: T extends object
? { [K in keyof T]?: TranslationOverride<T[K]> }
: T
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}
/** Nested records recurse; strings, functions and arrays are replaced wholesale. */
export function mergeTranslations<T>(base: T, overrides: TranslationOverride<T> | undefined): T {
if (!isRecord(base) || !isRecord(overrides)) {
return (overrides ?? base) as T
}
const result: Record<string, unknown> = { ...base }
for (const [key, value] of Object.entries(overrides)) {
if (value === undefined) {
continue
}
const baseValue = result[key]
result[key] = isRecord(baseValue) && isRecord(value) ? mergeTranslations(baseValue, value) : value
}
return result as T
}