@frank-auth/react
Version:
Flexible and customizable React UI components for Frank Authentication
130 lines • 3.93 kB
TypeScript
import { Locale, LocaleDirection, LocalizationConfig } from './types';
import { DEFAULT_LOCALE_MESSAGES, DEFAULT_LOCALIZATION_CONFIG } from './defaults';
import { LocaleMessages } from '../locales';
/**
* Deep key paths for type-safe translations
*/
type DeepKeyOf<T> = T extends object ? {
[K in keyof T]: K extends string ? T[K] extends object ? `${K}.${DeepKeyOf<T[K]>}` : K : never;
}[keyof T] : never;
export type TranslationKey = DeepKeyOf<LocaleMessages>;
/**
* Interpolation values for translations
*/
export interface InterpolationValues {
[key: string]: string | number | boolean | Date;
}
/**
* Pluralization options
*/
export interface PluralOptions {
count: number;
zero?: string;
one?: string;
two?: string;
few?: string;
many?: string;
other: string;
}
export declare class LocalizationManager {
private config;
private currentLocale;
private loadedMessages;
private listeners;
constructor(initialConfig?: Partial<LocalizationConfig>);
/**
* Get current locale
*/
getCurrentLocale(): Locale;
/**
* Get current locale metadata
*/
getCurrentLocaleMetadata(): {
name: string;
nativeName: string;
region: string;
direction: LocaleDirection;
dateFormat: string;
timeFormat: string;
numberFormat: Intl.NumberFormatOptions;
pluralRules: Intl.PluralRules;
};
/**
* Set current locale
*/
setLocale(locale: Locale): Promise<void>;
/**
* Get translation for a key
*/
t(key: TranslationKey, interpolation?: InterpolationValues): string;
/**
* Get plural translation
*/
plural(key: string, options: PluralOptions): string;
/**
* Format date according to current locale
*/
formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string;
/**
* Format time according to current locale
*/
formatTime(date: Date, options?: Intl.DateTimeFormatOptions): string;
/**
* Format number according to current locale
*/
formatNumber(number: number, options?: Intl.NumberFormatOptions): string;
/**
* Format currency according to current locale
*/
formatCurrency(amount: number, currency: string, options?: Intl.NumberFormatOptions): string;
/**
* Format relative time (e.g., "2 hours ago")
*/
formatRelativeTime(date: Date, options?: Intl.RelativeTimeFormatOptions): string;
/**
* Get available locales
*/
getAvailableLocales(): Array<{
code: Locale;
name: string;
nativeName: string;
}>;
/**
* Subscribe to locale changes
*/
subscribe(callback: (locale: Locale) => void): () => void;
/**
* Update localization configuration
*/
updateConfig(updates: Partial<LocalizationConfig>): void;
private getCurrentMessages;
private getNestedValue;
private interpolate;
private loadLocaleMessages;
private notifyListeners;
}
/**
* Create a localization manager instance
*/
export declare function createLocalizationManager(config?: Partial<LocalizationConfig>): LocalizationManager;
/**
* Detect browser locale
*/
export declare function detectBrowserLocale(supportedLocales: Locale[]): Locale;
/**
* Get text direction for a locale
*/
export declare function getLocaleDirection(locale: Locale): LocaleDirection;
/**
* Check if locale is RTL
*/
export declare function isRTL(locale: Locale): boolean;
/**
* Create namespace for translations (useful for component libraries)
*/
export declare function createTranslationNamespace(manager: LocalizationManager, namespace: string): {
t: (key: string, interpolation?: InterpolationValues) => string;
plural: (key: string, options: PluralOptions) => string;
};
export { DEFAULT_LOCALIZATION_CONFIG, DEFAULT_LOCALE_MESSAGES, };
//# sourceMappingURL=localization.d.ts.map