wuchale
Version:
Protobuf-like i18n from plain code
29 lines (28 loc) • 1.23 kB
TypeScript
import { type CatalogModule, type Runtime } from '../runtime.js';
export type LoaderFunc = (loadID: string, locale: string) => CatalogModule | Promise<CatalogModule>;
export type RuntimeCollection = {
get: (loadID: string) => Runtime;
set: (loadID: string, catalog: Runtime) => void;
};
export type LoaderState = {
load: LoaderFunc;
loadIDs: string[];
collection: RuntimeCollection;
};
export declare function defaultCollection(store: Record<string, Runtime>): RuntimeCollection;
/**
* - `key` is a unique identifier for the group
* - `loadIDs` and `load` MUST be imported from the loader virtual modules or proxies.
*/
export declare function registerLoaders(key: string, load: LoaderFunc, loadIDs: string[], collection?: RuntimeCollection): (fileID: string) => Runtime;
/**
* Loads catalogs using registered async loaders.
* Can be called anywhere you want to set the locale.
*/
export declare function loadLocale(locale: string, key?: string): Promise<void>;
/**
* Loads catalogs using registered sync loaders.
* Can be called anywhere you want to set the locale.
* The loadCatalog function should be from a sync proxy.
*/
export declare function loadLocaleSync(locale: string, key?: string): void;