import { DEFAULT_MESSAGES } from "@/app/lib/i18n/defaultMessages"; import { resolveMessage, type MessageParams } from "@/app/lib/i18n/t"; const placeholders = (code: string) => [...DEFAULT_MESSAGES[code].matchAll(/\{(\w+)\}/g)].map((m) => m[1]); /** Every code renders as «Code», plus ":{param}" per placeholder in its English default, so a test can * see both that the code was used and which values were passed: «ProductCountOther:3». */ export const CATALOG: Record = Object.fromEntries( Object.keys(DEFAULT_MESSAGES).map((code) => [code, `«${code}${placeholders(code).map((p) => `:{${p}}`).join("")}»`]), ); /** The expected rendering of a code, values in the order the placeholders appear in the English default. */ export const m = (code: string, ...values: Array) => `«${[code, ...values].join(":")}»`; /** getServerT's replacement for vi.mock("@/app/lib/server/i18n"). */ export const serverT = async () => (code: string, params?: MessageParams) => resolveMessage(CATALOG, code, params); /** A helper's `t` that renders the English defaults, for tests that assert the English text. */ export const tEn = (code: string, params?: MessageParams) => resolveMessage({}, code, params); /** A helper's `t` that renders «Code» like CATALOG, for tests that assert which code was used. */ export const tCode = (code: string, params?: MessageParams) => resolveMessage(CATALOG, code, params);