Skip to main content
Defined in: i18n/I18n.ts:169 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

Defined in: i18n/I18n.ts:183

Parameters

Returns

I18n

Methods

configure()

Defined in: i18n/I18n.ts:195 Apply i18n options (marks the registry as enabled). Throws TypeError on invalid values.

Parameters

Returns

this

add()

Defined in: i18n/I18n.ts:228 Deep-merge messages into locale code. Throws TypeError on an invalid code or tree.

Parameters

Returns

this

setDefaultLocale()

Defined in: i18n/I18n.ts:244 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

Returns

this

locales()

Defined in: i18n/I18n.ts:261 Registered locale codes (built-ins included).

Returns

string[]

supported()

Defined in: i18n/I18n.ts:268 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

Returns

string | undefined

translate()

Defined in: i18n/I18n.ts:282 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

Returns

string

resolve()

Defined in: i18n/I18n.ts:311 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), so the result is always a registered locale or the default. Never rejects. Returns the default immediately while i18n is not enabled.

Parameters

Returns

Promise<string>

resolveDetailed()

Defined in: i18n/I18n.ts:316 resolve plus where the language came from (see LangSource). Never rejects.

Parameters

Returns

Promise<{ lang: string; source: LangSource; }>

languageOf()

Defined in: i18n/I18n.ts:343 The stored preference of a profile (the registered locale serving it), else the default locale. Agrees with resolve: while i18n is not enabled it is always the default. Never rejects.

Parameters

Returns

Promise<string>

forget()

Defined in: i18n/I18n.ts:352 Forget the provider-reported language remembered for sender (subject erasure, bot.deleteSubject()). Returns whether one was remembered.

Parameters

Returns

boolean

Accessors

defaultLocale

Get Signature

Defined in: i18n/I18n.ts:252 The default locale (normalized).
Returns
string

userKey

Get Signature

Defined in: i18n/I18n.ts:255 ctx.user key holding the language preference.
Returns
string

enabled

Get Signature

Defined in: i18n/I18n.ts:258 True once locales were registered or options configured — language resolution is active.
Returns
boolean

hasDetector

Get Signature

Defined in: i18n/I18n.ts:336 Whether a custom detector is configured (its answer may depend on ctx.body).
Returns
boolean