@reaktly-js/tone-accessibility
Version:
A vanilla JS Accessability Widget compliant with ADA and WCAG 2.2.
31 lines (30 loc) • 1.26 kB
TypeScript
import { TranslationKey } from '../i18n/keys.js';
export type LanguageCode = string;
export declare class I18nService {
private static instance;
private translations;
private currentLanguage;
private constructor();
static getInstance(): I18nService;
/**
* Asynchronously loads and sets the language for the service.
* This is the preferred way to change languages.
* @param lang The language code to set (e.g., 'en', 'es').
* @returns A promise that resolves to true if the language was loaded and set, false otherwise.
*/
setLanguage(lang: LanguageCode): Promise<boolean>;
/**
* Initializes the service with a default language without preloading it.
* Call this once when your application starts.
* @param initialLang The default language code.
*/
init(initialLang?: LanguageCode): Promise<void>;
getCurrentLanguage(): LanguageCode;
/**
* Translates a key. It's highly performant due to direct Map lookups.
* It provides a fallback to English if a key is missing in the current language.
* @param key The TranslationKey to translate.
* @returns The translated string or the key itself if not found.
*/
translate(key: TranslationKey): string;
}