/** * Translation function implementation with fallback chain support. * * Supports: * - Simple interpolation: "Hello {name}" * - ICU MessageFormat: "{count, plural, one {# item} other {# items}}" * - Function-based translations * - Locale-bound formatters for dates, numbers, currencies * * @module i18n/translator */ import type { I18nState, Translator } from './types.js'; /** * Get translation function for a namespace. * * The translator tries each locale in the fallback chain until it finds * a translation. If no translation is found, returns the key itself. * * @example * ```typescript * const t = createTranslator(state.i18n, 'common'); * t('welcome', { name: 'Alice' }); // "Welcome, Alice!" * ``` */ export declare function createTranslator(i18nState: I18nState, namespace: string): Translator; /** * Check if a namespace is loaded for the current locale. */ export declare function isNamespaceLoaded(i18nState: I18nState, namespace: string): boolean; /** * Check if a namespace is currently loading. */ export declare function isNamespaceLoading(i18nState: I18nState, namespace: string): boolean; /** * Get all loaded namespaces for the current locale. */ export declare function getLoadedNamespaces(i18nState: I18nState): string[]; /** * Formatters bound to the current locale. * Convenience wrapper around Intl formatters that automatically uses the current locale. */ export interface BoundFormatters { /** Format a date (e.g., "January 5, 2025" or "5 janvier 2025") */ date: (date: Date | string | number, options?: Intl.DateTimeFormatOptions) => string; /** Format a number (e.g., "1,234.56" or "1 234,56") */ number: (value: number, options?: Intl.NumberFormatOptions) => string; /** Format currency (e.g., "$1,234.56" or "1 234,56 €") */ currency: (value: number, currency: string) => string; /** Format relative time (e.g., "5 minutes ago" or "il y a 5 minutes") */ relativeTime: (date: Date) => string; } /** * Create formatters bound to the current locale from i18n state. * * This is a convenience wrapper that eliminates the need to pass locale manually. * * @param i18nState - Current i18n state (for locale) * @returns Bound formatters that automatically use the current locale * * @example Basic Usage * ```typescript * const formatters = createFormatters($store.i18n); * * // Date formatting - respects locale conventions * formatters.date(post.date, DateFormats.long); * // en: "January 5, 2025" * // fr: "5 janvier 2025" * // es: "5 de enero de 2025" * * // Number formatting - respects locale conventions * formatters.number(1234.56); * // en: "1,234.56" * // fr: "1 234,56" * // de: "1.234,56" * * // Currency formatting * formatters.currency(1234.56, 'USD'); * // en-US: "$1,234.56" * // fr: "1 234,56 $US" * * // Relative time * formatters.relativeTime(yesterday); * // en: "yesterday" * // fr: "hier" * ``` * * @example In Svelte Component * ```svelte * * *
*

{post.title}

*

{formatters.date(post.date, DateFormats.long)}

*

{formatters.number(post.views)} {t('views')}

*
* ``` */ export declare function createFormatters(i18nState: I18nState): BoundFormatters; //# sourceMappingURL=translator.d.ts.map