"use client"; import * as React from "react"; type ComponentLabels = { /** Read out after a link that opens another tab. */ opensInNewTab: string; /** A Meter's value in words when the caller gives none. Template over * `{{value}}` and `{{max}}`. */ valueOfMax: string; /** The name of an ItemList checkbox. Template over `{{item}}`. */ selectItem: string; /** The FilterList's search field. */ search: string; /** The FilterList's button that empties the choice. */ clear: string; /** What the FilterList says when its search finds no option. */ noResults: string; /** The two arrows of a Pagination with a summary. */ previousPage: string; nextPage: string; /** The CodeBlock's button, before and after the copy. */ copy: string; copied: string; /** What the CodeBlock says when the browser refuses the copy. */ copyFailed: string; /** What a section of a form in an Accordion says after its title. */ sectionDone: string; sectionTodo: string; /** UsageBars: after the value of the period still running, read out. */ usageCurrent: string; /** UsageBars' legend: the period still running (template over * `{{current}}`, the words read after its value), the closed ones, and the * series when no period is running. */ usageCurrentMonth: string; usageClosedMonths: string; usageSeries: string; /** UsageBars: after the value of a period counted only in part, read * out. */ usagePartial: string; /** A figure the counter did not record: in UsageBars' legend and * read-out, and for a StatTile without a value. */ notAvailable: string; /** The same, short, under a bar of UsageBars. */ notAvailableShort: string; }; // The few words the shared components say on their own. `Providers` supplies // them from the dictionary, once for the whole app (the `pagination-labels` // pattern); a component's own label prop still wins. The English ones only // serve a render outside it. const DEFAULTS: ComponentLabels = { opensInNewTab: "(opens in a new tab)", valueOfMax: "{{value}} of {{max}}", selectItem: "Select: {{item}}", search: "Search", clear: "Clear", noResults: "No results", previousPage: "Previous page", nextPage: "Next page", copy: "Copy", copied: "Copied", copyFailed: "Copy failed: select the text and copy it by hand.", sectionDone: "(complete)", sectionTodo: "(to complete)", usageCurrent: "in progress", usageCurrentMonth: "Month {{current}}", usageClosedMonths: "Closed months", usageSeries: "Usage", usagePartial: "partial", notAvailable: "No data", notAvailableShort: "n/a", }; const ComponentLabelsContext = React.createContext(DEFAULTS); function ComponentLabelsProvider({ labels, children, }: { labels: Partial; children: React.ReactNode; }) { const value = React.useMemo(() => ({ ...DEFAULTS, ...labels }), [labels]); return ( {children} ); } function useComponentLabels(): ComponentLabels { return React.useContext(ComponentLabelsContext); } /** * What a link that opens another tab says after its words, for assistive * technology only. A component of its own so the ones that draw such a link * need no hook, and stay usable from a server component. */ function NewTabHint() { const { opensInNewTab } = useComponentLabels(); return {opensInNewTab}; } export { ComponentLabelsProvider, NewTabHint, useComponentLabels }; export type { ComponentLabels };