/** * Enhanced LionRapid Core with event-based language change and smart caching * filepath: /home/janrau/tm-integration/packages/core/src/lionRapid.ts */ import { EventEmitter } from './base/event-emitter.js'; import { HandlerChain } from './handlers/handler-chain.js'; import type { IPlugin } from './interfaces/plugin.interface.js'; import type { TranslationKeys } from './types/generated.types.js'; import type { TranslationRequest } from './types/translation.types.js'; import type { ContentUnit } from './content/types.js'; import { CacheManager } from './cache/CacheManager.js'; export declare class LionRapidCore { private handlerChain; private currentLocale; private defaultNamespace?; private pendingTranslations; bus: EventEmitter; private plugins; private formatters; private processors; private warnedNoInterpolate; private eventPlugins; private readonly markupParser; private readonly htmlSerializer; readonly cache: CacheManager; constructor(eventEmitter: EventEmitter, handlerChain: HandlerChain, defaultLocale?: string, defaultNamespace?: string); /** * ✅ Register plugin (called by builder) */ registerPlugin(plugin: IPlugin): void; /** * 🔥 EMBEDDED: Integrate plugin functionality into core */ private integrateEmbeddedPlugin; /** * 📦 TRANSLATION API - Returns PLAIN TEXT * * Strips indexed tags and returns safe plain text output. * For HTML output with styles, use tHtml() instead. * * @param key - Translation key * @param params - Optional interpolation parameters * @param defaultValue - Optional default value * @returns Plain text string (safe, no XSS risk) * * @example * ```typescript * t('welcome') // → "Hello World" * t('greeting', { name: 'John' }) // → "Hello John" * t('missing', 'Default text') // → "Default text" (if key missing) * ``` */ t(key: K, ...args: K extends keyof TranslationKeys ? TranslationKeys[K] extends Record ? [defaultValue?: string] : [params: TranslationKeys[K], defaultValue?: string] : [params?: Record, defaultValue?: string]): string; /** * 📦 HTML TRANSLATION API * Returns translation as HTML string with styles applied. * * Use for innerHTML, dangerouslySetInnerHTML, or server-side rendering. * For React components, prefer using instead. * * @param key - Translation key * @param params - Optional interpolation parameters * @param defaultValue - Optional default value (can contain HTML) * @returns HTML string with styles applied * * @example * ```typescript * // Vanilla JS * element.innerHTML = i18n.tHtml('welcome'); * // → "Hello World" * * // React (use sparingly) * * ``` */ tHtml(key: K, ...args: K extends keyof TranslationKeys ? TranslationKeys[K] extends Record ? [defaultValue?: string] : [params: TranslationKeys[K], defaultValue?: string] : [params?: Record, defaultValue?: string]): string; /** * 📦 Process value as HTML (for tHtml) * * Converts indexed tags to HTML using styles from result or namespace cache. * * @internal */ private processValueAsHtml; /** * 📦 Process a value through ContentUnit or ICU pipeline * * Processing priority: * 1. Indexed tags (<1>...) from server ContentUnit → convert to HTML at render time * 2. HTML tags (from defaultValue or legacy) → MarkupParser → ContentUnit → HTML * 3. Plain text → standard ICU processing * * @internal */ private processValue; /** * 📦 Check if a string contains indexed tags * * Used for auto-detection of server ContentUnit format. * * @param value - String to check * @returns true if indexed tags are detected */ private containsIndexedTags; /** * 📦 Process indexed value - returns PLAIN TEXT * * Strips indexed tags (<1>text) → "text" * For HTML output, use tHtml() instead. * * @internal */ private processIndexedValue; /** * 📦 Get styles for a translation key from namespace cache (fallback) * * Used when styles are not available in the result (e.g., for fallback values). * Looks up the full ContentUnit from the namespace cache to get styles. * * @internal */ private getStylesFromNamespace; /** * 📦 Process HTML value - returns PLAIN TEXT * * Parses HTML to ContentUnit, processes ICU, strips indexed tags. * For HTML output, use tHtml() instead. * * @internal */ private processHtmlValue; /** * ✅ Process translation value through embedded plugins * * Public overload for Trans component usage (simple API) */ processTranslationValue(value: string, params?: Record, locale?: string, key?: string): string; /** * Internal overload (with full TranslationRequest for t() method) */ processTranslationValue(value: string, request: TranslationRequest): string; /** * 📦 CONTENT UNIT API * Returns translation as ContentUnit for JSX rendering (Trans component) * * This is the preferred method for components that need to render * styled content with JSX interpolation. * * @param key - Translation key * @param params - Optional interpolation parameters * @param defaultValue - Optional default value (can contain HTML) * @returns ContentUnit with indexed tags and styles * * @example * ```typescript * const unit = i18n.getContentUnit('terms', {}, 'Read our Terms.'); * // → { text: "Read our <1>Terms.", styles: {"1": ["raw:"]} } * ``` */ getContentUnit(key: string, params?: Record, defaultValue?: string): ContentUnit; /** * 📦 Process ContentUnit text through ICU formatters * * Used by JSX serializers to process individual text segments. * * @param text - Text segment (may contain ICU expressions like {name}) * @param params - Interpolation parameters * @returns Processed text with ICU expressions resolved */ processContentText(text: string, params?: Record): string; /** * 📦 Check if a string contains HTML tags * * Used for auto-detection of HTML in default values. * * @param value - String to check * @returns true if HTML tags are detected */ containsHtml(value: string): boolean; /** * ✅ Handle structured formatters (plural, context) - embedded in core */ private applyStructuralFormatters; /** * Trigger background load via handler chain */ private triggerBackgroundLoad; /** * Get the current locale */ getCurrentLocale(): string; /** * Set default namespace (useful for scoped translations) */ setDefaultNamespace(namespace?: string): void; /** * Get current default namespace */ getDefaultNamespace(): string | undefined; getEntries(): Record; isCached(key: string): boolean; getHandlerChainInfo(): any; /** * ✅ Smart language change with selective cache clearing */ changeLanguage(newLocale: string, options?: { clear?: boolean; preloadNamespaces?: string[]; }): Promise; private clearCache; private clearOldLocalePendingTranslations; private loadNamespaces; /** * Reload a namespace by clearing cache and fetching fresh data from server * Useful after syncing new translations to ensure fresh data * * @param namespace - The namespace to reload * @param locale - Optional locale (defaults to current locale) * @deprecated Use cache.invalidate({ namespace, refetch: true }) instead */ reloadNamespace(namespace: string, locale?: string): Promise; private isEmbeddedPlugin; private isEventPlugin; } //# sourceMappingURL=lionRapid.d.ts.map