import { ReadonlyVal, Val } from 'value-enhancer'; type LocaleLang = string; type LocaleLangObservable = ReadonlyVal; type Locale = { readonly [key: string]: string | Locale; }; type Locales = { readonly [lang: LocaleLang]: Locale; }; /** Optional `args` object for t function */ type TFunctionArgs = { readonly [key: string | number]: any; readonly ["@"]?: string | number; }; /** * Get locale message by key-path(`"a.b.c"`) with optional arguments for interpolation * @returns locale message or empty string if not found */ type TFunction = (keyPath: string, args?: TFunctionArgs) => string; type TFunctionObservable = ReadonlyVal; interface LocaleFetcher { (lang: LocaleLang): Promise | Locale; } interface I18nOptions { /** Fetch locale of the specified lang. */ fetcher: LocaleFetcher; } declare class I18n { /** Fetch locale of `initialLang` and return an I18n instance with the locale. */ static preload(initialLang: LocaleLang, fetcher: LocaleFetcher): Promise; /** A Val of current lang. */ readonly lang$: ReadonlyVal; /** Current lang. */ get lang(): LocaleLang; /** A Val of current translate function. */ readonly t$: ReadonlyVal; /** Translation function that uses the current `t$` function. */ readonly t: TFunction; /** Fetch locale of the specified lang. */ fetcher?: LocaleFetcher; /** A Val of all loaded locales. */ readonly locales$: Val; /** All loaded locales. */ get locales(): Locales; /** A Val of current locale. */ readonly locale$: ReadonlyVal; /** Current locale */ get locale(): Locale; constructor(initialLang: LocaleLang, locales: Locales, options?: I18nOptions); /** * Change language. * * @returns — a promise that resolves when the new locale is fetched. */ switchLang(lang: LocaleLang): Promise; /** * @returns — boolean indicating whether a message with the specified key in current language exists or not. */ hasKey(key: string): boolean; /** * Add a locale to the locales. * * Use `i18n.locales$.set()` for more control. */ addLocale(lang: LocaleLang, locale: Locale): void; dispose(): void; } /** * Get browser/nodejs language * * @returns BCP 47 tags of the browser/nodejs language */ declare function detectLang(): string; /** * Get browser/nodejs language that matches the given language tags * * @param langs The language tags to match (BCP 47 tags and sub-tags are supported) * @returns The first language tag that matches the browser/nodejs language, or `null` if no match * * @example * ```js * detectLang(["en", "zh-CN"]) || "zh-TW" * ``` */ declare function detectLang(langs: readonly T[]): T | null; declare function detectLang(langs: readonly string[]): string | null; export { I18n, type I18nOptions, type Locale, type LocaleFetcher, type LocaleLang, type LocaleLangObservable, type Locales, type TFunction, type TFunctionArgs, type TFunctionObservable, detectLang };