@grammyjs/i18n
Version:
Internationalization plugin for grammY based on Fluent.
52 lines • 2.43 kB
TypeScript
import type { Context, HearsContext, MiddlewareFn } from "./deps.js";
import { Fluent } from "./fluent.js";
import type { I18nConfig, I18nFlavor, LoadLocaleOptions, LocaleId, TranslationVariables } from "./types.js";
export declare class I18n<C extends Context = Context> {
private config;
readonly fluent: Fluent;
readonly locales: string[];
constructor(config: Partial<I18nConfig<C>>);
/**
* Loads locales from the specified directory and registers them in the Fluent instance.
* @param directory Path to the directory to look for the translation files.
*/
loadLocalesDir(directory: string): Promise<void>;
/**
* Loads locales from any existing nested file or folder within the specified directory and registers them in the Fluent instance.
* @param directory Path to the directory to look for the translation files.
*/
loadLocalesDirSync(directory: string): void;
/**
* Registers a locale in the Fluent instance based on the provided options.
* @param locale Locale ID
* @param options Options to specify the source and behavior of the translation
*/
loadLocale(locale: LocaleId, options: LoadLocaleOptions): Promise<void>;
/**
* Synchronously registers a locale in the Fluent instance based on the provided options.
* @param locale Locale ID
* @param options Options to specify the source and behavior of the translation
*/
loadLocaleSync(locale: LocaleId, options: LoadLocaleOptions): void;
/**
* Gets a message by its key from the specified locale.
* Alias of `translate`.
*/
t<K extends string>(locale: LocaleId, key: string, variables?: TranslationVariables<K>): string;
/** Gets a message by its key from the specified locale. */
translate<K extends string>(locale: LocaleId, key: string, variables?: TranslationVariables<K>): string;
/** Returns a middleware to .use on the `Bot` instance. */
middleware(): MiddlewareFn<C & I18nFlavor>;
}
/**
* A filter middleware for listening to the messages send by the in their language.
* It is useful when you have to listen for custom keyboard texts.
*
* ```ts
* bot.filter(hears("menu-btn"), (ctx) => ...)
* ```
*
* @param key Key of the message to listen for.
*/
export declare function hears(key: string): <C extends Context & I18nFlavor>(ctx: C) => ctx is HearsContext<C>;
//# sourceMappingURL=i18n.d.ts.map