@fluenti/react 0.3.3 → 0.4.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/dist/components/DateTime.d.ts +3 -3
  3. package/dist/components/DateTime.d.ts.map +1 -1
  4. package/dist/components/Number.d.ts +3 -3
  5. package/dist/components/Number.d.ts.map +1 -1
  6. package/dist/components/trans-core.d.ts.map +1 -1
  7. package/dist/components-entry.cjs +2 -0
  8. package/dist/components-entry.cjs.map +1 -0
  9. package/dist/components-entry.d.ts +12 -0
  10. package/dist/components-entry.d.ts.map +1 -0
  11. package/dist/components-entry.js +91 -0
  12. package/dist/components-entry.js.map +1 -0
  13. package/dist/context-DVbvrSE8.cjs +2 -0
  14. package/dist/context-DVbvrSE8.cjs.map +1 -0
  15. package/dist/context-DVudCV1o.js +7 -0
  16. package/dist/context-DVudCV1o.js.map +1 -0
  17. package/dist/create-fluenti.d.ts +12 -8
  18. package/dist/create-fluenti.d.ts.map +1 -1
  19. package/dist/{icu-rich-BOtj4Oxu.js → icu-rich-ChVWsA7C.js} +18 -11
  20. package/dist/icu-rich-ChVWsA7C.js.map +1 -0
  21. package/dist/icu-rich-CotMVC_x.cjs +2 -0
  22. package/dist/icu-rich-CotMVC_x.cjs.map +1 -0
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.ts +0 -5
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +127 -288
  28. package/dist/index.js.map +1 -1
  29. package/dist/provider.d.ts +41 -0
  30. package/dist/provider.d.ts.map +1 -1
  31. package/dist/server.cjs +1 -1
  32. package/dist/server.cjs.map +1 -1
  33. package/dist/server.d.ts +24 -9
  34. package/dist/server.d.ts.map +1 -1
  35. package/dist/server.js +23 -22
  36. package/dist/server.js.map +1 -1
  37. package/dist/types.d.ts +5 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/llms-full.txt +2 -1
  40. package/llms-migration.txt +2 -2
  41. package/llms.txt +61 -0
  42. package/package.json +18 -4
  43. package/dist/icu-rich-BOtj4Oxu.js.map +0 -1
  44. package/dist/icu-rich-vPU-0wGQ.cjs +0 -2
  45. package/dist/icu-rich-vPU-0wGQ.cjs.map +0 -1
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/create-fluenti.ts","../src/context.ts","../src/global-registry.ts","../src/provider.tsx","../src/hooks/useI18n.ts","../src/compile-time-t.ts","../src/components/Trans.tsx","../src/components/Plural.tsx","../src/components/Select.tsx","../src/components/DateTime.tsx","../src/components/Number.tsx"],"sourcesContent":["import { useState, useCallback, useEffect, useMemo, useRef } from 'react'\nimport { createFluentiCore } from '@fluenti/core'\nimport type {\n FluentiCoreInstanceFull as FluentInstanceExtended,\n CompiledMessage,\n Locale,\n Messages,\n AllMessages,\n DateFormatOptions,\n NumberFormatOptions,\n LocalizedString,\n MessageDescriptor,\n} from '@fluenti/core'\n\n/**\n * Configuration for `createFluenti()`.\n */\nexport interface FluentiConfig {\n /** Active locale code */\n locale: string\n /** Static message catalogs keyed by locale */\n messages?: AllMessages\n /** Async loader for lazy-loading locale messages */\n loadMessages?: (locale: string) => Promise<Messages | { default: Messages }>\n /** Fallback locale when a translation is missing */\n fallbackLocale?: string\n /** Custom fallback chains per locale */\n fallbackChain?: Record<string, string[]>\n /** Date format styles */\n dateFormats?: DateFormatOptions\n /** Number format styles */\n numberFormats?: NumberFormatOptions\n /** Missing message handler */\n missing?: (locale: Locale, id: string) => string | undefined\n}\n\n/**\n * The object returned by `createFluenti()`.\n *\n * Contains all i18n state and methods. Pass to `<I18nProvider instance={...}>`\n * or use directly in tests/non-React contexts.\n */\nexport interface FluentiInstance {\n /** Translate a message by id with optional interpolation values */\n t: {\n (id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n (strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n }\n /** Format a date value for the current locale */\n d: (value: Date | number, style?: string) => LocalizedString\n /** Format a number value for the current locale */\n n: (value: number, style?: string) => LocalizedString\n /** Current locale */\n locale: string\n /** Change the active locale (async when lazy loading) */\n setLocale: (locale: string) => Promise<void>\n /** Whether a locale is currently being loaded */\n isLoading: boolean\n /** Preload a locale in the background without switching to it */\n preloadLocale: (locale: string) => Promise<void>\n /** Check whether a translation key exists for the given or current locale */\n te: (key: string, locale?: string) => boolean\n /** Get the raw compiled message for a key without interpolation */\n tm: (key: string, locale?: string) => CompiledMessage | undefined\n /** The underlying Fluent instance (escape hatch for advanced use) */\n i18n: FluentInstanceExtended\n /** Format an ICU message string directly (no catalog lookup) */\n format: (message: string, values?: Record<string, unknown>) => LocalizedString\n /** Merge additional messages into a locale catalog at runtime */\n loadMessages: (locale: string, messages: Messages) => void\n /** Return all locale codes that have loaded messages */\n getLocales: () => string[]\n /** Set of locales whose messages have been loaded */\n loadedLocales: string[]\n}\n\nfunction unwrapMessages(allMessages: Record<string, unknown>): Record<string, Messages> {\n const result: Record<string, Messages> = {}\n for (const [locale, msgs] of Object.entries(allMessages)) {\n result[locale] = typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : msgs as Messages\n }\n return result\n}\n\n/**\n * Create a standalone Fluenti i18n instance.\n *\n * This is a React hook that manages locale state, message loading, and\n * provides all i18n methods. The returned instance can be passed to\n * `<I18nProvider instance={...}>` to share it with the component tree.\n *\n * @example\n * ```tsx\n * function App() {\n * const i18n = createFluenti({\n * locale: 'en',\n * messages: { en: enMessages, fr: frMessages },\n * })\n * return (\n * <I18nProvider instance={i18n}>\n * <MyApp />\n * </I18nProvider>\n * )\n * }\n * ```\n */\nexport function createFluenti(config: FluentiConfig): FluentiInstance {\n const {\n locale: initialLocale,\n messages: initialMessages,\n loadMessages: loadMessagesFn,\n fallbackLocale,\n fallbackChain,\n dateFormats,\n numberFormats,\n missing,\n } = config\n\n const [currentLocale, setCurrentLocale] = useState(initialLocale)\n const [isLoading, setIsLoading] = useState(false)\n const [loadedMessages, setLoadedMessages] = useState<Record<string, Messages>>(\n initialMessages ? unwrapMessages(initialMessages) : {},\n )\n const [loadedLocales, setLoadedLocales] = useState<string[]>(\n initialMessages ? Object.keys(initialMessages) : [],\n )\n\n const loadedMessagesRef = useRef(loadedMessages)\n loadedMessagesRef.current = loadedMessages\n\n const localeRequestRef = useRef(0)\n\n const i18n = useMemo(() => {\n const cfg: Parameters<typeof createFluentiCore>[0] = {\n locale: currentLocale,\n messages: loadedMessages,\n }\n if (fallbackLocale !== undefined) cfg.fallbackLocale = fallbackLocale\n if (fallbackChain !== undefined) cfg.fallbackChain = fallbackChain\n if (dateFormats !== undefined) cfg.dateFormats = dateFormats\n if (numberFormats !== undefined) cfg.numberFormats = numberFormats\n if (missing !== undefined) cfg.missing = missing\n return createFluentiCore(cfg)\n }, [currentLocale, loadedMessages, fallbackLocale, fallbackChain, dateFormats, numberFormats, missing])\n\n // Sync external locale changes\n useEffect(() => {\n if (initialLocale !== currentLocale) {\n void handleSetLocale(initialLocale)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [initialLocale])\n\n const handleSetLocale = useCallback(\n async (newLocale: string) => {\n const requestId = ++localeRequestRef.current\n\n if (loadedMessagesRef.current[newLocale] && !loadMessagesFn) {\n setCurrentLocale(newLocale)\n return\n }\n\n if (loadedMessagesRef.current[newLocale]) {\n setCurrentLocale(newLocale)\n return\n }\n\n if (!loadMessagesFn) {\n console.warn(\n `[fluenti] No messages for locale \"${newLocale}\" and no loadMessages function provided`,\n )\n return\n }\n\n setIsLoading(true)\n try {\n const msgs = await loadMessagesFn(newLocale)\n if (requestId !== localeRequestRef.current) return\n\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n setLoadedMessages((prev) => ({ ...prev, [newLocale]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, newLocale])])\n setCurrentLocale(newLocale)\n } catch (err) {\n if (requestId === localeRequestRef.current) {\n console.error(`[fluenti] Failed to load locale \"${newLocale}\"`, err)\n }\n } finally {\n if (requestId === localeRequestRef.current) {\n setIsLoading(false)\n }\n }\n },\n [loadMessagesFn],\n )\n\n const preloadLocale = useCallback(\n async (loc: string) => {\n if (loadedMessagesRef.current[loc] || !loadMessagesFn) return\n try {\n const msgs = await loadMessagesFn(loc)\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n setLoadedMessages((prev) => ({ ...prev, [loc]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, loc])])\n } catch {\n // Silent fail for preload\n }\n },\n [loadMessagesFn],\n )\n\n const te = useCallback(\n (key: string, loc?: string): boolean => {\n const msgs = loadedMessages[loc ?? currentLocale]\n return msgs !== undefined && key in msgs\n },\n [loadedMessages, currentLocale],\n )\n\n const tm = useCallback(\n (key: string, loc?: string): Messages[string] | undefined => {\n const msgs = loadedMessages[loc ?? currentLocale]\n if (!msgs) return undefined\n return msgs[key]\n },\n [loadedMessages, currentLocale],\n )\n\n return useMemo(\n () => ({\n t: i18n.t.bind(i18n),\n d: i18n.d.bind(i18n),\n n: i18n.n.bind(i18n),\n locale: currentLocale,\n setLocale: handleSetLocale,\n isLoading,\n preloadLocale,\n te,\n tm,\n i18n,\n format: i18n.format.bind(i18n),\n loadMessages: i18n.loadMessages.bind(i18n),\n getLocales: i18n.getLocales.bind(i18n),\n loadedLocales,\n }),\n [i18n, currentLocale, handleSetLocale, isLoading, preloadLocale, te, tm, loadedLocales],\n )\n}\n","import { createContext } from 'react'\nimport type { FluentiContext } from './types'\n\nexport const I18nContext = createContext<FluentiContext | null>(null)\n","import type { FluentiCoreInstanceFull } from '@fluenti/core'\n\n/**\n * Global i18n instance registry.\n *\n * Used by `@fluenti/next` webpack loader and `@fluenti/vite-plugin` to access\n * the i18n instance from module-level code via a Proxy. The instance is set by\n * `<I18nProvider>` on mount.\n */\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __fluenti_i18n: FluentiCoreInstanceFull | undefined\n}\n\n/** Get the global i18n instance (set by `<I18nProvider>`). */\nexport function getGlobalI18n(): FluentiCoreInstanceFull | undefined {\n return globalThis.__fluenti_i18n\n}\n\n/** Set the global i18n instance. Called by `<I18nProvider>` on mount. */\nexport function setGlobalI18n(instance: FluentiCoreInstanceFull): void {\n globalThis.__fluenti_i18n = instance\n}\n\n/** Clear the global i18n instance. Primarily for testing. */\nexport function clearGlobalI18n(): void {\n globalThis.__fluenti_i18n = undefined\n}\n","import { useState, useCallback, useEffect, useMemo, useRef } from 'react'\nimport { createFluentiCore } from '@fluenti/core'\nimport type { Messages } from '@fluenti/core'\nimport { I18nContext } from './context'\nimport type { FluentiProviderProps, FluentiContext } from './types'\nimport type { FluentiInstance } from './create-fluenti'\nimport { setGlobalI18n } from './global-registry'\n\ninterface SplitRuntimeModule {\n __switchLocale?: (locale: string) => Promise<void>\n __preloadLocale?: (locale: string) => Promise<void>\n}\n\nfunction unwrapMessages(allMessages: Record<string, unknown>): Record<string, Messages> {\n const result: Record<string, Messages> = {}\n for (const [locale, msgs] of Object.entries(allMessages)) {\n result[locale] = typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : msgs as Messages\n }\n return result\n}\n\nconst SPLIT_RUNTIME_KEY = Symbol.for('fluenti.runtime.react.v1')\n\nfunction getSplitRuntimeModule(): SplitRuntimeModule | null {\n const runtime = (globalThis as Record<PropertyKey, unknown>)[SPLIT_RUNTIME_KEY]\n return typeof runtime === 'object' && runtime !== null\n ? runtime as SplitRuntimeModule\n : null\n}\n\n/**\n * Internal provider that uses a pre-created `FluentiInstance`.\n */\nfunction InstanceProvider({ instance, children }: { instance: FluentiInstance; children: React.ReactNode }) {\n const ctx: FluentiContext = useMemo(\n () => ({\n t: instance.t,\n d: instance.d,\n n: instance.n,\n format: instance.format,\n loadMessages: instance.loadMessages,\n getLocales: instance.getLocales,\n locale: instance.locale,\n setLocale: instance.setLocale,\n isLoading: instance.isLoading,\n loadedLocales: instance.loadedLocales,\n preloadLocale: instance.preloadLocale,\n te: instance.te,\n tm: instance.tm,\n // Internal: used by __useI18n hook and compiled components — not part of public API\n i18n: instance.i18n,\n }) as FluentiContext,\n [instance],\n )\n\n return <I18nContext.Provider value={ctx}>{children}</I18nContext.Provider>\n}\n\nexport function I18nProvider(props: FluentiProviderProps) {\n if (props.instance) {\n return <InstanceProvider instance={props.instance}>{props.children}</InstanceProvider>\n }\n\n return <InlineProvider {...props} />\n}\n\n/**\n * Original inline provider that manages its own state.\n */\nfunction InlineProvider({\n locale: localeProp,\n fallbackLocale,\n messages,\n loadMessages,\n fallbackChain,\n dateFormats,\n numberFormats,\n missing,\n diagnostics,\n children,\n}: FluentiProviderProps) {\n const locale = localeProp ?? 'en'\n\n const [currentLocale, setCurrentLocale] = useState(locale)\n const [isLoading, setIsLoading] = useState(false)\n const [loadedMessages, setLoadedMessages] = useState<Record<string, Messages>>(\n messages ? unwrapMessages(messages) : {},\n )\n const [loadedLocales, setLoadedLocales] = useState<string[]>(\n messages ? Object.keys(messages) : [],\n )\n\n // Use ref to avoid stale closures in callbacks\n const loadedMessagesRef = useRef(loadedMessages)\n loadedMessagesRef.current = loadedMessages\n\n // Guard against out-of-order async locale loads (race condition protection)\n const localeRequestRef = useRef(0)\n\n const i18n = useMemo(() => {\n const config: Parameters<typeof createFluentiCore>[0] = {\n locale: currentLocale,\n messages: loadedMessages,\n }\n if (fallbackLocale !== undefined) config.fallbackLocale = fallbackLocale\n if (fallbackChain !== undefined) config.fallbackChain = fallbackChain\n if (dateFormats !== undefined) config.dateFormats = dateFormats\n if (numberFormats !== undefined) config.numberFormats = numberFormats\n if (missing !== undefined) config.missing = missing\n if (diagnostics !== undefined) config.diagnostics = diagnostics\n return createFluentiCore(config)\n }, [currentLocale, loadedMessages, fallbackLocale, fallbackChain, dateFormats, numberFormats, missing, diagnostics])\n\n // Set global i18n instance for webpack loader / vite plugin access\n useEffect(() => {\n setGlobalI18n(i18n)\n }, [i18n])\n\n // Sync external locale prop changes\n useEffect(() => {\n if (locale !== currentLocale) {\n void handleSetLocale(locale)\n }\n // Intentionally only depend on `locale` — we want to sync when the\n // external prop changes, not when internal state (`currentLocale`,\n // `handleSetLocale`) updates, which would cause infinite re-renders.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [locale])\n\n const handleSetLocale = useCallback(\n async (newLocale: string) => {\n const requestId = ++localeRequestRef.current\n\n if (loadedMessagesRef.current[newLocale] && !loadMessages) {\n setCurrentLocale(newLocale)\n return\n }\n\n const splitRuntime = loadMessages ? getSplitRuntimeModule() : null\n\n if (loadedMessagesRef.current[newLocale]) {\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n setCurrentLocale(newLocale)\n return\n }\n\n if (!loadMessages) {\n console.warn(\n `[fluenti] No messages for locale \"${newLocale}\" and no loadMessages function provided`,\n )\n return\n }\n\n setIsLoading(true)\n try {\n const msgs = await loadMessages(newLocale)\n\n // A newer request has superseded this one — discard stale result\n if (requestId !== localeRequestRef.current) return\n\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n setLoadedMessages((prev) => ({ ...prev, [newLocale]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, newLocale])])\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n setCurrentLocale(newLocale)\n } catch (err) {\n // Only log if this request is still the latest\n if (requestId === localeRequestRef.current) {\n console.error(`[fluenti] Failed to load locale \"${newLocale}\"`, err)\n }\n } finally {\n if (requestId === localeRequestRef.current) {\n setIsLoading(false)\n }\n }\n },\n [loadMessages],\n )\n\n const preloadLocale = useCallback(\n async (loc: string) => {\n const splitRuntime = getSplitRuntimeModule()\n if (loadedMessagesRef.current[loc] || !loadMessages) return\n try {\n const msgs = await loadMessages(loc)\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n setLoadedMessages((prev) => ({ ...prev, [loc]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, loc])])\n if (splitRuntime?.__preloadLocale) {\n await splitRuntime.__preloadLocale(loc)\n }\n } catch {\n // Silent fail for preload\n }\n },\n [loadMessages],\n )\n\n const te = useCallback(\n (key: string, loc?: string): boolean => {\n const msgs = loadedMessagesRef.current[loc ?? currentLocale]\n return msgs !== undefined && key in msgs\n },\n [currentLocale],\n )\n\n const tm = useCallback(\n (key: string, loc?: string): Messages[string] | undefined => {\n const msgs = loadedMessagesRef.current[loc ?? currentLocale]\n if (!msgs) return undefined\n return msgs[key]\n },\n [currentLocale],\n )\n\n const ctx = useMemo(\n () => ({\n t: i18n.t.bind(i18n),\n d: i18n.d.bind(i18n),\n n: i18n.n.bind(i18n),\n format: i18n.format.bind(i18n),\n loadMessages: i18n.loadMessages.bind(i18n),\n getLocales: i18n.getLocales.bind(i18n),\n locale: currentLocale,\n setLocale: handleSetLocale,\n isLoading,\n loadedLocales,\n preloadLocale,\n te,\n tm,\n // Internal: used by __useI18n hook and compiled components — not part of public API\n i18n,\n }) as FluentiContext,\n [i18n, currentLocale, handleSetLocale, isLoading, loadedLocales, preloadLocale, te, tm],\n )\n\n return <I18nContext.Provider value={ctx}>{children}</I18nContext.Provider>\n}\n","import { useContext } from 'react'\nimport { I18nContext } from '../context'\nimport type { FluentiContext } from '../types'\n\n/**\n * Primary hook for accessing i18n functions.\n *\n * Returns locale, setLocale, isLoading, loadedLocales, preloadLocale,\n * and the underlying i18n instance with t(), d(), n() methods.\n *\n * @throws If used outside of `<I18nProvider>`\n */\nexport function useI18n(): FluentiContext {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error(\n '[fluenti] useI18n() must be used within an <I18nProvider>. ' +\n 'Wrap your app with <I18nProvider> to provide i18n context.',\n )\n }\n return ctx\n}\n","import type { CompileTimeT } from '@fluenti/core'\n\nexport const t: CompileTimeT = ((..._args: unknown[]) => {\n throw new Error(\n \"[fluenti] `t` imported from '@fluenti/react' is a compile-time API. \" +\n 'Use it only with the Fluenti build transform inside a component or custom hook. ' +\n 'For runtime lookups, use useI18n().t(...).',\n )\n}) as CompileTimeT\n","import {\n createElement,\n memo,\n useContext,\n useMemo,\n type ReactElement,\n type ReactNode,\n} from 'react'\nimport { I18nContext } from '../context'\nimport { hashMessage, extractMessage, reconstruct } from './trans-core'\n\nexport interface FluentiTransProps {\n /** Source text with embedded components */\n children: ReactNode\n /** Override auto-generated hash ID */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Context comment for translators */\n comment?: string\n /** Wrapper element tag name (e.g. 'span', 'div'). Defaults to Fragment (no wrapper). */\n tag?: keyof React.JSX.IntrinsicElements\n /** Custom render wrapper */\n render?: (translation: ReactNode) => ReactNode\n /** @internal Pre-computed message ID from build plugin */\n __id?: string\n /** @internal Pre-computed ICU message from build plugin */\n __message?: string\n /** @internal Pre-computed component list from build plugin */\n __components?: ReactElement[]\n}\n\n/**\n * `<Trans>` component for rich-text translations containing nested React elements.\n *\n * @example\n * ```tsx\n * <Trans>Read the <a href=\"/docs\">documentation</a> for more info.</Trans>\n * ```\n */\nexport const Trans = memo(function Trans({\n children,\n id,\n context,\n comment,\n tag,\n render,\n __id,\n __message,\n __components,\n}: FluentiTransProps) {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error('[fluenti] <Trans> must be used within an <I18nProvider>')\n }\n\n // Fast path: build plugin pre-computed message and components\n const hasPrecomputed = __message !== undefined\n\n const { message, components } = useMemo(\n () => hasPrecomputed\n ? { message: __message!, components: __components ?? [] }\n : extractMessage(children),\n [hasPrecomputed, __message, __components, children],\n )\n const messageId = useMemo(\n () => id ?? __id ?? hashMessage(message, context),\n [id, __id, message, context],\n )\n\n const translated = ctx.t(\n {\n id: messageId,\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n )\n\n const result = reconstruct(translated, components)\n if (render) return render(result)\n return tag ? createElement(tag, null, result) : <>{result}</>\n})\n","import { memo, useContext, type ReactNode } from 'react'\nimport { hashMessage } from '@fluenti/core/internal'\nimport { I18nContext } from '../context'\nimport { PLURAL_CATEGORIES, type PluralCategory } from './plural-core'\nimport { buildICUPluralMessage, renderRichTranslation, serializeRichForms } from './icu-rich'\n\nexport interface FluentiPluralProps {\n /** The count value */\n value: number\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Text for zero (if language supports) */\n zero?: ReactNode\n /** Singular form. `#` replaced with value */\n one?: ReactNode\n /** Dual form (Arabic, etc.) */\n two?: ReactNode\n /** Few form (Slavic languages, etc.) */\n few?: ReactNode\n /** Many form */\n many?: ReactNode\n /** Default plural form */\n other: ReactNode\n /** Offset from value before selecting form */\n offset?: number\n}\n\n/**\n * `<Plural>` — ICU plural handling as a component.\n *\n * @example\n * ```tsx\n * <Plural value={count} zero=\"No messages\" one=\"# message\" other=\"# messages\" />\n * ```\n */\nexport const Plural = memo(function Plural({\n value,\n id,\n context,\n comment,\n zero,\n one,\n two,\n few,\n many,\n other,\n offset,\n}: FluentiPluralProps) {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error('[fluenti] <Plural> must be used within an <I18nProvider>')\n }\n\n const forms: Record<PluralCategory, ReactNode | undefined> = {\n zero,\n one,\n two,\n few,\n many,\n other,\n }\n const { messages, components } = serializeRichForms(PLURAL_CATEGORIES, forms)\n const icuMessage = buildICUPluralMessage(\n {\n ...(messages.zero !== undefined && { zero: messages.zero }),\n ...(messages.one !== undefined && { one: messages.one }),\n ...(messages.two !== undefined && { two: messages.two }),\n ...(messages.few !== undefined && { few: messages.few }),\n ...(messages.many !== undefined && { many: messages.many }),\n other: messages.other ?? '',\n },\n offset,\n )\n\n const descriptor = {\n id: id ?? (context === undefined ? icuMessage : hashMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n }\n\n return <>{renderRichTranslation(descriptor, { count: value }, (desc, values) => ctx.t(desc, values), components)}</>\n})\n","import { createElement, memo, useContext, type ReactNode } from 'react'\nimport { hashMessage } from '@fluenti/core/internal'\nimport { I18nContext } from '../context'\nimport { buildICUSelectMessage, normalizeSelectForms, renderRichTranslation, serializeRichForms } from './icu-rich'\n\nexport interface FluentiSelectProps {\n /** The selector value */\n value: string\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Default case */\n other: ReactNode\n /** Type-safe named options. Takes precedence over direct case props. */\n options?: Record<string, ReactNode>\n /** Wrapper element tag name (e.g. 'span', 'div'). Defaults to Fragment (no wrapper). */\n tag?: keyof React.JSX.IntrinsicElements\n /** Named cases — any string key maps to a ReactNode */\n [key: string]: ReactNode | Record<string, ReactNode> | keyof React.JSX.IntrinsicElements | undefined\n}\n\n/**\n * `<Select>` — ICU select for gender, role, or other categorical values.\n *\n * @example\n * ```tsx\n * <Select\n * value={gender}\n * male=\"He liked your post\"\n * female=\"She liked your post\"\n * other=\"They liked your post\"\n * />\n * ```\n */\nexport const Select = memo(function Select(props: FluentiSelectProps) {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error('[fluenti] <Select> must be used within an <I18nProvider>')\n }\n\n const { value, id, context, comment, other, options, tag, ...cases } = props\n const forms: Record<string, ReactNode | undefined> = options === undefined\n ? {\n ...Object.fromEntries(\n Object.entries(cases).filter(([key]) => !['value', 'id', 'context', 'comment', 'options', 'other', 'tag'].includes(key)),\n ),\n other,\n }\n : {\n ...options,\n other,\n }\n\n const orderedKeys = [...Object.keys(forms).filter(key => key !== 'other'), 'other'] as const\n const { messages, components } = serializeRichForms(orderedKeys, forms)\n const normalized = normalizeSelectForms(\n Object.fromEntries(\n [...orderedKeys].map((key) => [key, messages[key] ?? '']),\n ),\n )\n const icuMessage = buildICUSelectMessage(normalized.forms)\n\n const descriptor = {\n id: id ?? (context === undefined ? icuMessage : hashMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n }\n\n const result = renderRichTranslation(\n descriptor,\n { value: normalized.valueMap[value] ?? 'other' },\n (desc, values) => ctx.t(desc, values),\n components,\n )\n return tag ? createElement(tag, null, result) : <>{result}</>\n})\n","import { memo, useContext } from 'react'\nimport { I18nContext } from '../context'\n\nexport interface FluentiDateTimeProps {\n /** Date value to format */\n value: Date | number\n /** Named format style */\n style?: string\n}\n\n/**\n * `<DateTime>` — formatting component using Intl APIs.\n *\n * @example\n * ```tsx\n * <DateTime value={new Date()} style=\"long\" />\n * ```\n */\nexport const DateTime = memo(function DateTime({ value, style }: FluentiDateTimeProps) {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error('[fluenti] <DateTime> must be used within an <I18nProvider>')\n }\n return <>{ctx.d(value, style)}</>\n})\n","import { memo, useContext } from 'react'\nimport { I18nContext } from '../context'\n\nexport interface NumberFormatProps {\n /** Number value to format */\n value: number\n /** Named format style */\n style?: string\n}\n\n/** @alias NumberFormatProps */\nexport type FluentiNumberFormatProps = NumberFormatProps\n\n/**\n * `<Number>` — number formatting component using Intl APIs.\n *\n * @example\n * ```tsx\n * <Number value={1234.56} style=\"currency\" />\n * ```\n */\nexport const NumberFormat = memo(function NumberFormat({ value, style }: NumberFormatProps) {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error('[fluenti] <Number> must be used within an <I18nProvider>')\n }\n return <>{ctx.n(value, style)}</>\n})\n"],"mappings":";;;;;;;AA4EA,SAAS,EAAe,GAAgE;CACtF,IAAM,IAAmC,EAAE;AAC3C,MAAK,IAAM,CAAC,GAAQ,MAAS,OAAO,QAAQ,EAAY,CACtD,GAAO,KAAU,OA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3,"file":"index.js","names":[],"sources":["../src/create-fluenti.ts","../src/global-registry.ts","../src/provider.tsx","../src/hooks/useI18n.ts","../src/compile-time-t.ts"],"sourcesContent":["import { useState, useCallback, useEffect, useMemo, useRef } from 'react'\nimport { createFluentiCore } from '@fluenti/core'\nimport type {\n FluentiCoreInstanceFull as FluentInstanceExtended,\n CompiledMessage,\n Locale,\n Messages,\n AllMessages,\n DateFormatOptions,\n NumberFormatOptions,\n LocalizedString,\n MessageDescriptor,\n} from '@fluenti/core'\n\n/**\n * Configuration for `createFluenti()`.\n */\nexport interface FluentiConfig {\n /** Active locale code */\n locale: string\n /** Static message catalogs keyed by locale */\n messages?: AllMessages | undefined\n /** Async loader for lazy-loading locale messages */\n loadMessages?: ((locale: string) => Promise<Messages | { default: Messages }>) | undefined\n /** Fallback locale when a translation is missing */\n fallbackLocale?: string | undefined\n /** Custom fallback chains per locale */\n fallbackChain?: Record<string, string[]> | undefined\n /** Date format styles */\n dateFormats?: DateFormatOptions | undefined\n /** Number format styles */\n numberFormats?: NumberFormatOptions | undefined\n /** Missing message handler */\n missing?: ((locale: Locale, id: string) => string | undefined) | undefined\n /** Runtime diagnostics (pre-created instance or config) */\n diagnostics?: unknown | undefined\n /** Custom interpolation function for full ICU support at runtime */\n interpolate?: ((message: string, values: Record<string, unknown> | undefined, locale: string, formatters?: Record<string, unknown>) => string) | undefined\n}\n\n/**\n * The object returned by `createFluenti()`.\n *\n * Contains all i18n state and methods. Pass to `<I18nProvider instance={...}>`\n * or use directly in tests/non-React contexts.\n */\nexport interface FluentiInstance {\n /** Translate a message by id with optional interpolation values */\n t: {\n (id: string | MessageDescriptor, values?: Record<string, unknown>): LocalizedString\n (strings: TemplateStringsArray, ...exprs: unknown[]): LocalizedString\n }\n /** Format a date value for the current locale */\n d: (value: Date | number, style?: string) => LocalizedString\n /** Format a number value for the current locale */\n n: (value: number, style?: string) => LocalizedString\n /** Current locale */\n locale: string\n /** Change the active locale (async when lazy loading) */\n setLocale: (locale: string) => Promise<void>\n /** Whether a locale is currently being loaded */\n isLoading: boolean\n /** Preload a locale in the background without switching to it */\n preloadLocale: (locale: string) => Promise<void>\n /** Check whether a translation key exists for the given or current locale */\n te: (key: string, locale?: string) => boolean\n /** Get the raw compiled message for a key without interpolation */\n tm: (key: string, locale?: string) => CompiledMessage | undefined\n /** The underlying Fluent instance (escape hatch for advanced use) */\n i18n: FluentInstanceExtended\n /** Format an ICU message string directly (no catalog lookup) */\n format: (message: string, values?: Record<string, unknown>) => LocalizedString\n /** Merge additional messages into a locale catalog at runtime */\n loadMessages: (locale: string, messages: Messages) => void\n /** Return all locale codes that have loaded messages */\n getLocales: () => string[]\n /** Set of locales whose messages have been loaded */\n loadedLocales: string[]\n}\n\nfunction unwrapMessages(allMessages: Record<string, unknown>): Record<string, Messages> {\n const result: Record<string, Messages> = {}\n for (const [locale, msgs] of Object.entries(allMessages)) {\n result[locale] = typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : msgs as Messages\n }\n return result\n}\n\n/**\n * Create a standalone Fluenti i18n instance.\n *\n * This is a React hook that manages locale state, message loading, and\n * provides all i18n methods. The returned instance can be passed to\n * `<I18nProvider instance={...}>` to share it with the component tree.\n *\n * @example\n * ```tsx\n * function App() {\n * const i18n = createFluenti({\n * locale: 'en',\n * messages: { en: enMessages, fr: frMessages },\n * })\n * return (\n * <I18nProvider instance={i18n}>\n * <MyApp />\n * </I18nProvider>\n * )\n * }\n * ```\n */\nexport function createFluenti(config: FluentiConfig): FluentiInstance {\n const {\n locale: initialLocale,\n messages: initialMessages,\n loadMessages: loadMessagesFn,\n fallbackLocale,\n fallbackChain,\n dateFormats,\n numberFormats,\n missing,\n diagnostics,\n interpolate,\n } = config\n\n const [currentLocale, setCurrentLocale] = useState(initialLocale)\n const [isLoading, setIsLoading] = useState(false)\n const [loadedMessages, setLoadedMessages] = useState<Record<string, Messages>>(\n initialMessages ? unwrapMessages(initialMessages) : {},\n )\n const [loadedLocales, setLoadedLocales] = useState<string[]>(\n initialMessages ? Object.keys(initialMessages) : [],\n )\n\n const loadedMessagesRef = useRef(loadedMessages)\n loadedMessagesRef.current = loadedMessages\n\n const localeRequestRef = useRef(0)\n\n // Split runtime integration (for Vite plugin code splitting)\n const SPLIT_RUNTIME_KEY = Symbol.for('fluenti.runtime.react.v1')\n function getSplitRuntime(): { __switchLocale?: (l: string) => Promise<void>; __preloadLocale?: (l: string) => Promise<void> } | null {\n const rt = (globalThis as Record<PropertyKey, unknown>)[SPLIT_RUNTIME_KEY]\n return typeof rt === 'object' && rt !== null ? rt as any : null\n }\n\n const i18n = useMemo(() => {\n const cfg: Parameters<typeof createFluentiCore>[0] = {\n locale: currentLocale,\n messages: loadedMessages,\n }\n if (fallbackLocale !== undefined) cfg.fallbackLocale = fallbackLocale\n if (fallbackChain !== undefined) cfg.fallbackChain = fallbackChain\n if (dateFormats !== undefined) cfg.dateFormats = dateFormats\n if (numberFormats !== undefined) cfg.numberFormats = numberFormats\n if (missing !== undefined) cfg.missing = missing\n if (diagnostics !== undefined) cfg.diagnostics = diagnostics as Parameters<typeof createFluentiCore>[0]['diagnostics']\n if (interpolate !== undefined) cfg.interpolate = interpolate\n return createFluentiCore(cfg)\n }, [currentLocale, loadedMessages, fallbackLocale, fallbackChain, dateFormats, numberFormats, missing, diagnostics, interpolate])\n\n // Sync external locale changes\n useEffect(() => {\n if (initialLocale !== currentLocale) {\n void handleSetLocale(initialLocale)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [initialLocale])\n\n const handleSetLocale = useCallback(\n async (newLocale: string) => {\n const requestId = ++localeRequestRef.current\n\n const splitRuntime = loadMessagesFn ? getSplitRuntime() : null\n\n if (loadedMessagesRef.current[newLocale] && !loadMessagesFn) {\n setCurrentLocale(newLocale)\n return\n }\n\n if (loadedMessagesRef.current[newLocale]) {\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n setCurrentLocale(newLocale)\n return\n }\n\n if (!loadMessagesFn) {\n console.warn(\n `[fluenti] No messages for locale \"${newLocale}\" and no loadMessages function provided`,\n )\n return\n }\n\n setIsLoading(true)\n try {\n const msgs = await loadMessagesFn(newLocale)\n if (requestId !== localeRequestRef.current) return\n\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n if (splitRuntime?.__switchLocale) {\n await splitRuntime.__switchLocale(newLocale)\n }\n if (requestId !== localeRequestRef.current) return\n setLoadedMessages((prev) => ({ ...prev, [newLocale]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, newLocale])])\n setCurrentLocale(newLocale)\n } catch (err) {\n if (requestId === localeRequestRef.current) {\n console.error(`[fluenti] Failed to load locale \"${newLocale}\"`, err)\n }\n } finally {\n if (requestId === localeRequestRef.current) {\n setIsLoading(false)\n }\n }\n },\n [loadMessagesFn],\n )\n\n const preloadLocale = useCallback(\n async (loc: string) => {\n if (loadedMessagesRef.current[loc] || !loadMessagesFn) return\n try {\n const msgs = await loadMessagesFn(loc)\n const resolved: Messages =\n typeof msgs === 'object' && msgs !== null && 'default' in msgs\n ? (msgs as { default: Messages }).default\n : (msgs as Messages)\n setLoadedMessages((prev) => ({ ...prev, [loc]: resolved }))\n setLoadedLocales((prev) => [...new Set([...prev, loc])])\n const splitRuntime = getSplitRuntime()\n if (splitRuntime?.__preloadLocale) {\n await splitRuntime.__preloadLocale(loc)\n }\n } catch {\n // Silent fail for preload\n }\n },\n [loadMessagesFn],\n )\n\n const te = useCallback(\n (key: string, loc?: string): boolean => {\n const msgs = loadedMessages[loc ?? currentLocale]\n return msgs !== undefined && key in msgs\n },\n [loadedMessages, currentLocale],\n )\n\n const tm = useCallback(\n (key: string, loc?: string): Messages[string] | undefined => {\n const msgs = loadedMessages[loc ?? currentLocale]\n if (!msgs) return undefined\n return msgs[key]\n },\n [loadedMessages, currentLocale],\n )\n\n return useMemo(\n () => ({\n t: i18n.t.bind(i18n),\n d: i18n.d.bind(i18n),\n n: i18n.n.bind(i18n),\n locale: currentLocale,\n setLocale: handleSetLocale,\n isLoading,\n preloadLocale,\n te,\n tm,\n i18n,\n format: i18n.format.bind(i18n),\n loadMessages: i18n.loadMessages.bind(i18n),\n getLocales: i18n.getLocales.bind(i18n),\n loadedLocales,\n }),\n [i18n, currentLocale, handleSetLocale, isLoading, preloadLocale, te, tm, loadedLocales],\n )\n}\n","import type { FluentiCoreInstanceFull } from '@fluenti/core'\n\n/**\n * Global i18n instance registry.\n *\n * Used by `@fluenti/next` webpack loader and `@fluenti/vite-plugin` to access\n * the i18n instance from module-level code via a Proxy. The instance is set by\n * `<I18nProvider>` on mount.\n */\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __fluenti_i18n: FluentiCoreInstanceFull | undefined\n}\n\n/** Get the global i18n instance (set by `<I18nProvider>`). */\nexport function getGlobalI18n(): FluentiCoreInstanceFull | undefined {\n return globalThis.__fluenti_i18n\n}\n\n/** Set the global i18n instance. Called by `<I18nProvider>` on mount. */\nexport function setGlobalI18n(instance: FluentiCoreInstanceFull): void {\n globalThis.__fluenti_i18n = instance\n}\n\n/** Clear the global i18n instance. Primarily for testing. */\nexport function clearGlobalI18n(): void {\n globalThis.__fluenti_i18n = undefined\n}\n","import { useEffect, useMemo } from 'react'\nimport { I18nContext } from './context'\nimport type { FluentiProviderProps, FluentiContext } from './types'\nimport type { FluentiInstance } from './create-fluenti'\nimport { createFluenti } from './create-fluenti'\nimport { setGlobalI18n } from './global-registry'\n\n/**\n * Internal provider that uses a pre-created `FluentiInstance`.\n */\nfunction InstanceProvider({ instance, children }: { instance: FluentiInstance; children: React.ReactNode }) {\n const ctx: FluentiContext = useMemo(\n () => ({\n t: instance.t,\n d: instance.d,\n n: instance.n,\n format: instance.format,\n loadMessages: instance.loadMessages,\n getLocales: instance.getLocales,\n locale: instance.locale,\n setLocale: instance.setLocale,\n isLoading: instance.isLoading,\n loadedLocales: instance.loadedLocales,\n preloadLocale: instance.preloadLocale,\n te: instance.te,\n tm: instance.tm,\n // Internal: used by __useI18n hook and compiled components — not part of public API\n i18n: instance.i18n,\n }) as FluentiContext,\n [instance],\n )\n\n return <I18nContext.Provider value={ctx}>{children}</I18nContext.Provider>\n}\n\n/**\n * Provides the Fluenti i18n context to the React component tree.\n *\n * Accepts either a `locale` + `messages` pair for inline configuration,\n * or a pre-created `instance` from `createFluenti()`.\n *\n * @example\n * ```tsx\n * import { I18nProvider, useI18n } from '@fluenti/react'\n * import messages from './locales/compiled/en.js'\n *\n * function App() {\n * return (\n * <I18nProvider locale=\"en\" messages={{ en: messages }}>\n * <Content />\n * </I18nProvider>\n * )\n * }\n *\n * function Content() {\n * const { t } = useI18n()\n * return <h1>{t`Welcome to our app`}</h1>\n * }\n * ```\n *\n * @example Using a pre-created instance\n * ```tsx\n * import { I18nProvider, createFluenti } from '@fluenti/react'\n * import messages from './locales/compiled/en.js'\n *\n * const i18n = createFluenti({ locale: 'en', messages: { en: messages } })\n *\n * function App() {\n * return (\n * <I18nProvider instance={i18n}>\n * <Content />\n * </I18nProvider>\n * )\n * }\n * ```\n */\nexport function I18nProvider(props: FluentiProviderProps) {\n if (props.instance) {\n return <InstanceProvider instance={props.instance}>{props.children}</InstanceProvider>\n }\n\n return <InlineProvider {...props} />\n}\n\n/**\n * Inline provider that delegates to `createFluenti()` for state management.\n */\nfunction InlineProvider({\n locale,\n fallbackLocale,\n messages,\n loadMessages,\n fallbackChain,\n dateFormats,\n numberFormats,\n missing,\n diagnostics,\n interpolate,\n children,\n}: FluentiProviderProps) {\n const instance = createFluenti({\n locale: locale ?? 'en',\n messages,\n loadMessages,\n fallbackLocale,\n fallbackChain,\n dateFormats,\n numberFormats,\n missing,\n diagnostics,\n interpolate,\n })\n\n // Set global i18n instance for webpack loader / vite plugin access\n useEffect(() => {\n setGlobalI18n(instance.i18n)\n }, [instance.i18n])\n\n return <InstanceProvider instance={instance}>{children}</InstanceProvider>\n}\n","import { useContext } from 'react'\nimport { I18nContext } from '../context'\nimport type { FluentiContext } from '../types'\n\n/**\n * Primary hook for accessing i18n functions.\n *\n * Returns locale, setLocale, isLoading, loadedLocales, preloadLocale,\n * and the underlying i18n instance with t(), d(), n() methods.\n *\n * @throws If used outside of `<I18nProvider>`\n */\nexport function useI18n(): FluentiContext {\n const ctx = useContext(I18nContext)\n if (!ctx) {\n throw new Error(\n '[fluenti] useI18n() must be used within an <I18nProvider>. ' +\n 'Wrap your app with <I18nProvider> to provide i18n context.',\n )\n }\n return ctx\n}\n","import type { CompileTimeT } from '@fluenti/core'\n\nexport const t: CompileTimeT = ((..._args: unknown[]) => {\n throw new Error(\n \"[fluenti] `t` imported from '@fluenti/react' is a compile-time API. \" +\n 'Use it only with the Fluenti build transform inside a component or custom hook. ' +\n 'For runtime lookups, use useI18n().t(...).',\n )\n}) as CompileTimeT\n"],"mappings":";;;;;;AAgFA,SAAS,EAAe,GAAgE;CACtF,IAAM,IAAmC,EAAE;AAC3C,MAAK,IAAM,CAAC,GAAQ,MAAS,OAAO,QAAQ,EAAY,CACtD,GAAO,KAAU,OAAO,KAAS,YAAY,KAAiB,aAAa,IACtE,EAA+B,UAChC;AAEN,QAAO;;AAyBT,SAAgB,EAAc,GAAwC;CACpE,IAAM,EACJ,QAAQ,GACR,UAAU,GACV,cAAc,GACd,mBACA,kBACA,gBACA,kBACA,YACA,gBACA,mBACE,GAEE,CAAC,GAAe,KAAoB,EAAS,EAAc,EAC3D,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAgB,KAAqB,EAC1C,IAAkB,EAAe,EAAgB,GAAG,EAAE,CACvD,EACK,CAAC,GAAe,KAAoB,EACxC,IAAkB,OAAO,KAAK,EAAgB,GAAG,EAAE,CACpD,EAEK,IAAoB,EAAO,EAAe;AAChD,GAAkB,UAAU;CAE5B,IAAM,IAAmB,EAAO,EAAE,EAG5B,IAAoB,OAAO,IAAI,2BAA2B;CAChE,SAAS,IAA4H;EACnI,IAAM,IAAM,WAA4C;AACxD,SAA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fluenti i18n context to the React component tree.
4
+ *
5
+ * Accepts either a `locale` + `messages` pair for inline configuration,
6
+ * or a pre-created `instance` from `createFluenti()`.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { I18nProvider, useI18n } from '@fluenti/react'
11
+ * import messages from './locales/compiled/en.js'
12
+ *
13
+ * function App() {
14
+ * return (
15
+ * <I18nProvider locale="en" messages={{ en: messages }}>
16
+ * <Content />
17
+ * </I18nProvider>
18
+ * )
19
+ * }
20
+ *
21
+ * function Content() {
22
+ * const { t } = useI18n()
23
+ * return <h1>{t`Welcome to our app`}</h1>
24
+ * }
25
+ * ```
26
+ *
27
+ * @example Using a pre-created instance
28
+ * ```tsx
29
+ * import { I18nProvider, createFluenti } from '@fluenti/react'
30
+ * import messages from './locales/compiled/en.js'
31
+ *
32
+ * const i18n = createFluenti({ locale: 'en', messages: { en: messages } })
33
+ *
34
+ * function App() {
35
+ * return (
36
+ * <I18nProvider instance={i18n}>
37
+ * <Content />
38
+ * </I18nProvider>
39
+ * )
40
+ * }
41
+ * ```
42
+ */
2
43
  export declare function I18nProvider(props: FluentiProviderProps): import("react/jsx-runtime").JSX.Element;
3
44
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAkB,MAAM,SAAS,CAAA;AAwDnE,wBAAgB,YAAY,CAAC,KAAK,EAAE,oBAAoB,2CAMvD"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAkB,MAAM,SAAS,CAAA;AAiCnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,oBAAoB,2CAMvD"}
package/dist/server.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./icu-rich-vPU-0wGQ.cjs`);let t=require(`react`),n=require(`@fluenti/core`),r=require(`@fluenti/core/internal`);function i(i){let a=(0,t.cache)(()=>({locale:null,instance:null})),o=(0,t.cache)(()=>new Map),s=null,c=0,l=0;function u(e){a().locale=e,c++,s=null}async function d(e){let t=o(),n=t.get(e);if(n)return n;let r=await i.loadMessages(e),a=typeof r==`object`&&r&&`default`in r?r.default:r;return t.set(e,a),a}async function f(){let e=a();!e.locale&&i.resolveLocale&&(e.locale=await i.resolveLocale());let t=e.locale;if(!t)throw Error(`[fluenti] No locale set. Call setLocale(locale) in your layout before using getI18n(), or provide a resolveLocale function in createServerI18n config to auto-detect locale in Server Actions and other contexts where the layout does not run.`);if(e.instance&&e.instance.locale===t)return e.instance;let r={};r[t]=await d(t),i.fallbackLocale&&i.fallbackLocale!==t&&(r[i.fallbackLocale]=await d(i.fallbackLocale));let o={locale:t,messages:r};return i.fallbackLocale!==void 0&&(o.fallbackLocale=i.fallbackLocale),i.fallbackChain!==void 0&&(o.fallbackChain=i.fallbackChain),i.dateFormats!==void 0&&(o.dateFormats=i.dateFormats),i.numberFormats!==void 0&&(o.numberFormats=i.numberFormats),i.missing!==void 0&&(o.missing=i.missing),e.instance=(0,n.createFluentiCore)(o),s=e.instance,l=c,e.instance}async function p({children:n,id:i,context:a,comment:o,render:s}){let c=await f(),{message:l,components:u}=e.r(n),d=i??(0,r.hashMessage)(l,a),p=e.i(c.t({id:d,message:l,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}}),u);return(0,t.createElement)(t.Fragment,null,s?s(p):p)}async function m({value:n,id:i,context:a,comment:o,zero:s,one:c,two:l,few:u,many:d,other:p,offset:m}){let h=await f(),{messages:g,components:_}=e.n(r.PLURAL_CATEGORIES,{zero:s,one:c,two:l,few:u,many:d,other:p}),v=(0,r.buildICUPluralMessage)({...g.zero!==void 0&&{zero:g.zero},...g.one!==void 0&&{one:g.one},...g.two!==void 0&&{two:g.two},...g.few!==void 0&&{few:g.few},...g.many!==void 0&&{many:g.many},other:g.other??``},m);return(0,t.createElement)(t.Fragment,null,e.t({id:i??(a===void 0?v:(0,r.hashMessage)(v,a)),message:v,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}},{count:n},(e,t)=>h.t(e,t),_))}async function h({value:n,id:i,context:a,comment:o,other:s,options:c,...l}){let u=await f(),d=c===void 0?{...Object.fromEntries(Object.entries(l).filter(([e])=>![`value`,`id`,`context`,`comment`,`options`,`other`].includes(e))),other:s}:{...c,other:s},p=[...Object.keys(d).filter(e=>e!==`other`),`other`],{messages:m,components:h}=e.n(p,d),g=(0,r.normalizeSelectForms)(Object.fromEntries([...p].map(e=>[e,m[e]??``]))),_=(0,r.buildICUSelectMessage)(g.forms);return(0,t.createElement)(t.Fragment,null,e.t({id:i??(a===void 0?_:(0,r.hashMessage)(_,a)),message:_,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}},{value:g.valueMap[n]??`other`},(e,t)=>u.t(e,t),h))}async function g({value:e,style:n}){return(0,t.createElement)(t.Fragment,null,(await f()).d(e,n))}async function _({value:e,style:n}){return(0,t.createElement)(t.Fragment,null,(await f()).n(e,n))}function v(){let e=a();if(e.instance)return e.instance;if(s&&l===c)return s;let t=e.locale??i.fallbackLocale??`en`,r=o(),u={},d=r.get(t);if(d&&(u[t]=d),i.fallbackLocale&&i.fallbackLocale!==t){let e=r.get(i.fallbackLocale);e&&(u[i.fallbackLocale]=e)}let f={locale:t,messages:u};return i.fallbackLocale!==void 0&&(f.fallbackLocale=i.fallbackLocale),i.fallbackChain!==void 0&&(f.fallbackChain=i.fallbackChain),i.dateFormats!==void 0&&(f.dateFormats=i.dateFormats),i.numberFormats!==void 0&&(f.numberFormats=i.numberFormats),i.missing!==void 0&&(f.missing=i.missing),e.instance=(0,n.createFluentiCore)(f),e.instance}async function y(e,t){let n=await f();return(await d(t??n.locale))[e]!==void 0}async function b(e,t){let n=await f();return(await d(t??n.locale))[e]}return{setLocale:u,getI18n:f,__getSyncInstance:v,te:y,tm:b,Trans:p,Plural:m,Select:h,DateTime:g,NumberFormat:_}}exports.createServerI18n=i,Object.defineProperty(exports,`detectLocale`,{enumerable:!0,get:function(){return n.detectLocale}}),Object.defineProperty(exports,`getDirection`,{enumerable:!0,get:function(){return n.getDirection}}),Object.defineProperty(exports,`getHydratedLocale`,{enumerable:!0,get:function(){return n.getHydratedLocale}}),Object.defineProperty(exports,`getSSRLocaleScript`,{enumerable:!0,get:function(){return n.getSSRLocaleScript}}),Object.defineProperty(exports,`isRTL`,{enumerable:!0,get:function(){return n.isRTL}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./icu-rich-CotMVC_x.cjs`);let t=require(`react`),n=require(`@fluenti/core`),r=require(`@fluenti/core/internal`),i=require(`@fluenti/core/ssr`);function a(i){let a=(0,t.cache)(()=>({locale:null,instance:null})),o=(0,t.cache)(()=>new Map),s=null,c=0,l=0;function u(e){a().locale=e,c++,s=null}async function d(e){let t=o(),n=t.get(e);if(n)return n;let r=await i.loadMessages(e),a=typeof r==`object`&&r&&`default`in r?r.default:r;return t.set(e,a),a}async function f(){let e=a();!e.locale&&i.resolveLocale&&(e.locale=await i.resolveLocale());let t=e.locale;if(!t)throw Error(`[fluenti] No locale set. Call setLocale(locale) in your layout before using getI18n(), or provide a resolveLocale function in createServerI18n config to auto-detect locale in Server Actions and other contexts where the layout does not run.`);if(e.instance&&e.instance.locale===t)return e.instance;let r={};r[t]=await d(t),i.fallbackLocale&&i.fallbackLocale!==t&&(r[i.fallbackLocale]=await d(i.fallbackLocale));let o={locale:t,messages:r};return i.fallbackLocale!==void 0&&(o.fallbackLocale=i.fallbackLocale),i.fallbackChain!==void 0&&(o.fallbackChain=i.fallbackChain),i.dateFormats!==void 0&&(o.dateFormats=i.dateFormats),i.numberFormats!==void 0&&(o.numberFormats=i.numberFormats),i.missing!==void 0&&(o.missing=i.missing),i.interpolate!==void 0&&(o.interpolate=i.interpolate),e.instance=(0,n.createFluentiCore)(o),s=e.instance,l=c,e.instance}async function p({children:n,id:i,context:a,comment:o,render:s}){let c=await f(),{message:l,components:u}=e.r(n),d=i??(0,r.hashMessage)(l,a),p=e.i(c.t({id:d,message:l,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}}),u);return(0,t.createElement)(t.Fragment,null,s?s(p):p)}async function m({value:n,id:i,context:a,comment:o,zero:s,one:c,two:l,few:u,many:d,other:p,offset:m}){let h=await f(),{messages:g,components:_}=e.n(r.PLURAL_CATEGORIES,{zero:s,one:c,two:l,few:u,many:d,other:p}),v=(0,r.buildICUPluralMessage)({...g.zero!==void 0&&{zero:g.zero},...g.one!==void 0&&{one:g.one},...g.two!==void 0&&{two:g.two},...g.few!==void 0&&{few:g.few},...g.many!==void 0&&{many:g.many},other:g.other??``},m);return(0,t.createElement)(t.Fragment,null,e.t({id:i??(a===void 0?v:(0,r.hashMessage)(v,a)),message:v,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}},{count:n},(e,t)=>h.t(e,t),_))}async function h({value:n,id:i,context:a,comment:o,other:s,options:c,...l}){let u=await f(),d=c===void 0?{...Object.fromEntries(Object.entries(l).filter(([e])=>![`value`,`id`,`context`,`comment`,`options`,`other`].includes(e))),other:s}:{...c,other:s},p=[...Object.keys(d).filter(e=>e!==`other`),`other`],{messages:m,components:h}=e.n(p,d),g=(0,r.normalizeSelectForms)(Object.fromEntries([...p].map(e=>[e,m[e]??``]))),_=(0,r.buildICUSelectMessage)(g.forms);return(0,t.createElement)(t.Fragment,null,e.t({id:i??(a===void 0?_:(0,r.hashMessage)(_,a)),message:_,...a===void 0?{}:{context:a},...o===void 0?{}:{comment:o}},{value:g.valueMap[n]??`other`},(e,t)=>u.t(e,t),h))}async function g({value:e,format:n}){return(0,t.createElement)(t.Fragment,null,(await f()).d(e,n))}async function _({value:e,format:n}){return(0,t.createElement)(t.Fragment,null,(await f()).n(e,n))}function v(){let e=a();if(e.instance)return e.instance;if(s&&l===c)return s;let t=e.locale??i.fallbackLocale??`en`,r=o(),u={},d=r.get(t);if(d&&(u[t]=d),i.fallbackLocale&&i.fallbackLocale!==t){let e=r.get(i.fallbackLocale);e&&(u[i.fallbackLocale]=e)}let f={locale:t,messages:u};return i.fallbackLocale!==void 0&&(f.fallbackLocale=i.fallbackLocale),i.fallbackChain!==void 0&&(f.fallbackChain=i.fallbackChain),i.dateFormats!==void 0&&(f.dateFormats=i.dateFormats),i.numberFormats!==void 0&&(f.numberFormats=i.numberFormats),i.missing!==void 0&&(f.missing=i.missing),i.interpolate!==void 0&&(f.interpolate=i.interpolate),e.instance=(0,n.createFluentiCore)(f),e.instance}async function y(e,t){let n=await f();return(await d(t??n.locale))[e]!==void 0}async function b(e,t){let n=await f();return(await d(t??n.locale))[e]}return{setLocale:u,getI18n:f,__getSyncInstance:v,te:y,tm:b,Trans:p,Plural:m,Select:h,DateTime:g,NumberFormat:_}}exports.createServerI18n=a,Object.defineProperty(exports,`detectLocale`,{enumerable:!0,get:function(){return i.detectLocale}}),Object.defineProperty(exports,`getDirection`,{enumerable:!0,get:function(){return n.getDirection}}),Object.defineProperty(exports,`getHydratedLocale`,{enumerable:!0,get:function(){return i.getHydratedLocale}}),Object.defineProperty(exports,`getSSRLocaleScript`,{enumerable:!0,get:function(){return i.getSSRLocaleScript}}),Object.defineProperty(exports,`isRTL`,{enumerable:!0,get:function(){return n.isRTL}});
2
2
  //# sourceMappingURL=server.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.cjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["import { cache } from 'react'\nimport { createFluentiCore } from '@fluenti/core'\nimport type {\n FluentiCoreInstanceFull,\n FluentiCoreConfigFull,\n Locale,\n Messages,\n DateFormatOptions,\n NumberFormatOptions,\n} from '@fluenti/core'\nimport { hashMessage as hashSyntheticMessage } from '@fluenti/core/internal'\nimport { createElement, Fragment, type ReactNode, type ReactElement } from 'react'\nimport { hashMessage, extractMessage, reconstruct } from './components/trans-core'\nimport { PLURAL_CATEGORIES, type PluralCategory } from './components/plural-core'\nimport { buildICUPluralMessage, buildICUSelectMessage, normalizeSelectForms, renderRichTranslation, serializeRichForms } from './components/icu-rich'\n\n// Re-export SSR utilities from core for convenience\nexport { detectLocale, getSSRLocaleScript, getHydratedLocale, isRTL, getDirection } from '@fluenti/core'\nexport type { DetectLocaleOptions } from '@fluenti/core'\n\n/**\n * Configuration for `createServerI18n`.\n */\nexport interface ServerI18nConfig {\n /** Load messages for a given locale. Called once per locale per request. */\n loadMessages: (locale: string) => Promise<Messages | { default: Messages }>\n /** Fallback locale when a translation is missing */\n fallbackLocale?: string\n /**\n * Auto-resolve locale when `setLocale()` was not called.\n *\n * This is the fallback for contexts where the layout doesn't run — most\n * notably **Server Actions** (`'use server'`), which are independent\n * requests that skip the layout tree entirely.\n *\n * Common patterns:\n * - Read from a cookie (Next.js: `cookies().get('locale')`)\n * - Read from a request header set by middleware\n * - Query the database for the authenticated user's preference\n *\n * If omitted and `setLocale()` was not called, `getI18n()` will throw.\n *\n * @example\n * ```ts\n * resolveLocale: async () => {\n * const { cookies } = await import('next/headers')\n * return (await cookies()).get('locale')?.value ?? 'en'\n * }\n * ```\n */\n resolveLocale?: () => string | Promise<string>\n /** Custom fallback chains per locale */\n fallbackChain?: Record<string, Locale[]>\n /** Custom date format styles */\n dateFormats?: DateFormatOptions\n /** Custom number format styles */\n numberFormats?: NumberFormatOptions\n /** Handler for missing translation keys */\n missing?: (locale: Locale, id: string) => string | undefined\n}\n\n// ─── Server Component Props ──────────────────────────────────────────────────\n\nexport interface ServerTransProps {\n /** Source text with embedded components */\n children: ReactNode\n /** Override auto-generated hash ID */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Context comment for translators */\n comment?: string\n /** Custom render wrapper */\n render?: (translation: ReactNode) => ReactNode\n}\n\nexport interface ServerPluralProps {\n /** The count value */\n value: number\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Text for zero (if language supports) */\n zero?: ReactNode\n /** Singular form. `#` replaced with value */\n one?: ReactNode\n /** Dual form (Arabic, etc.) */\n two?: ReactNode\n /** Few form (Slavic languages, etc.) */\n few?: ReactNode\n /** Many form */\n many?: ReactNode\n /** Default plural form */\n other: ReactNode\n /** Offset from value before selecting form */\n offset?: number\n}\n\nexport interface ServerSelectProps {\n /** The selector value */\n value: string\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Default case */\n other: ReactNode\n /** Type-safe named options. Takes precedence over direct case props. */\n options?: Record<string, ReactNode>\n /** Named cases — any string key maps to a ReactNode */\n [key: string]: ReactNode | Record<string, ReactNode> | string | undefined\n}\n\nexport interface ServerDateTimeProps {\n /** Date value to format */\n value: Date | number\n /** Named format style */\n style?: string\n}\n\nexport interface ServerNumberProps {\n /** Number value to format */\n value: number\n /** Named format style */\n style?: string\n}\n\n// ─── Server Component Types ──────────────────────────────────────────────────\n\ntype ServerTransComponent = (props: ServerTransProps) => Promise<ReactElement>\ntype ServerPluralComponent = (props: ServerPluralProps) => Promise<ReactElement>\ntype ServerSelectComponent = (props: ServerSelectProps) => Promise<ReactElement>\ntype ServerDateTimeComponent = (props: ServerDateTimeProps) => Promise<ReactElement>\ntype ServerNumberComponent = (props: ServerNumberProps) => Promise<ReactElement>\n\n/**\n * The object returned by `createServerI18n`.\n */\nexport interface ServerI18n {\n /**\n * Set the locale for the current server request.\n * Call this once in your root layout or page before any `getI18n()` calls.\n *\n * Uses `React.cache()` — scoped to the current request automatically.\n */\n setLocale: (locale: string) => void\n\n /**\n * Get a fully configured i18n instance for the current request.\n * Messages are loaded lazily and cached per-request.\n *\n * @example\n * ```tsx\n * // In any Server Component\n * const { t, d, n, locale } = await getI18n()\n * return <h1>{t('welcome')}</h1>\n * ```\n */\n getI18n: () => Promise<FluentiCoreInstanceFull & { locale: string }>\n\n /**\n * `<Trans>` for React Server Components.\n * Async component — automatically resolves the i18n instance.\n *\n * @example\n * ```tsx\n * <Trans>Read the <a href=\"/docs\">documentation</a>.</Trans>\n * ```\n */\n Trans: ServerTransComponent\n\n /**\n * `<Plural>` for React Server Components.\n *\n * @example\n * ```tsx\n * <Plural value={count} one=\"# item\" other=\"# items\" />\n * ```\n */\n Plural: ServerPluralComponent\n\n /**\n * `<Select>` for React Server Components.\n *\n * @example\n * ```tsx\n * <Select value={gender} male=\"He liked this\" other=\"They liked this\" />\n * ```\n */\n Select: ServerSelectComponent\n\n /**\n * `<DateTime>` for React Server Components.\n *\n * @example\n * ```tsx\n * <DateTime value={new Date()} style=\"long\" />\n * ```\n */\n DateTime: ServerDateTimeComponent\n\n /**\n * `<NumberFormat>` for React Server Components.\n *\n * @example\n * ```tsx\n * <NumberFormat value={1234.56} style=\"currency\" />\n * ```\n */\n NumberFormat: ServerNumberComponent\n\n /**\n * Check if a translation key exists in the catalog.\n * Optionally check a specific locale instead of the current one.\n */\n te: (key: string, locale?: string) => Promise<boolean>\n\n /**\n * Get the raw compiled message without interpolation.\n * Optionally look up in a specific locale instead of the current one.\n */\n tm: (key: string, locale?: string) => Promise<Messages[string] | undefined>\n\n /**\n * Synchronous accessor for the cached i18n instance.\n * Used internally by @fluenti/next webpack loader.\n * @internal\n */\n __getSyncInstance: () => FluentiCoreInstanceFull & { locale: string }\n}\n\n/**\n * Create server-side i18n utilities for React Server Components.\n *\n * Uses `React.cache()` to share state within a single server request\n * without React Context (which is unavailable in Server Components).\n *\n * @example\n * ```ts\n * // lib/i18n.server.ts — define once\n * import { createServerI18n } from '@fluenti/react/server'\n *\n * export const { setLocale, getI18n, Trans, Plural, Select, DateTime, NumberFormat } = createServerI18n({\n * loadMessages: (locale) => import(`../messages/${locale}.json`),\n * fallbackLocale: 'en',\n * })\n * ```\n *\n * ```tsx\n * // app/[locale]/layout.tsx — set locale once\n * import { setLocale } from '@/lib/i18n.server'\n *\n * export default async function Layout({ params, children }) {\n * const { locale } = await params\n * setLocale(locale)\n * return <html lang={locale}><body>{children}</body></html>\n * }\n * ```\n *\n * ```tsx\n * // app/[locale]/page.tsx — use Trans, Plural, etc. directly\n * import { Trans, Plural, Select } from '@/lib/i18n.server'\n *\n * export default async function Page() {\n * return (\n * <div>\n * <Trans>Read the <a href=\"/docs\">documentation</a>.</Trans>\n * <Plural value={5} one=\"# item\" other=\"# items\" />\n * <Select value=\"male\" male=\"He liked this\" other=\"They liked this\" />\n * </div>\n * )\n * }\n * ```\n */\nexport function createServerI18n(config: ServerI18nConfig): ServerI18n {\n // Request-scoped store using React.cache()\n // Each server request gets its own isolated state\n const getRequestStore = cache((): {\n locale: string | null\n instance: (FluentiCoreInstanceFull & { locale: string }) | null\n } => ({\n locale: null,\n instance: null,\n }))\n\n // Cache loaded messages per-request to avoid redundant imports\n const getMessageCache = cache((): Map<string, Messages> => new Map())\n\n // Module-level fallback for server actions where React.cache()\n // may not share state with the page render.\n let _lastInstance: (FluentiCoreInstanceFull & { locale: string }) | null = null\n let _requestId = 0\n let _lastRequestId = 0\n\n function setLocale(locale: string): void {\n getRequestStore().locale = locale\n _requestId++\n _lastInstance = null\n }\n\n async function loadLocaleMessages(locale: string): Promise<Messages> {\n const messageCache = getMessageCache()\n const cached = messageCache.get(locale)\n if (cached) return cached\n\n const raw = await config.loadMessages(locale)\n const messages: Messages =\n typeof raw === 'object' && raw !== null && 'default' in raw\n ? (raw as { default: Messages }).default\n : (raw as Messages)\n\n messageCache.set(locale, messages)\n return messages\n }\n\n async function getI18n(): Promise<FluentiCoreInstanceFull & { locale: string }> {\n const store = getRequestStore()\n\n // If setLocale() was never called (e.g. Server Action — independent request\n // that skips the layout), try the resolveLocale fallback.\n if (!store.locale && config.resolveLocale) {\n store.locale = await config.resolveLocale()\n }\n\n const locale = store.locale\n\n if (!locale) {\n throw new Error(\n '[fluenti] No locale set. Call setLocale(locale) in your layout before using getI18n(), ' +\n 'or provide a resolveLocale function in createServerI18n config to auto-detect locale ' +\n 'in Server Actions and other contexts where the layout does not run.',\n )\n }\n\n // Return cached instance if locale hasn't changed\n if (store.instance && store.instance.locale === locale) {\n return store.instance\n }\n\n // Load messages for current locale (and fallback if configured)\n const allMessages: Record<string, Messages> = {}\n allMessages[locale] = await loadLocaleMessages(locale)\n\n if (config.fallbackLocale && config.fallbackLocale !== locale) {\n allMessages[config.fallbackLocale] = await loadLocaleMessages(config.fallbackLocale)\n }\n\n const fluentConfig: FluentiCoreConfigFull = {\n locale,\n messages: allMessages,\n }\n if (config.fallbackLocale !== undefined) fluentConfig.fallbackLocale = config.fallbackLocale\n if (config.fallbackChain !== undefined) fluentConfig.fallbackChain = config.fallbackChain\n if (config.dateFormats !== undefined) fluentConfig.dateFormats = config.dateFormats\n if (config.numberFormats !== undefined) fluentConfig.numberFormats = config.numberFormats\n if (config.missing !== undefined) fluentConfig.missing = config.missing\n\n store.instance = createFluentiCore(fluentConfig)\n _lastInstance = store.instance\n _lastRequestId = _requestId\n return store.instance\n }\n\n // ─── Async Server Components ─────────────────────────────────────────────\n\n async function Trans({ children, id, context, comment, render }: ServerTransProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const { message, components } = extractMessage(children)\n const messageId = id ?? hashMessage(message, context)\n const translated = i18n.t({\n id: messageId,\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n })\n const result = reconstruct(translated, components)\n return createElement(Fragment, null, render ? render(result) : result)\n }\n\n async function Plural({\n value,\n id,\n context,\n comment,\n zero,\n one,\n two,\n few,\n many,\n other,\n offset,\n }: ServerPluralProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const forms: Record<PluralCategory, ReactNode | undefined> = {\n zero,\n one,\n two,\n few,\n many,\n other,\n }\n const { messages, components } = serializeRichForms(PLURAL_CATEGORIES, forms)\n const icuMessage = buildICUPluralMessage(\n {\n ...(messages.zero !== undefined && { zero: messages.zero }),\n ...(messages.one !== undefined && { one: messages.one }),\n ...(messages.two !== undefined && { two: messages.two }),\n ...(messages.few !== undefined && { few: messages.few }),\n ...(messages.many !== undefined && { many: messages.many }),\n other: messages.other ?? '',\n },\n offset,\n )\n\n const result = renderRichTranslation(\n {\n id: id ?? (context === undefined ? icuMessage : hashSyntheticMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n { count: value },\n (descriptor, values) => i18n.t(descriptor, values),\n components,\n )\n\n return createElement(Fragment, null, result)\n }\n\n async function Select({\n value,\n id,\n context,\n comment,\n other,\n options,\n ...cases\n }: ServerSelectProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const forms: Record<string, ReactNode | undefined> = options === undefined\n ? {\n ...Object.fromEntries(\n Object.entries(cases).filter(([key]) => !['value', 'id', 'context', 'comment', 'options', 'other'].includes(key)),\n ),\n other,\n }\n : {\n ...options,\n other,\n }\n\n const orderedKeys = [...Object.keys(forms).filter(key => key !== 'other'), 'other'] as const\n const { messages, components } = serializeRichForms(orderedKeys, forms)\n const normalized = normalizeSelectForms(\n Object.fromEntries(\n [...orderedKeys].map((key) => [key, messages[key] ?? '']),\n ),\n )\n const icuMessage = buildICUSelectMessage(normalized.forms)\n\n const result = renderRichTranslation(\n {\n id: id ?? (context === undefined ? icuMessage : hashSyntheticMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n { value: normalized.valueMap[value] ?? 'other' },\n (descriptor, values) => i18n.t(descriptor, values),\n components,\n )\n\n return createElement(Fragment, null, result)\n }\n\n async function DateTime({ value, style }: ServerDateTimeProps): Promise<ReactElement> {\n const i18n = await getI18n()\n return createElement(Fragment, null, i18n.d(value, style))\n }\n\n async function NumberFormat({ value, style }: ServerNumberProps): Promise<ReactElement> {\n const i18n = await getI18n()\n return createElement(Fragment, null, i18n.n(value, style))\n }\n\n /**\n * Synchronous accessor for the cached i18n instance.\n * Used by @fluenti/next webpack loader for t`` in RSC.\n * Throws if getI18n() hasn't been called yet in this request.\n * @internal\n */\n function __getSyncInstance(): FluentiCoreInstanceFull & { locale: string } {\n const store = getRequestStore()\n if (store.instance) {\n return store.instance\n }\n\n // Module-level fallback for server actions where React.cache()\n // may not share state across different call contexts.\n // Only use within the same request (tracked by _requestId).\n if (_lastInstance && _lastRequestId === _requestId) {\n return _lastInstance\n }\n\n // Final fallback: create instance synchronously with the default locale.\n // This handles Suspense boundaries and streamed components where\n // the React.cache store may not have been populated yet.\n const locale = store.locale ?? config.fallbackLocale ?? 'en'\n const messageCache = getMessageCache()\n const messages: Record<string, Messages> = {}\n const cached = messageCache.get(locale)\n if (cached) messages[locale] = cached\n if (config.fallbackLocale && config.fallbackLocale !== locale) {\n const fallback = messageCache.get(config.fallbackLocale)\n if (fallback) messages[config.fallbackLocale] = fallback\n }\n\n const fluentConfig: FluentiCoreConfigFull = { locale, messages }\n if (config.fallbackLocale !== undefined) fluentConfig.fallbackLocale = config.fallbackLocale\n if (config.fallbackChain !== undefined) fluentConfig.fallbackChain = config.fallbackChain\n if (config.dateFormats !== undefined) fluentConfig.dateFormats = config.dateFormats\n if (config.numberFormats !== undefined) fluentConfig.numberFormats = config.numberFormats\n if (config.missing !== undefined) fluentConfig.missing = config.missing\n\n store.instance = createFluentiCore(fluentConfig)\n return store.instance\n }\n\n /**\n * Check if a translation key exists in the catalog for the given (or current) locale.\n * Async because it needs to ensure messages are loaded via getI18n().\n */\n async function te(key: string, locale?: string): Promise<boolean> {\n const i18n = await getI18n()\n const targetLocale = locale ?? i18n.locale\n const msgs = await loadLocaleMessages(targetLocale)\n return msgs[key] !== undefined\n }\n\n /**\n * Get the raw compiled message for the given key without interpolation.\n * Async because it needs to ensure messages are loaded via getI18n().\n */\n async function tm(key: string, locale?: string): Promise<Messages[string] | undefined> {\n const i18n = await getI18n()\n const targetLocale = locale ?? i18n.locale\n const msgs = await loadLocaleMessages(targetL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M,EAAO,MAAM,GAAS,CAG5B,OADa,MAAM,EADE,GAAU,EAAK,OACe,EACvC,GAGd,MAAO,CAAE,YAAW,UAAS,oBAAmB,KAAI,KAAI,QAAO,SAAQ,SAAQ,WAAU,eAAc"}
1
+ {"version":3,"file":"server.cjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["import { cache } from 'react'\nimport { createFluentiCore } from '@fluenti/core'\nimport type {\n FluentiCoreInstanceFull,\n FluentiCoreConfigFull,\n Locale,\n Messages,\n DateFormatOptions,\n NumberFormatOptions,\n} from '@fluenti/core'\nimport { hashMessage as hashSyntheticMessage } from '@fluenti/core/internal'\nimport { createElement, Fragment, type ReactNode, type ReactElement } from 'react'\nimport { hashMessage, extractMessage, reconstruct } from './components/trans-core'\nimport { PLURAL_CATEGORIES, type PluralCategory } from './components/plural-core'\nimport { buildICUPluralMessage, buildICUSelectMessage, normalizeSelectForms, renderRichTranslation, serializeRichForms } from './components/icu-rich'\n\n// Re-export SSR utilities from core for convenience\nexport { detectLocale, getSSRLocaleScript, getHydratedLocale } from '@fluenti/core/ssr'\nexport type { DetectLocaleOptions } from '@fluenti/core/ssr'\nexport { isRTL, getDirection } from '@fluenti/core'\n\n/**\n * Configuration for `createServerI18n`.\n */\nexport interface ServerI18nConfig {\n /** Load messages for a given locale. Called once per locale per request. */\n loadMessages: (locale: string) => Promise<Messages | { default: Messages }>\n /** Fallback locale when a translation is missing */\n fallbackLocale?: string\n /**\n * Auto-resolve locale when `setLocale()` was not called.\n *\n * This is the fallback for contexts where the layout doesn't run — most\n * notably **Server Actions** (`'use server'`), which are independent\n * requests that skip the layout tree entirely.\n *\n * Common patterns:\n * - Read from a cookie (Next.js: `cookies().get('locale')`)\n * - Read from a request header set by middleware\n * - Query the database for the authenticated user's preference\n *\n * If omitted and `setLocale()` was not called, `getI18n()` will throw.\n *\n * @example\n * ```ts\n * resolveLocale: async () => {\n * const { cookies } = await import('next/headers')\n * return (await cookies()).get('locale')?.value ?? 'en'\n * }\n * ```\n */\n resolveLocale?: () => string | Promise<string>\n /** Custom fallback chains per locale */\n fallbackChain?: Record<string, Locale[]>\n /** Custom date format styles */\n dateFormats?: DateFormatOptions\n /** Custom number format styles */\n numberFormats?: NumberFormatOptions\n /** Handler for missing translation keys */\n missing?: (locale: Locale, id: string) => string | undefined\n /**\n * Custom interpolation function for ICU MessageFormat parsing.\n *\n * By default, the runtime uses a lightweight `{key}` replacer.\n * Pass the full `interpolate` from `@fluenti/core` for runtime\n * ICU MessageFormat parsing (plurals, selects, nested arguments).\n *\n * @example\n * ```ts\n * import { interpolate } from '@fluenti/core'\n * createServerI18n({ interpolate, ... })\n * ```\n */\n interpolate?: FluentiCoreConfigFull['interpolate']\n}\n\n// ─── Server Component Props ──────────────────────────────────────────────────\n\nexport interface ServerTransProps {\n /** Source text with embedded components */\n children: ReactNode\n /** Override auto-generated hash ID */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Context comment for translators */\n comment?: string\n /** Custom render wrapper */\n render?: (translation: ReactNode) => ReactNode\n}\n\nexport interface ServerPluralProps {\n /** The count value */\n value: number\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Text for zero (if language supports) */\n zero?: ReactNode\n /** Singular form. `#` replaced with value */\n one?: ReactNode\n /** Dual form (Arabic, etc.) */\n two?: ReactNode\n /** Few form (Slavic languages, etc.) */\n few?: ReactNode\n /** Many form */\n many?: ReactNode\n /** Default plural form */\n other: ReactNode\n /** Offset from value before selecting form */\n offset?: number\n}\n\nexport interface ServerSelectProps {\n /** The selector value */\n value: string\n /** Override the auto-generated synthetic ICU message id */\n id?: string\n /** Message context used for identity and translator disambiguation */\n context?: string\n /** Translator-facing note preserved in extraction catalogs */\n comment?: string\n /** Default case */\n other: ReactNode\n /** Type-safe named options. Takes precedence over direct case props. */\n options?: Record<string, ReactNode>\n /** Named cases — any string key maps to a ReactNode */\n [key: string]: ReactNode | Record<string, ReactNode> | string | undefined\n}\n\nexport interface ServerDateTimeProps {\n /** Date value to format */\n value: Date | number\n /** Named format key defined in dateFormats config */\n format?: string\n}\n\nexport interface ServerNumberProps {\n /** Number value to format */\n value: number\n /** Named format key defined in numberFormats config */\n format?: string\n}\n\n// ─── Server Component Types ──────────────────────────────────────────────────\n\ntype ServerTransComponent = (props: ServerTransProps) => Promise<ReactElement>\ntype ServerPluralComponent = (props: ServerPluralProps) => Promise<ReactElement>\ntype ServerSelectComponent = (props: ServerSelectProps) => Promise<ReactElement>\ntype ServerDateTimeComponent = (props: ServerDateTimeProps) => Promise<ReactElement>\ntype ServerNumberComponent = (props: ServerNumberProps) => Promise<ReactElement>\n\n/**\n * The object returned by `createServerI18n`.\n */\nexport interface ServerI18n {\n /**\n * Set the locale for the current server request.\n * Call this once in your root layout or page before any `getI18n()` calls.\n *\n * Uses `React.cache()` — scoped to the current request automatically.\n */\n setLocale: (locale: string) => void\n\n /**\n * Get a fully configured i18n instance for the current request.\n * Messages are loaded lazily and cached per-request.\n *\n * @example\n * ```tsx\n * // In any Server Component\n * const { t, d, n, locale } = await getI18n()\n * return <h1>{t('welcome')}</h1>\n * ```\n */\n getI18n: () => Promise<FluentiCoreInstanceFull & { locale: string }>\n\n /**\n * `<Trans>` for React Server Components.\n * Async component — automatically resolves the i18n instance.\n *\n * @example\n * ```tsx\n * <Trans>Read the <a href=\"/docs\">documentation</a>.</Trans>\n * ```\n */\n Trans: ServerTransComponent\n\n /**\n * `<Plural>` for React Server Components.\n *\n * @example\n * ```tsx\n * <Plural value={count} one=\"# item\" other=\"# items\" />\n * ```\n */\n Plural: ServerPluralComponent\n\n /**\n * `<Select>` for React Server Components.\n *\n * @example\n * ```tsx\n * <Select value={gender} male=\"He liked this\" other=\"They liked this\" />\n * ```\n */\n Select: ServerSelectComponent\n\n /**\n * `<DateTime>` for React Server Components.\n *\n * @example\n * ```tsx\n * <DateTime value={new Date()} format=\"long\" />\n * ```\n */\n DateTime: ServerDateTimeComponent\n\n /**\n * `<NumberFormat>` for React Server Components.\n *\n * @example\n * ```tsx\n * <NumberFormat value={1234.56} format=\"currency\" />\n * ```\n */\n NumberFormat: ServerNumberComponent\n\n /**\n * Check if a translation key exists in the catalog.\n * Optionally check a specific locale instead of the current one.\n */\n te: (key: string, locale?: string) => Promise<boolean>\n\n /**\n * Get the raw compiled message without interpolation.\n * Optionally look up in a specific locale instead of the current one.\n */\n tm: (key: string, locale?: string) => Promise<Messages[string] | undefined>\n\n /**\n * Synchronous accessor for the cached i18n instance.\n * Used internally by @fluenti/next webpack loader.\n * @internal\n */\n __getSyncInstance: () => FluentiCoreInstanceFull & { locale: string }\n}\n\n/**\n * Create server-side i18n utilities for React Server Components.\n *\n * Uses `React.cache()` to share state within a single server request\n * without React Context (which is unavailable in Server Components).\n *\n * @example\n * ```ts\n * // lib/i18n.server.ts — define once\n * import { createServerI18n } from '@fluenti/react/server'\n *\n * export const { setLocale, getI18n, Trans, Plural, Select, DateTime, NumberFormat } = createServerI18n({\n * loadMessages: (locale) => import(`../messages/${locale}.json`),\n * fallbackLocale: 'en',\n * })\n * ```\n *\n * ```tsx\n * // app/[locale]/layout.tsx — set locale once\n * import { setLocale } from '@/lib/i18n.server'\n *\n * export default async function Layout({ params, children }) {\n * const { locale } = await params\n * setLocale(locale)\n * return <html lang={locale}><body>{children}</body></html>\n * }\n * ```\n *\n * ```tsx\n * // app/[locale]/page.tsx — use Trans, Plural, etc. directly\n * import { Trans, Plural, Select } from '@/lib/i18n.server'\n *\n * export default async function Page() {\n * return (\n * <div>\n * <Trans>Read the <a href=\"/docs\">documentation</a>.</Trans>\n * <Plural value={5} one=\"# item\" other=\"# items\" />\n * <Select value=\"male\" male=\"He liked this\" other=\"They liked this\" />\n * </div>\n * )\n * }\n * ```\n */\nexport function createServerI18n(config: ServerI18nConfig): ServerI18n {\n // Request-scoped store using React.cache()\n // Each server request gets its own isolated state\n const getRequestStore = cache((): {\n locale: string | null\n instance: (FluentiCoreInstanceFull & { locale: string }) | null\n } => ({\n locale: null,\n instance: null,\n }))\n\n // Cache loaded messages per-request to avoid redundant imports\n const getMessageCache = cache((): Map<string, Messages> => new Map())\n\n // Module-level fallback for server actions where React.cache()\n // may not share state with the page render.\n let _lastInstance: (FluentiCoreInstanceFull & { locale: string }) | null = null\n let _requestId = 0\n let _lastRequestId = 0\n\n function setLocale(locale: string): void {\n getRequestStore().locale = locale\n _requestId++\n _lastInstance = null\n }\n\n async function loadLocaleMessages(locale: string): Promise<Messages> {\n const messageCache = getMessageCache()\n const cached = messageCache.get(locale)\n if (cached) return cached\n\n const raw = await config.loadMessages(locale)\n const messages: Messages =\n typeof raw === 'object' && raw !== null && 'default' in raw\n ? (raw as { default: Messages }).default\n : (raw as Messages)\n\n messageCache.set(locale, messages)\n return messages\n }\n\n async function getI18n(): Promise<FluentiCoreInstanceFull & { locale: string }> {\n const store = getRequestStore()\n\n // If setLocale() was never called (e.g. Server Action — independent request\n // that skips the layout), try the resolveLocale fallback.\n if (!store.locale && config.resolveLocale) {\n store.locale = await config.resolveLocale()\n }\n\n const locale = store.locale\n\n if (!locale) {\n throw new Error(\n '[fluenti] No locale set. Call setLocale(locale) in your layout before using getI18n(), ' +\n 'or provide a resolveLocale function in createServerI18n config to auto-detect locale ' +\n 'in Server Actions and other contexts where the layout does not run.',\n )\n }\n\n // Return cached instance if locale hasn't changed\n if (store.instance && store.instance.locale === locale) {\n return store.instance\n }\n\n // Load messages for current locale (and fallback if configured)\n const allMessages: Record<string, Messages> = {}\n allMessages[locale] = await loadLocaleMessages(locale)\n\n if (config.fallbackLocale && config.fallbackLocale !== locale) {\n allMessages[config.fallbackLocale] = await loadLocaleMessages(config.fallbackLocale)\n }\n\n const fluentConfig: FluentiCoreConfigFull = {\n locale,\n messages: allMessages,\n }\n if (config.fallbackLocale !== undefined) fluentConfig.fallbackLocale = config.fallbackLocale\n if (config.fallbackChain !== undefined) fluentConfig.fallbackChain = config.fallbackChain\n if (config.dateFormats !== undefined) fluentConfig.dateFormats = config.dateFormats\n if (config.numberFormats !== undefined) fluentConfig.numberFormats = config.numberFormats\n if (config.missing !== undefined) fluentConfig.missing = config.missing\n if (config.interpolate !== undefined) fluentConfig.interpolate = config.interpolate\n\n store.instance = createFluentiCore(fluentConfig)\n _lastInstance = store.instance\n _lastRequestId = _requestId\n return store.instance\n }\n\n // ─── Async Server Components ─────────────────────────────────────────────\n\n async function Trans({ children, id, context, comment, render }: ServerTransProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const { message, components } = extractMessage(children)\n const messageId = id ?? hashMessage(message, context)\n const translated = i18n.t({\n id: messageId,\n message,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n })\n const result = reconstruct(translated, components)\n return createElement(Fragment, null, render ? render(result) : result)\n }\n\n async function Plural({\n value,\n id,\n context,\n comment,\n zero,\n one,\n two,\n few,\n many,\n other,\n offset,\n }: ServerPluralProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const forms: Record<PluralCategory, ReactNode | undefined> = {\n zero,\n one,\n two,\n few,\n many,\n other,\n }\n const { messages, components } = serializeRichForms(PLURAL_CATEGORIES, forms)\n const icuMessage = buildICUPluralMessage(\n {\n ...(messages.zero !== undefined && { zero: messages.zero }),\n ...(messages.one !== undefined && { one: messages.one }),\n ...(messages.two !== undefined && { two: messages.two }),\n ...(messages.few !== undefined && { few: messages.few }),\n ...(messages.many !== undefined && { many: messages.many }),\n other: messages.other ?? '',\n },\n offset,\n )\n\n const result = renderRichTranslation(\n {\n id: id ?? (context === undefined ? icuMessage : hashSyntheticMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n { count: value },\n (descriptor, values) => i18n.t(descriptor, values),\n components,\n )\n\n return createElement(Fragment, null, result)\n }\n\n async function Select({\n value,\n id,\n context,\n comment,\n other,\n options,\n ...cases\n }: ServerSelectProps): Promise<ReactElement> {\n const i18n = await getI18n()\n const forms: Record<string, ReactNode | undefined> = options === undefined\n ? {\n ...Object.fromEntries(\n Object.entries(cases).filter(([key]) => !['value', 'id', 'context', 'comment', 'options', 'other'].includes(key)),\n ),\n other,\n }\n : {\n ...options,\n other,\n }\n\n const orderedKeys = [...Object.keys(forms).filter(key => key !== 'other'), 'other'] as const\n const { messages, components } = serializeRichForms(orderedKeys, forms)\n const normalized = normalizeSelectForms(\n Object.fromEntries(\n [...orderedKeys].map((key) => [key, messages[key] ?? '']),\n ),\n )\n const icuMessage = buildICUSelectMessage(normalized.forms)\n\n const result = renderRichTranslation(\n {\n id: id ?? (context === undefined ? icuMessage : hashSyntheticMessage(icuMessage, context)),\n message: icuMessage,\n ...(context !== undefined ? { context } : {}),\n ...(comment !== undefined ? { comment } : {}),\n },\n { value: normalized.valueMap[value] ?? 'other' },\n (descriptor, values) => i18n.t(descriptor, values),\n components,\n )\n\n return createElement(Fragment, null, result)\n }\n\n async function DateTime({ value, format }: ServerDateTimeProps): Promise<ReactElement> {\n const i18n = await getI18n()\n return createElement(Fragment, null, i18n.d(value, format))\n }\n\n async function NumberFormat({ value, format }: ServerNumberProps): Promise<ReactElement> {\n const i18n = await getI18n()\n return createElement(Fragment, null, i18n.n(value, format))\n }\n\n /**\n * Synchronous accessor for the cached i18n instance.\n * Used by @fluenti/next webpack loader for t`` in RSC.\n *\n * Falls back to creating a minimal instance from the message cache when the\n * React.cache() request store hasn't been populated yet — this handles\n * Suspense boundaries and streamed components where React.cache() state\n * may not propagate from the layout render into streamed children.\n * @internal\n */\n function __getSyncInstance(): FluentiCoreInstanceFull & { locale: string } {\n const store = getRequestStore()\n if (store.instance) {\n return store.instance\n }\n\n // Module-level fallback for server actions where React.cache()\n // may not share state across different call contexts.\n // Only use within the same request (tracked by _requestId).\n if (_lastInstance && _lastRequestId === _requestId) {\n return _lastInstance\n }\n\n // Final fallback: create instance synchronously with the default locale.\n // This handles Suspense boundaries and streamed components where\n // the React.cache store may not have been populated yet.\n const locale = store.locale ?? config.fallbackLocale ?? 'en'\n const messageCache = getMessageCache()\n const messages: Record<string, Messages> = {}\n const cached = messageCache.get(locale)\n if (cached) messages[locale] = cached\n if (config.fallbackLocale && config.fallbackLocale !== locale) {\n const fallback = messageCache.get(config.fallbackLocale)\n if (fallback) messages[config.fallbackLocale] = fallback\n }\n\n const fluentConfig: FluentiCoreConfigFull = { locale, messages }\n if (config.fallbackLocale !== undefined) fluentConfig.fallbackLocale = config.fallbackLocale\n if (config.fallbackChain !== undefined) fluentConfig.fallbackChain = config.fallbackChain\n if (config.dateFormats !== undefined) fluentConfig.dateFormats = config.dateFormats\n if (config.numberFormats !== undefined) fluentConfig.numberFormats = config.numberFormats\n if (config.missing !== undefined) fluentConfig.missing = config.missing\n if (config.interpolate !== undefined) fluentConfig.interpolate = config.interpolate\n\n store.instance = createFluentiCore(fluentConfig)\n return store.instance\n }\n\n /**\n * Check if a translation key exists in the catalog for the given (or current) locale.\n * Async because it needs to ensure messages are loaded via getI18n().\n */\n async function te(key: string, locale?: string): Promise<boolean> {\n const i18n = await getI18n()\n const targetLocale = locale ?? i18n.locale\n const msgs = await loadLocaleMessages(targetLocale)\n return msgs[key] !== undefined\n }\n\n /**\n * Get the raw compiled message for the given key without interpolation.\n * Async because it needs to ensure messages are loaded via getI18n().\n */\n async function tm(key: string, locale?: string): Promise<Messages[string] | undefined> {\n const i18n = await getI18n()\n const targetLocale = locale ?? i18n.locale\n const msgs = await loadLocaleMessages(targetLocale)\n return msgs[key]\n }\n\n return { setLocale, getI18n, __getSyncInstance, te, tm, Trans, Plural, Select, DateTime, NumberFormat }\n}\n"],"mappings":"mOAsSA,SAAgB,EAAiB,EAAsC,CAGrE,IAAM,GAAA,EAAA,EAAA,YAGA,CACJ,OAAQ,KACR,SAAU,KACX,EAAE,CAGG,GAAA,EAAA,EAAA,WAAqD,IAAI,IAAM,CAIjE,EAAuE,KACvE,EAAa,EACb,EAAiB,EAErB,SAAS,EAAU,EAAsB,CACvC,GAAiB,CAAC,O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ptions, NumberFormatOptions } from '@fluenti/core';
1
+ import { FluentiCoreInstanceFull, FluentiCoreConfigFull, Locale, Messages, DateFormatOptions, NumberFormatOptions } from '@fluenti/core';
2
2
  import { ReactNode, ReactElement } from 'react';
3
- export { detectLocale, getSSRLocaleScript, getHydratedLocale, isRTL, getDirection } from '@fluenti/core';
4
- export type { DetectLocaleOptions } from '@fluenti/core';
3
+ export { detectLocale, getSSRLocaleScript, getHydratedLocale } from '@fluenti/core/ssr';
4
+ export type { DetectLocaleOptions } from '@fluenti/core/ssr';
5
+ export { isRTL, getDirection } from '@fluenti/core';
5
6
  /**
6
7
  * Configuration for `createServerI18n`.
7
8
  */
@@ -43,6 +44,20 @@ export interface ServerI18nConfig {
43
44
  numberFormats?: NumberFormatOptions;
44
45
  /** Handler for missing translation keys */
45
46
  missing?: (locale: Locale, id: string) => string | undefined;
47
+ /**
48
+ * Custom interpolation function for ICU MessageFormat parsing.
49
+ *
50
+ * By default, the runtime uses a lightweight `{key}` replacer.
51
+ * Pass the full `interpolate` from `@fluenti/core` for runtime
52
+ * ICU MessageFormat parsing (plurals, selects, nested arguments).
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { interpolate } from '@fluenti/core'
57
+ * createServerI18n({ interpolate, ... })
58
+ * ```
59
+ */
60
+ interpolate?: FluentiCoreConfigFull['interpolate'];
46
61
  }
47
62
  export interface ServerTransProps {
48
63
  /** Source text with embedded components */
@@ -99,14 +114,14 @@ export interface ServerSelectProps {
99
114
  export interface ServerDateTimeProps {
100
115
  /** Date value to format */
101
116
  value: Date | number;
102
- /** Named format style */
103
- style?: string;
117
+ /** Named format key defined in dateFormats config */
118
+ format?: string;
104
119
  }
105
120
  export interface ServerNumberProps {
106
121
  /** Number value to format */
107
122
  value: number;
108
- /** Named format style */
109
- style?: string;
123
+ /** Named format key defined in numberFormats config */
124
+ format?: string;
110
125
  }
111
126
  type ServerTransComponent = (props: ServerTransProps) => Promise<ReactElement>;
112
127
  type ServerPluralComponent = (props: ServerPluralProps) => Promise<ReactElement>;
@@ -171,7 +186,7 @@ export interface ServerI18n {
171
186
  *
172
187
  * @example
173
188
  * ```tsx
174
- * <DateTime value={new Date()} style="long" />
189
+ * <DateTime value={new Date()} format="long" />
175
190
  * ```
176
191
  */
177
192
  DateTime: ServerDateTimeComponent;
@@ -180,7 +195,7 @@ export interface ServerI18n {
180
195
  *
181
196
  * @example
182
197
  * ```tsx
183
- * <NumberFormat value={1234.56} style="currency" />
198
+ * <NumberFormat value={1234.56} format="currency" />
184
199
  * ```
185
200
  */
186
201
  NumberFormat: ServerNumberComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EAEvB,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,OAAO,CAAA;AAMlF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACxG,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,GAAG;QAAE,OAAO,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAA;IAC3E,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,aAAa,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9C,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,gCAAgC;IAChC,WAAW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uBAAuB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CACtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU,CA2RrE"}
package/dist/server.js CHANGED
@@ -1,18 +1,19 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./icu-rich-BOtj4Oxu.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./icu-rich-ChVWsA7C.js";
2
2
  import { Fragment as l, cache as u, createElement as d } from "react";
3
- import { createFluentiCore as f, detectLocale as p, getDirection as m, getHydratedLocale as h, getSSRLocaleScript as g, isRTL as _ } from "@fluenti/core";
4
- import { hashMessage as v } from "@fluenti/core/internal";
3
+ import { createFluentiCore as f, getDirection as p, isRTL as m } from "@fluenti/core";
4
+ import { hashMessage as h } from "@fluenti/core/internal";
5
+ import { detectLocale as g, getHydratedLocale as _, getSSRLocaleScript as v } from "@fluenti/core/ssr";
5
6
  //#region src/server.ts
6
7
  function y(p) {
7
8
  let m = u(() => ({
8
9
  locale: null,
9
10
  instance: null
10
- })), h = u(() => /* @__PURE__ */ new Map()), g = null, _ = 0, y = 0;
11
+ })), g = u(() => /* @__PURE__ */ new Map()), _ = null, v = 0, y = 0;
11
12
  function b(e) {
12
- m().locale = e, _++, g = null;
13
+ m().locale = e, v++, _ = null;
13
14
  }
14
15
  async function x(e) {
15
- let t = h(), n = t.get(e);
16
+ let t = g(), n = t.get(e);
16
17
  if (n) return n;
17
18
  let r = await p.loadMessages(e), i = typeof r == "object" && r && "default" in r ? r.default : r;
18
19
  return t.set(e, i), i;
@@ -29,7 +30,7 @@ function y(p) {
29
30
  locale: t,
30
31
  messages: n
31
32
  };
32
- return p.fallbackLocale !== void 0 && (r.fallbackLocale = p.fallbackLocale), p.fallbackChain !== void 0 && (r.fallbackChain = p.fallbackChain), p.dateFormats !== void 0 && (r.dateFormats = p.dateFormats), p.numberFormats !== void 0 && (r.numberFormats = p.numberFormats), p.missing !== void 0 && (r.missing = p.missing), e.instance = f(r), g = e.instance, y = _, e.instance;
33
+ return p.fallbackLocale !== void 0 && (r.fallbackLocale = p.fallbackLocale), p.fallbackChain !== void 0 && (r.fallbackChain = p.fallbackChain), p.dateFormats !== void 0 && (r.dateFormats = p.dateFormats), p.numberFormats !== void 0 && (r.numberFormats = p.numberFormats), p.missing !== void 0 && (r.missing = p.missing), p.interpolate !== void 0 && (r.interpolate = p.interpolate), e.instance = f(r), _ = e.instance, y = v, e.instance;
33
34
  }
34
35
  async function C({ children: e, id: n, context: i, comment: a, render: o }) {
35
36
  let c = await S(), { message: u, components: f } = s(e), p = n ?? t(u, i), m = r(c.t({
@@ -40,14 +41,14 @@ function y(p) {
40
41
  }), f);
41
42
  return d(l, null, o ? o(m) : m);
42
43
  }
43
- async function w({ value: t, id: r, context: i, comment: o, zero: s, one: u, two: f, few: p, many: m, other: h, offset: g }) {
44
- let _ = await S(), { messages: y, components: b } = e(a, {
44
+ async function w({ value: t, id: r, context: i, comment: o, zero: s, one: u, two: f, few: p, many: m, other: g, offset: _ }) {
45
+ let v = await S(), { messages: y, components: b } = e(a, {
45
46
  zero: s,
46
47
  one: u,
47
48
  two: f,
48
49
  few: p,
49
50
  many: m,
50
- other: h
51
+ other: g
51
52
  }), x = c({
52
53
  ...y.zero !== void 0 && { zero: y.zero },
53
54
  ...y.one !== void 0 && { one: y.one },
@@ -55,13 +56,13 @@ function y(p) {
55
56
  ...y.few !== void 0 && { few: y.few },
56
57
  ...y.many !== void 0 && { many: y.many },
57
58
  other: y.other ?? ""
58
- }, g);
59
+ }, _);
59
60
  return d(l, null, n({
60
- id: r ?? (i === void 0 ? x : v(x, i)),
61
+ id: r ?? (i === void 0 ? x : h(x, i)),
61
62
  message: x,
62
63
  ...i === void 0 ? {} : { context: i },
63
64
  ...o === void 0 ? {} : { comment: o }
64
- }, { count: t }, (e, t) => _.t(e, t), b));
65
+ }, { count: t }, (e, t) => v.t(e, t), b));
65
66
  }
66
67
  async function T({ value: t, id: r, context: a, comment: s, other: c, options: u, ...f }) {
67
68
  let p = await S(), m = u === void 0 ? {
@@ -77,25 +78,25 @@ function y(p) {
77
78
  } : {
78
79
  ...u,
79
80
  other: c
80
- }, h = [...Object.keys(m).filter((e) => e !== "other"), "other"], { messages: g, components: _ } = e(h, m), y = o(Object.fromEntries([...h].map((e) => [e, g[e] ?? ""]))), b = i(y.forms);
81
+ }, g = [...Object.keys(m).filter((e) => e !== "other"), "other"], { messages: _, components: v } = e(g, m), y = o(Object.fromEntries([...g].map((e) => [e, _[e] ?? ""]))), b = i(y.forms);
81
82
  return d(l, null, n({
82
- id: r ?? (a === void 0 ? b : v(b, a)),
83
+ id: r ?? (a === void 0 ? b : h(b, a)),
83
84
  message: b,
84
85
  ...a === void 0 ? {} : { context: a },
85
86
  ...s === void 0 ? {} : { comment: s }
86
- }, { value: y.valueMap[t] ?? "other" }, (e, t) => p.t(e, t), _));
87
+ }, { value: y.valueMap[t] ?? "other" }, (e, t) => p.t(e, t), v));
87
88
  }
88
- async function E({ value: e, style: t }) {
89
+ async function E({ value: e, format: t }) {
89
90
  return d(l, null, (await S()).d(e, t));
90
91
  }
91
- async function D({ value: e, style: t }) {
92
+ async function D({ value: e, format: t }) {
92
93
  return d(l, null, (await S()).n(e, t));
93
94
  }
94
95
  function O() {
95
96
  let e = m();
96
97
  if (e.instance) return e.instance;
97
- if (g && y === _) return g;
98
- let t = e.locale ?? p.fallbackLocale ?? "en", n = h(), r = {}, i = n.get(t);
98
+ if (_ && y === v) return _;
99
+ let t = e.locale ?? p.fallbackLocale ?? "en", n = g(), r = {}, i = n.get(t);
99
100
  if (i && (r[t] = i), p.fallbackLocale && p.fallbackLocale !== t) {
100
101
  let e = n.get(p.fallbackLocale);
101
102
  e && (r[p.fallbackLocale] = e);
@@ -104,7 +105,7 @@ function y(p) {
104
105
  locale: t,
105
106
  messages: r
106
107
  };
107
- return p.fallbackLocale !== void 0 && (a.fallbackLocale = p.fallbackLocale), p.fallbackChain !== void 0 && (a.fallbackChain = p.fallbackChain), p.dateFormats !== void 0 && (a.dateFormats = p.dateFormats), p.numberFormats !== void 0 && (a.numberFormats = p.numberFormats), p.missing !== void 0 && (a.missing = p.missing), e.instance = f(a), e.instance;
108
+ return p.fallbackLocale !== void 0 && (a.fallbackLocale = p.fallbackLocale), p.fallbackChain !== void 0 && (a.fallbackChain = p.fallbackChain), p.dateFormats !== void 0 && (a.dateFormats = p.dateFormats), p.numberFormats !== void 0 && (a.numberFormats = p.numberFormats), p.missing !== void 0 && (a.missing = p.missing), p.interpolate !== void 0 && (a.interpolate = p.interpolate), e.instance = f(a), e.instance;
108
109
  }
109
110
  async function k(e, t) {
110
111
  let n = await S();
@@ -128,6 +129,6 @@ function y(p) {
128
129
  };
129
130
  }
130
131
  //#endregion
131
- export { y as createServerI18n, p as detectLocale, m as getDirection, h as getHydratedLocale, g as getSSRLocaleScript, _ as isRTL };
132
+ export { y as createServerI18n, g as detectLocale, p as getDirection, _ as getHydratedLocale, v as getSSRLocaleScript, m as isRTL };
132
133
 
133
134
  //# sourceMappingURL=server.js.map