// The labels each component takes, built from a message lookup. Every key this module's pages use is // named here or in pages.tsx, so `__tests__/i18n.test.ts` can run these builders against the // catalogues and fail on a key either language lacks. // // `t` takes a key relative to the module (`form.submit`); the page binds it to // `i18n.message("crm." + key)`. `refusals` is the kit's text for each business refusal in the reader's // language (`businessRefusalNotices`), which a form shows when the service refuses. import { CONTACT_KINDS, CONTACT_PURPOSES } from "../contract/constants.js" import type { ContactFormLabels } from "./contact-form.js" import type { ContactsLabels } from "./contacts.js" import type { PartyFormLabels } from "./party-form.js" import type { PartyListLabels } from "./party-list.js" export type Translate = (key: string, values?: Record) => string export type Refusals = Readonly> const ALL_KINDS = ["postal", "email", "phone", "web", "peppol_endpoint"] as const const purposeNames = (t: Translate) => Object.fromEntries( CONTACT_PURPOSES.map((purpose) => [purpose, t(`purposes.${purpose}`)]), ) as ContactsLabels["purposeNames"] export function partyFormLabels(t: Translate, refusals: Refusals): PartyFormLabels { return { heading: t("form.heading"), kind: t("form.kind"), person: t("kinds.person"), organization: t("kinds.organization"), displayName: t("form.displayName"), legalName: t("form.legalName"), country: t("form.country"), countryHint: t("form.countryHint"), linkSelf: t("form.linkSelf"), submit: t("form.submit"), busy: t("form.busy"), refusals, } } export function partyListLabels(t: Translate): PartyListLabels { return { caption: t("parties.caption"), empty: t("parties.empty"), name: t("parties.name"), kind: t("parties.kind"), country: t("parties.country"), person: t("kinds.person"), organization: t("kinds.organization"), // The placeholder is the component's to fill, so it is passed through untouched. open: t("parties.open", { name: "{name}" }), search: t("parties.search"), } } export function contactsLabels(t: Translate, count: number): ContactsLabels { return { title: t("contacts.title"), count: t("contacts.count", { count }), caption: t("contacts.caption"), empty: t("contacts.empty"), kind: t("contacts.kind"), value: t("contacts.value"), purposes: t("contacts.purposes"), primary: t("contacts.primary"), erased: t("contacts.erased"), yes: t("contacts.yes"), no: t("contacts.no"), kinds: Object.fromEntries(ALL_KINDS.map((kind) => [kind, t(`contactKinds.${kind}`)])) as ContactsLabels["kinds"], purposeNames: purposeNames(t), } } export function contactFormLabels(t: Translate, refusals: Refusals): ContactFormLabels { return { heading: t("contactForm.heading"), kind: t("contactForm.kind"), value: t("contactForm.value"), purposes: t("contactForm.purposes"), primary: t("contactForm.primary"), submit: t("contactForm.submit"), busy: t("contactForm.busy"), kinds: Object.fromEntries( CONTACT_KINDS.map((kind) => [kind, t(`contactKinds.${kind}`)]), ) as ContactFormLabels["kinds"], purposeNames: purposeNames(t), refusals, } }