// The labels each component takes, built from a message lookup. Every key this module's pages use is // named here and nowhere else, so `__tests__/i18n.test.ts` can run these builders against the // catalogues and fail on a key either language lacks -- the page itself holds no string. // // `t` takes a key relative to the module (`form.create`); the page binds it to // `i18n.message("notes." + key)`. The one message that is not this module's own, the app's // `app.failed`, is passed in already looked up. import type { AttachmentLabels } from "./attachments.js" import type { DeleteNoteLabels } from "./delete-note.js" import type { NoteFormLabels } from "./note-form.js" import type { NoteListLabels } from "./note-list.js" export type Translate = (key: string, values?: Record) => string export function createFormLabels(t: Translate, failed: string): NoteFormLabels { return { heading: t("form.createHeading"), title: t("form.titleLabel"), body: t("form.bodyLabel"), submit: t("form.create"), busy: t("form.creating"), saved: t("form.saved"), failed, } } export function editFormLabels(t: Translate, failed: string): NoteFormLabels { return { heading: t("form.editHeading"), title: t("form.titleLabel"), body: t("form.bodyLabel"), submit: t("form.save"), busy: t("form.saving"), saved: t("form.saved"), failed, } } export function listLabels(t: Translate): NoteListLabels { return { caption: t("list.caption"), empty: t("list.empty"), note: t("list.note"), attachments: t("list.attachments"), updated: t("list.updated"), // The `{title}` placeholder is the component's to fill, so it is passed through untouched. open: t("list.open", { title: "{title}" }), } } export function attachmentLabels(t: Translate, failed: string, count: number): AttachmentLabels { return { title: t("attachments.title"), count: t("attachments.count", { count }), empty: t("attachments.empty"), file: t("attachments.file"), type: t("attachments.type"), sizeHeading: t("attachments.size"), actions: t("attachments.actions"), download: t("attachments.download", { filename: "{filename}" }), remove: t("attachments.remove", { filename: "{filename}" }), removeShort: t("attachments.removeShort"), off: t("attachments.off"), uploadLabel: t("upload.label"), uploadHint: t("upload.hint"), uploadSubmit: t("upload.submit"), uploadBusy: t("upload.busy"), uploadDone: t("upload.done"), failed, } } export function deleteLabels(t: Translate, failed: string): DeleteNoteLabels { return { button: t("delete.button"), confirm: t("delete.confirm"), yes: t("delete.yes"), no: t("delete.no"), failed, } } /** A size as the message of the module: whole kilobytes, at least one. */ export const sizeLabel = (t: Translate, bytes: number): string => t("attachments.sizeKb", { size: Math.max(1, Math.ceil(bytes / 1024)) })