UNPKG

@shelchin/svelte-i18n

Version:

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

55 lines (54 loc) 1.85 kB
/** * Unified persistence module for i18n locale management * Handles both client-side (localStorage) and universal (cookie + localStorage) persistence */ interface PersistenceConfig { cookieName?: string; storageKey?: string; enableBrowserDetection?: boolean; } /** * Get locale from cookies (works on both server and client) */ export declare function getLocaleFromCookie(cookieString: string, cookieName?: string): string | null; /** * Set locale in cookie (client-side only) */ export declare function setLocaleCookie(locale: string, cookieName?: string): void; /** * Get locale from localStorage (client-side only) */ export declare function getLocaleFromStorage(storageKey?: string): string | null; /** * Set locale in localStorage (client-side only) */ export declare function setLocaleStorage(locale: string, storageKey?: string): void; /** * Save locale to both cookie and localStorage */ export declare function saveLocaleUniversal(locale: string, config?: PersistenceConfig): void; /** * Get initial locale from cookie or localStorage * Priority: cookie > localStorage > browser > default */ export declare function getInitialLocaleUniversal(defaultLocale: string, cookieString?: string, config?: PersistenceConfig): string; /** * Save the selected locale to localStorage and cookie */ export declare function saveLocale(locale: string): void; /** * Load the saved locale from localStorage */ export declare function loadSavedLocale(): string | null; /** * Clear the saved locale from both localStorage and cookie */ export declare function clearSavedLocale(): void; /** * Get initial locale based on priority: * 1. Saved locale from localStorage * 2. Browser language * 3. Default locale */ export declare function getInitialLocale(defaultLocale: string, availableLocales?: string[]): string; export {};