import type { FluentVariable } from '@fluent/bundle'; import type { FluentVue } from 'fluent-vue'; import type { BundleSource, BuiltResource } from '../bundle-source'; import type { StorageWrapper } from '../storage/storage-wrapper'; export type UniversalRef = { readonly value: T; } & Record; export type LocaleCode = string; export type NamespaceCode = string; export type ResourceKey = `${NamespaceCode}/${LocaleCode}`; export interface LocaleManagerParams extends LocaleParams { bundleSource: BundleSource; fallbackLocale: LocaleCode; warmUp?: boolean; storageWrapper?: StorageWrapper; } interface LocaleParams { allowedLocales?: LocaleCode[]; preferredLocale?: LocaleCode; namespaces?: NamespaceCode[]; } export interface SetLocaleParams extends LocaleParams { useCache: boolean; } export type FluentFormat = (key: string, value?: Record | undefined) => string; export type FluentFormatAttrs = (key: string, value?: Record | undefined) => Record; export interface UseI18N { currentLocale: UniversalRef; setI18N: (args?: Partial, namespace?: string) => void; $t: FluentFormat; $ta: FluentFormatAttrs; } export declare abstract class BaseLocaleManager { readonly ready: Promise; private readonly localStorageKey; private readonly bundleSource; private readonly fallbackLocale; private readonly storageWrapper; private allowedLocales; private readonly currentNamespaces; private _resolveReady; protected fluent: FluentVue | null; private _cachedBundles; private _cachedHash; private preferredLocale; protected abstract setCurrentLocaleProp(locale: string): void; abstract changeLocale(args?: Partial, namespace?: string): void; constructor({ bundleSource, preferredLocale, allowedLocales, namespaces, fallbackLocale, warmUp, storageWrapper, }: LocaleManagerParams); private warmUp; abstract useI18N(namespace?: string): UseI18N; get fluentFormat(): FluentFormat; get fluentFormatAttrs(): FluentFormatAttrs; /** * Leaving this to not break backwards compatibility. * @deprecated Use updateLocaleSettings instead. */ change(args?: Partial): Promise; /** * Updates the locale-related settings synchronously. * * This method applies the given locale configuration by updating allowed locales, * preferred locale, and active namespaces. It also primes the bundle cache immediately, * so the system is ready to serve localized content without delay. * * If `useCache` is false, the internal cache is cleared before applying the new settings. * * @param args - Partial set of locale configuration options to apply. If omitted, defaults are used. */ updateLocaleSettings(args?: Partial): void; protected initFluent(): FluentVue; protected determineLocale({ preferredLocale, allowedLocales, }: { preferredLocale?: LocaleCode; allowedLocales?: LocaleCode[]; }): LocaleCode; /** * Add multiple sources to the locale manager, and when all are loaded, triggers * the `ready` promise. * * @param sources - An array of objects with the following properties: * - locale: The locale of the source. * - namespace: The namespace of the source. * - source: The actual source string, or a promise that resolves to the * source string. */ addSources(sources: BuiltResource[]): void; /** * This method allows you to add a translation source to the bundle source at * runtime. It is expected that you will not need to call this in normal * operation, but it is here for the sake of testing. * * @param locale - The locale of the translation source to add. * @param namespace - The namespace of the translation source to add. * @param source - The source of the translation source to add. */ private addSource; private getStoredLocale; private saveLocale; private getBrowserLocale; get fluentPlugin(): FluentVue; private get currentBundles(); private get activeLocales(); private setOptions; private setPreferredLocale; private setAllowedLocales; private addNamespaces; private getCurrentBundles; private loadBundles; private getCachedBundles; private hashState; } export {};