# FakeMessageCatalogue

A scripted [`MessageCatalogue`](https://docs.mapcairn.com/api/core/MessageCatalogue.md).

This is a class exported by `@mapcairn/core`, checked against version 0.2.0.

## Signature

```ts
import { FakeMessageCatalogue } from "@mapcairn/core";
 
class FakeMessageCatalogue implements MessageCatalogue
```

## Description

How to script it: pass `overrides` to change what a key resolves to, or
`missingKeys` to simulate a translation that lacks a key (falls back to
English and warns, like the real catalogue). `calls` records every `t`/
`plural` call in order, so a component test can assert on the key and
parameters a component asked for, rather than only on rendered text.
`list` is not scripted: it formats with `Intl.ListFormat`, the same as the
real catalogue, because it needs no catalogue lookup to fake.

## Constructors

### (constructor)

```ts
constructor(options?: FakeMessageCatalogueOptions);
```

Constructs a new instance of the `FakeMessageCatalogue` class

- `options?` (`FakeMessageCatalogueOptions`)

## Properties

### calls

```ts
readonly calls: MessageCatalogueCall[];
```

Every `t` and `plural` call, in order, with its key and parameters.

### definitionTexts

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

The host's definition text translations the fake was given, if any.

### language

```ts
readonly get language(): string;
```

The language tag, `en-GB` unless the options say otherwise.

### layerTemplates

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

The host's layer template translations the fake was given, if any.

### list

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

Joins the items with `Intl.ListFormat`. It is not recorded or scripted.

### numberingSystem

```ts
readonly get numberingSystem(): string | undefined;
```

The `Intl` numbering system the fake was given, or `undefined`.

### plural

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

Records the call, then returns the form of the text that the count selects.

### t

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

Records the call, then returns the catalogue text for the key with its parameters filled in.

## See also

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

Source: [packages/core/src/fakes/FakeMessageCatalogue.ts:63](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeMessageCatalogue.ts#L63)
