@ordojs/core
Version:
Core compiler and runtime for OrdoJS framework
233 lines • 5.96 kB
TypeScript
/**
* @fileoverview OrdoJS Core - Internationalization Manager
*/
export interface I18nConfig {
defaultLocale: string;
supportedLocales: string[];
fallbackLocale: string;
enableRTL: boolean;
enableNumberFormatting: boolean;
enableDateFormatting: boolean;
enableCurrencyFormatting: boolean;
enablePluralization: boolean;
enableGenderSupport: boolean;
enableContextSupport: boolean;
translationPath: string;
autoDetectLocale: boolean;
persistLocale: boolean;
}
export interface TranslationData {
[key: string]: string | TranslationData | ((params: any) => string);
}
export interface LocaleConfig {
code: string;
name: string;
nativeName: string;
rtl: boolean;
numberFormat: Intl.NumberFormatOptions;
dateFormat: Intl.DateTimeFormatOptions;
currencyFormat: Intl.NumberFormatOptions;
pluralRules: PluralRules;
genderRules: GenderRules;
}
export interface PluralRules {
zero?: string;
one: string;
two?: string;
few?: string;
many?: string;
other: string;
}
export interface GenderRules {
male: string;
female: string;
neutral: string;
}
export interface FormatOptions {
locale?: string;
numberFormat?: Intl.NumberFormatOptions;
dateFormat?: Intl.DateTimeFormatOptions;
currencyFormat?: Intl.NumberFormatOptions;
}
export interface TranslationContext {
count?: number;
gender?: 'male' | 'female' | 'neutral';
context?: string;
[key: string]: any;
}
/**
* Internationalization Manager for OrdoJS applications
*/
export declare class I18nManager {
private config;
private currentLocale;
private translations;
private localeConfigs;
private numberFormatters;
private dateFormatters;
private currencyFormatters;
constructor(config?: Partial<I18nConfig>);
/**
* Initialize the i18n manager
*/
private initialize;
/**
* Detect user's preferred locale
*/
private detectLocale;
/**
* Get persisted locale from storage
*/
private getPersistedLocale;
/**
* Set persisted locale in storage
*/
private setPersistedLocale;
/**
* Load translations for a locale
*/
loadTranslations(locale: string): Promise<void>;
/**
* Setup locale configurations
*/
private setupLocaleConfigs;
/**
* Setup formatters
*/
private setupFormatters;
/**
* Setup RTL support
*/
private setupRTLSupport;
/**
* Translate a key with optional context
*/
translate(key: string, context?: TranslationContext): string;
/**
* Get translation for a key
*/
private getTranslation;
/**
* Get nested translation from object
*/
private getNestedTranslation;
/**
* Interpolate variables in translation string
*/
private interpolate;
/**
* Format number according to current locale
*/
formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
/**
* Format date according to current locale
*/
formatDate(date: Date, options?: Intl.DateTimeFormatOptions): string;
/**
* Format currency according to current locale
*/
formatCurrency(value: number, currency?: string, options?: Intl.NumberFormatOptions): string;
/**
* Handle pluralization
*/
pluralize(key: string, count: number, context?: TranslationContext): string;
/**
* Get plural rule for count
*/
private getPluralRule;
/**
* Handle gender-specific translations
*/
genderize(key: string, gender: 'male' | 'female' | 'neutral', context?: TranslationContext): string;
/**
* Change current locale
*/
setLocale(locale: string): Promise<void>;
/**
* Get current locale
*/
getCurrentLocale(): string;
/**
* Get supported locales
*/
getSupportedLocales(): string[];
/**
* Get locale configuration
*/
getLocaleConfig(locale: string): LocaleConfig | undefined;
/**
* Check if locale is RTL
*/
isRTL(locale?: string): boolean;
/**
* Get locale name
*/
getLocaleName(locale: string): string;
/**
* Get native locale name
*/
getNativeLocaleName(locale: string): string;
/**
* Add custom locale configuration
*/
addLocaleConfig(locale: string, config: LocaleConfig): void;
/**
* Add custom translations
*/
addTranslations(locale: string, translations: TranslationData): void;
/**
* Create translation workflow
*/
createTranslationWorkflow(): TranslationWorkflow;
/**
* Export translations for a locale
*/
exportTranslations(locale: string): TranslationData;
/**
* Import translations for a locale
*/
importTranslations(locale: string, translations: TranslationData): void;
/**
* Get missing translations
*/
getMissingTranslations(locale: string, baseLocale?: string): string[];
/**
* Find missing translation keys
*/
private findMissingKeys;
}
/**
* Translation Workflow for managing translations
*/
export declare class TranslationWorkflow {
private i18n;
constructor(i18n: I18nManager);
/**
* Extract translatable strings from code
*/
extractStrings(code: string): string[];
/**
* Generate translation template
*/
generateTemplate(locale: string, strings: string[]): TranslationData;
/**
* Validate translations
*/
validateTranslations(locale: string): {
valid: boolean;
errors: string[];
};
/**
* Find unused translations
*/
private findUnusedTranslations;
/**
* Merge translations
*/
mergeTranslations(locale: string, newTranslations: TranslationData): void;
/**
* Deep merge objects
*/
private deepMerge;
}
//# sourceMappingURL=i18n-manager.d.ts.map