Skip to main content
Module

x/grammy_i18n/i18n.ts>I18n

Internationalization for grammY powered by Fluent.
Latest
class I18n
import { I18n } from "https://deno.land/x/grammy_i18n@v1.0.2/i18n.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 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.

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.