/** Per-locale map of message key → ICU MessageFormat string. */ type LocaleMessages = Record; /** Options for {@link createTranslator}. */ interface TranslatorOptions { /** The locale to fall back to when a key is missing for the requested locale. */ fallbackLocale: string; /** `locale → (key → ICU message)`. Locales may be `en`, `de-DE`, `de_DE`, … */ messages: Record; /** Called when a key is missing in every candidate locale; defaults to returning the key. */ onMissing?: (locale: string, key: string) => string; } /** Resolves and formats localized messages with ICU MessageFormat. */ interface Translator { /** Whether `key` resolves for `locale` (via region → language → fallback). */ has: (locale: string, key: string) => boolean; /** Format `key` for `locale`, interpolating `values` (plurals/select via ICU). */ translate: (locale: string, key: string, values?: Record) => string; } /** * Create a {@link Translator} over a set of locale message tables, using * [ICU MessageFormat](https://formatjs.io/docs/core-concepts/icu-syntax/) (plurals, * select, number/date) via `intl-messageformat`, with region → language → fallback * resolution driven by the subscriber's locale. Edge-safe and dependency-light * (requires the `intl-messageformat` peer). * @param options Message tables, fallback locale, and an optional missing-key handler. * @returns A {@link Translator}. * @example * ```ts * const t = createTranslator({ * fallbackLocale: "en", * messages: { * en: { likes: "{count, plural, one {# like} other {# likes}}" }, * de_DE: { likes: "{count, plural, one {# Like} other {# Likes}}" }, * }, * }); * * t.translate("de_DE", "likes", { count: 3 }); // "3 Likes" * t.translate("fr", "likes", { count: 1 }); // falls back to en → "1 like" * ``` */ declare const createTranslator: (options: TranslatorOptions) => Translator; export { type Translator, type TranslatorOptions, createTranslator };