Skip to main content

MessageCatalogue

Formats text for one language. The SDK's dependency-free default is createMessageCatalogue; a host may wire a message-format library of its own behind this same shape.

This is an interface exported by @mapcairn/core, checked against version 0.2.0.

Signature​

import type { MessageCatalogue } from "@mapcairn/core";

interface MessageCatalogue

Properties​

definitionTexts​

readonly definitionTexts?: Readonly<Record<string, string>>;

Optional translations of a host's own definition text, by the key of a HostText. An entry replaces that text's source; a key with no own entry, or a blank one, shows the source text.

language​

readonly language: string;

BCP 47 tag of the language this instance speaks, for example "en-GB" or "af".

layerTemplates​

readonly layerTemplates?: Readonly<Record<string, string>>;

Optional host translations for layer templates, units and labels.

numberingSystem​

readonly numberingSystem?: string;

An Intl numbering system, for example "latn", that numbers and dates are written in instead of the language's own digits. Unset, they follow the language's Intl defaults. Coordinates are always ASCII. Format with formatLocale(catalogue) rather than language to honour it.

Methods​

list​

list(items: readonly string[], type?: "conjunction" | "disjunction"): string;

Joins items with Intl.ListFormat, for example "Topographic, Satellite and Dark". type defaults to "conjunction".

  • items (readonly string[])
  • type? ("conjunction" | "disjunction")

plural​

plural<K extends MessageKey>(key: K, params: MessageParams[K] & {
readonly count: number;
}): string;

As t, but first picks a form with Intl.PluralRules when the selected value has plural forms, using that value's language. A plain value is formatted as with t. params carries count plus the key's other parameters.

  • key (K)
  • params (MessageParams[K] & { readonly count: number; })

t​

t<K extends MessageKey>(key: K, params: MessageParams[K]): string;

Looks up a key, substitutes its parameters (written {name} in the string), and falls back with a single console.warn per missing key when the active catalogue lacks it. The dependency-free default uses English unless its host supplies another fallback language.

  • key (K)
  • params (MessageParams[K])

See also​

Source: packages/core/src/ports/messages.ts:1239