@unicef-polymer/etools-unicef
Version:
eTools UNICEF library of reusable components
40 lines (39 loc) • 1.37 kB
TypeScript
export type Value = object | string | number;
export type ValueCallback = () => Value;
export type Values = {
[key: string]: Value | ValueCallback;
};
export type ValuesCallback = () => Values;
export type Key = string;
export type LanguageIdentifier = string;
export type Translation = string;
export type Strings = {
[key: string]: string | Strings;
};
export type TranslationCache = {
[key: string]: Translation;
};
export type StringsLoader = (lang: LanguageIdentifier, config: ITranslateConfig) => Promise<Strings> | Strings;
export type InterpolateFunction = (text: string, values: Values | ValuesCallback | null, config: ITranslateConfig) => Translation;
export type EmptyFunction = (key: Key, config: ITranslateConfig) => string;
export type LookupFunction = (key: Key, config: ITranslateConfig) => string | null;
export type LangChangedEvent = {
strings: Strings;
lang: LanguageIdentifier;
config: ITranslateConfig;
};
export interface ITranslateConfig {
loader: StringsLoader;
interpolate: InterpolateFunction;
empty: EmptyFunction;
lookup: LookupFunction;
translationCache: TranslationCache;
lang?: LanguageIdentifier;
strings?: Strings;
}
export type LangChangedSubscription = () => void;
declare global {
interface GlobalEventHandlersEventMap {
langChanged: CustomEvent<LangChangedEvent>;
}
}