Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/grammy_i18n/mod.ts>I18n

Internationalization for grammY powered by Fluent.
Latest
class I18n
import { I18n } from "https://deno.land/x/grammy_i18n@v1.1.0/mod.ts";

Constructors

new
I18n(config: Partial<I18nConfig<C>>)

Type Parameters

optional
C extends Context = Context

Properties

private
config: I18nConfig<C>
readonly
fluent: Fluent
readonly
locales: Array<string>

Methods

loadLocale(locale: LocaleId, options: LoadLocaleOptions): Promise<void>

Registers a locale in the Fluent instance based on the provided options.

loadLocalesDir(directory: string): Promise<void>

Loads locales from the specified directory and registers them in the Fluent instance.

loadLocalesDirSync(directory: string): void

Loads locales from any existing nested file or folder within the specified directory and registers them in the Fluent instance.

loadLocaleSync(locale: LocaleId, options: LoadLocaleOptions): void

Synchronously registers a locale in the Fluent instance based on the provided options.

middleware(): MiddlewareFn<C & I18nFlavor>

Returns a middleware to .use on the Bot instance.

t<K extends string>(
locale: LocaleId,
key: string,
variables?: TranslationVariables<K>,
): string

Gets a message by its key from the specified locale. Alias of translate.

translate<K extends string>(
locale: LocaleId,
key: string,
variables?: TranslationVariables<K>,
): string

Gets a message by its key from the specified locale.