@readium/shared
Version:
Shared models to be used across other Readium projects and implementations in Typescript
55 lines (54 loc) • 1.79 kB
TypeScript
export interface L10nString {
compact: string;
descriptive: string;
}
type LocaleValue = string | L10nString | LocaleData;
interface LocaleData {
[key: string]: LocaleValue | LocaleValue[];
}
declare class LocalizationImpl {
private static instance;
private currentLocaleCode;
private locale;
private loadedLocales;
private constructor();
static getInstance(): LocalizationImpl;
/**
* Loads a locale dynamically
* @param localeCode BCP 47 language code (e.g., 'en', 'fr')
* @returns Promise indicating if the locale was loaded successfully
*/
loadLocale(localeCode: string): Promise<boolean>;
/**
* Registers a new locale or updates an existing one
* @param localeCode BCP 47 language code (e.g., 'en', 'fr-FR')
* @param localeData The locale data to register
*/
registerLocale(localeCode: string, localeData: LocaleData): void;
/**
* Sets the current locale by language code, loading it dynamically if needed
* @param localeCode BCP 47 language code (e.g., 'en', 'fr')
* @returns Promise indicating if the locale was set successfully
*/
setLocale(localeCode: string): Promise<boolean>;
/**
* Gets the current locale code (BCP 47)
*/
getCurrentLocale(): string;
/**
* Gets a list of available locale codes
*/
getAvailableLocales(): string[];
private getNestedValue;
/**
* Gets a localized string by key
* @param key The key for the string to retrieve
* @returns The localized string as a [L10nString], or an empty string if not found
*/
getString(key: string): L10nString;
}
/**
* The singleton instance of the [Localization] class.
*/
export declare const Localization: LocalizationImpl;
export {};