> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# I18n

> Class exported by @botmesh/core/spi.

Defined in: [i18n/I18n.ts:169](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L169)

The translation engine behind `bot.locale()`, `ctx.t()` and `ctx.lang`: locale
catalogues, plural forms, `{param}` interpolation and language resolution. Exposed for
integration authors; applications use the bot methods.

## Constructors

### Constructor

```ts theme={null}
new I18n(options?): I18n;
```

Defined in: [i18n/I18n.ts:183](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L183)

#### Parameters

| Parameter | Type |
| - | - |
| `options?` | [`I18nOptions`](https://botmesh.afaya.com.co/api/core/spi/interfaces/I18nOptions) |

#### Returns

`I18n`

## Methods

### configure()

```ts theme={null}
configure(config): this;
```

Defined in: [i18n/I18n.ts:195](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L195)

Apply i18n options (marks the registry as enabled). Throws `TypeError` on invalid values.

#### Parameters

| Parameter | Type |
| - | - |
| `config` | [`I18nConfig`](https://botmesh.afaya.com.co/api/core/interfaces/I18nConfig) |

#### Returns

`this`

***

### add()

```ts theme={null}
add(code, messages): this;
```

Defined in: [i18n/I18n.ts:228](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L228)

Deep-merge `messages` into locale `code`. Throws `TypeError` on an invalid code or tree.

#### Parameters

| Parameter | Type |
| - | - |
| `code` | `string` |
| `messages` | [`LocaleMessages`](https://botmesh.afaya.com.co/api/core/interfaces/LocaleMessages) |

#### Returns

`this`

***

### setDefaultLocale()

```ts theme={null}
setDefaultLocale(code): this;
```

Defined in: [i18n/I18n.ts:244](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L244)

Set the default locale WITHOUT turning on language resolution (`BotConfig.lang`):
the built-in texts and `ctx.lang` use `code`, and no `ctx.user` read, provider
language or detector is consulted. Throws `TypeError` on an empty code.

#### Parameters

| Parameter | Type |
| - | - |
| `code` | `string` |

#### Returns

`this`

***

### locales()

```ts theme={null}
locales(): string[];
```

Defined in: [i18n/I18n.ts:261](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L261)

Registered locale codes (built-ins included).

#### Returns

`string`\[]

***

### supported()

```ts theme={null}
supported(code): string | undefined;
```

Defined in: [i18n/I18n.ts:268](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L268)

The registered locale serving `code`: itself, else its base language
(`'es-AR'` → `'es'`). `undefined` when neither is registered, or when the
`locales` allow-list leaves it out (the default locale is always served).

#### Parameters

| Parameter | Type |
| - | - |
| `code` | `unknown` |

#### Returns

`string` | `undefined`

***

### translate()

```ts theme={null}
translate(
   lang, 
   key, 
   params?
): string;
```

Defined in: [i18n/I18n.ts:282](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L282)

Translate `key` for `lang` (see the class docs for the fallback chain).
Never throws: a key missing everywhere comes back as the key itself.

#### Parameters

| Parameter | Type |
| - | - |
| `lang` | `string` \| `undefined` |
| `key` | `string` |
| `params?` | [`TranslateParams`](https://botmesh.afaya.com.co/api/core/type-aliases/TranslateParams) |

#### Returns

`string`

***

### resolve()

```ts theme={null}
resolve(ctx): Promise<string>;
```

Defined in: [i18n/I18n.ts:311](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L311)

Resolve the language of an inbound context: the `ctx.user` preference →
the provider-reported language → the detector's answer → the default. Each
candidate only counts when a registered locale serves it ([supported](#supported)),
so the result is always a registered locale or the default. Never rejects. Returns the default
immediately while i18n is not [enabled](#enabled).

#### Parameters

| Parameter | Type |
| - | - |
| `ctx` | [`MessageContext`](https://botmesh.afaya.com.co/api/core/interfaces/MessageContext) |

#### Returns

`Promise`\<`string`>

***

### resolveDetailed()

```ts theme={null}
resolveDetailed(ctx): Promise<{
  lang: string;
  source: LangSource;
}>;
```

Defined in: [i18n/I18n.ts:316](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L316)

[resolve](#resolve) plus where the language came from (see [LangSource](https://botmesh.afaya.com.co/api/core/type-aliases/LangSource.md)). Never rejects.

#### Parameters

| Parameter | Type |
| - | - |
| `ctx` | [`MessageContext`](https://botmesh.afaya.com.co/api/core/interfaces/MessageContext) |

#### Returns

`Promise`\<\{
`lang`: `string`;
`source`: [`LangSource`](https://botmesh.afaya.com.co/api/core/type-aliases/LangSource);
}>

***

### languageOf()

```ts theme={null}
languageOf(user): Promise<string>;
```

Defined in: [i18n/I18n.ts:343](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L343)

The stored preference of a profile (the registered locale serving it), else
the default locale. Agrees with [resolve](#resolve): while i18n is not
[enabled](#enabled) it is always the default. Never rejects.

#### Parameters

| Parameter | Type |
| - | - |
| `user` | [`UserData`](https://botmesh.afaya.com.co/api/core/interfaces/UserData) |

#### Returns

`Promise`\<`string`>

***

### forget()

```ts theme={null}
forget(sender): boolean;
```

Defined in: [i18n/I18n.ts:352](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L352)

Forget the provider-reported language remembered for `sender` (subject erasure,
`bot.deleteSubject()`). Returns whether one was remembered.

#### Parameters

| Parameter | Type |
| - | - |
| `sender` | `string` |

#### Returns

`boolean`

## Accessors

### defaultLocale

#### Get Signature

```ts theme={null}
get defaultLocale(): string;
```

Defined in: [i18n/I18n.ts:252](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L252)

The default locale (normalized).

##### Returns

`string`

***

### userKey

#### Get Signature

```ts theme={null}
get userKey(): string;
```

Defined in: [i18n/I18n.ts:255](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L255)

`ctx.user` key holding the language preference.

##### Returns

`string`

***

### enabled

#### Get Signature

```ts theme={null}
get enabled(): boolean;
```

Defined in: [i18n/I18n.ts:258](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L258)

True once locales were registered or options configured — language resolution is active.

##### Returns

`boolean`

***

### hasDetector

#### Get Signature

```ts theme={null}
get hasDetector(): boolean;
```

Defined in: [i18n/I18n.ts:336](https://github.com/andresayac/botmesh/blob/main/packages/core/src/i18n/I18n.ts#L336)

Whether a custom detector is configured (its answer may depend on `ctx.body`).

##### Returns

`boolean`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.