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
Parameters
Returns
I18n
Methods
configure()
TypeError on invalid values.
Parameters
Returns
this
add()
messages into locale code. Throws TypeError on an invalid code or tree.
Parameters
Returns
this
setDefaultLocale()
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()
Returns
string[]
supported()
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()
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()
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()
Parameters
Returns
Promise<{
lang: string;
source: LangSource;
}>
languageOf()
Parameters
Returns
Promise<string>
forget()
sender (subject erasure,
bot.deleteSubject()). Returns whether one was remembered.
Parameters
Returns
boolean
Accessors
defaultLocale
Get Signature
Returns
string
userKey
Get Signature
ctx.user key holding the language preference.
Returns
string
enabled
Get Signature
Returns
boolean
hasDetector
Get Signature
ctx.body).
Returns
boolean