UNPKG

@shelchin/svelte-i18n

Version:

The last Svelte i18n library you'll ever need. Type-safe, AI-powered, zero-config.

90 lines (89 loc) 3.74 kB
import type { I18nConfig, I18nInstance, TranslationSchema, InterpolationParams, LanguageMeta, TranslationFile } from './types.js'; export declare class I18nStore implements I18nInstance { private config; private translations; private languageMeta; private currentLocale; private loading; private namespacePrefix; private validationErrors; private availableLocales; private isMainInstance; private clientLoadCalled; private localeRestored; get locale(): string; get locales(): string[]; get isLoading(): boolean; get errors(): Record<string, string[]>; get meta(): Record<string, LanguageMeta>; constructor(config: I18nConfig); /** * Set up locale synchronization with global state */ private setupLocaleSync; /** * Set locale synchronously without persistence (for initial hydration) */ setLocaleSync(locale: string): void; setLocale(locale: string): Promise<void>; t: (key: string, params?: InterpolationParams) => string; /** * Load translations synchronously (for built-in translations) * This is used to prevent flash during hydration */ loadLanguageSync(locale: string, translations: TranslationSchema | TranslationFile): void; loadLanguage(locale: string, source?: string | TranslationSchema | TranslationFile): Promise<void>; validateTranslations(locale: string, schema?: TranslationSchema): boolean; formatDate(date: Date | number | string, preset?: string): string; formatTime(date: Date | number | string, preset?: string): string; formatNumber(num: number, preset?: string): string; formatCurrency(num: number, currency?: string): string; formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit): string; formatList(items: string[], type?: 'conjunction' | 'disjunction' | 'unit'): string; detectBrowserLanguage(): string | null; getNamespace(): string | undefined; canShowValidationPopup(): boolean; setActiveValidationPopup(active: boolean): void; /** * Server-side method to load translations and determine best locale * This method is for SSR and should be called in +layout.server.ts * * @param cookies SvelteKit cookies object * @returns The best locale to use based on cookie and available translations */ serverLoad(cookies: any): Promise<string>; /** * Load registered translations synchronously (for SSR) * This ensures translations are available during server-side rendering */ private loadRegisteredTranslations; /** * Revalidate all loaded translations against the default locale * This is needed when translations are loaded out of order * * Note: Uses config.defaultLocale which can be any language (not just 'en') * This allows users to use Chinese, Japanese, or any other language as their reference */ private revalidateAllTranslations; /** * Client-side method to automatically load all available languages * This method handles: * - Checking if languages are already loaded * - Loading all available languages * - Setting fallback locale if needed * * @param options Optional configuration for loading * @returns Promise that resolves when loading is complete */ clientLoad(options?: { initialLocale?: string; skipLocaleRestore?: boolean; }): Promise<void>; } /** * Clear all instances (for testing) */ export declare function clearAllInstances(): void; export declare function setupI18n(config: I18nConfig): I18nInstance; export declare function getI18n(namespace?: string): I18nInstance; export declare function resetI18nForTesting(): void;