Skip to content

Adapter Interface

interface I18nAdapter {
name: string;
getLocale(): Locale;
getTranslations(locale: Locale): TranslationDictionary;
onLocaleChange(callback: (locale: Locale) => void): () => void;
getKeyFromElement?(element: HTMLElement): string | null;
destroy?(): void;
}
Property/MethodRequiredDescription
name✅Unique adapter identifier
getLocale()✅Returns the currently active locale
getTranslations(locale)✅Returns the full translation dictionary for a locale
onLocaleChange(cb)✅Subscribes to locale changes. Returns unsubscribe function
getKeyFromElement(el)❌Extract the i18n key from a DOM element (for auto-tagging)
destroy()❌Clean up any listeners or observers
type TranslationDictionary = Record<string, string | TranslationValue>;
type TranslationValue = string | Record<string, string>;

Supports both flat and nested structures:

{
"nav.home": "Home",
"card.welcome": "Welcome!",
"app": {
"title": "My App",
"subtitle": "Edit translations live"
}
}