# 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

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

## Properties

### definitionTexts

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

Optional translations of a host's own definition text, by the `key` of a
[`HostText`](https://docs.mapcairn.com/api/core/HostText.md). An entry replaces that text's source; a key with no own
entry, or a blank one, shows the source text.

### language

```ts
readonly language: string;
```

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

### layerTemplates

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

Optional host translations for layer templates, units and labels.

### numberingSystem

```ts
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

```ts
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

```ts
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

```ts
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

- [`MessageKey`](https://docs.mapcairn.com/api/core/MessageKey.md)
- [`MessageParams`](https://docs.mapcairn.com/api/core/MessageParams.md)

Source: [packages/core/src/ports/messages.ts:1239](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/ports/messages.ts#L1239)
