@intlayer/use-intl 9.0.0-canary.2 → 9.0.0-canary.21

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 (88) hide show
  1. package/dist/cjs/{react → client}/IntlProvider.cjs +1 -1
  2. package/dist/cjs/client/IntlProvider.cjs.map +1 -0
  3. package/dist/cjs/{react → client}/helpers.cjs +1 -1
  4. package/dist/cjs/client/helpers.cjs.map +1 -0
  5. package/dist/cjs/client/index.cjs +27 -0
  6. package/dist/cjs/client/index.cjs.map +1 -0
  7. package/dist/cjs/{react → client}/useLocale.cjs +1 -1
  8. package/dist/cjs/client/useLocale.cjs.map +1 -0
  9. package/dist/cjs/{react → client}/useTranslations.cjs +1 -1
  10. package/dist/cjs/client/useTranslations.cjs.map +1 -0
  11. package/dist/cjs/core/initializeConfig.cjs.map +1 -1
  12. package/dist/cjs/index.cjs +14 -14
  13. package/dist/esm/{react → client}/IntlProvider.mjs +1 -1
  14. package/dist/esm/client/IntlProvider.mjs.map +1 -0
  15. package/dist/esm/{react → client}/helpers.mjs +1 -1
  16. package/dist/esm/client/helpers.mjs.map +1 -0
  17. package/dist/esm/{react → client}/index.mjs +3 -3
  18. package/dist/esm/client/index.mjs.map +1 -0
  19. package/dist/esm/{react → client}/useLocale.mjs +1 -1
  20. package/dist/esm/client/useLocale.mjs.map +1 -0
  21. package/dist/esm/{react → client}/useTranslations.mjs +2 -2
  22. package/dist/esm/client/useTranslations.mjs.map +1 -0
  23. package/dist/esm/core/createFormatter.mjs.map +1 -1
  24. package/dist/esm/core/createTranslator.mjs.map +1 -1
  25. package/dist/esm/core/errors.mjs.map +1 -1
  26. package/dist/esm/core/hasLocale.mjs.map +1 -1
  27. package/dist/esm/core/initializeConfig.mjs.map +1 -1
  28. package/dist/esm/index.mjs +8 -7
  29. package/dist/esm/plugin/index.mjs +3 -36
  30. package/dist/esm/plugin/index.mjs.map +1 -1
  31. package/dist/esm/shared/intlFormatter.mjs.map +1 -1
  32. package/dist/esm/shared/namespaceTranslator.mjs +56 -35
  33. package/dist/esm/shared/namespaceTranslator.mjs.map +1 -1
  34. package/dist/esm/useDictionary.mjs +10 -15
  35. package/dist/esm/useDictionary.mjs.map +1 -1
  36. package/dist/esm/useDictionaryDynamic.mjs +7 -15
  37. package/dist/esm/useDictionaryDynamic.mjs.map +1 -1
  38. package/dist/types/{react → client}/IntlProvider.d.ts +4 -4
  39. package/dist/types/client/IntlProvider.d.ts.map +1 -0
  40. package/dist/types/{react → client}/helpers.d.ts +1 -2
  41. package/dist/types/client/helpers.d.ts.map +1 -0
  42. package/dist/types/{react → client}/index.d.ts +3 -4
  43. package/dist/types/client/index.d.ts.map +1 -0
  44. package/dist/types/{react → client}/useLocale.d.ts +1 -2
  45. package/dist/types/client/useLocale.d.ts.map +1 -0
  46. package/dist/types/{react → client}/useTranslations.d.ts +5 -5
  47. package/dist/types/client/useTranslations.d.ts.map +1 -0
  48. package/dist/types/core/createFormatter.d.ts +0 -1
  49. package/dist/types/core/createFormatter.d.ts.map +1 -1
  50. package/dist/types/core/createTranslator.d.ts +9 -7
  51. package/dist/types/core/createTranslator.d.ts.map +1 -1
  52. package/dist/types/core/errors.d.ts.map +1 -1
  53. package/dist/types/core/hasLocale.d.ts +0 -1
  54. package/dist/types/core/hasLocale.d.ts.map +1 -1
  55. package/dist/types/core/index.d.ts +1 -1
  56. package/dist/types/core/initializeConfig.d.ts +0 -1
  57. package/dist/types/core/initializeConfig.d.ts.map +1 -1
  58. package/dist/types/core/types.d.ts +1 -1
  59. package/dist/types/index.d.ts +11 -8
  60. package/dist/types/plugin/index.d.ts +0 -1
  61. package/dist/types/plugin/index.d.ts.map +1 -1
  62. package/dist/types/shared/intlFormatter.d.ts +0 -1
  63. package/dist/types/shared/intlFormatter.d.ts.map +1 -1
  64. package/dist/types/shared/namespaceTranslator.d.ts +33 -12
  65. package/dist/types/shared/namespaceTranslator.d.ts.map +1 -1
  66. package/dist/types/shared/translateFunctionTypes.d.ts +53 -8
  67. package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -1
  68. package/dist/types/useDictionary.d.ts +15 -6
  69. package/dist/types/useDictionary.d.ts.map +1 -1
  70. package/dist/types/useDictionaryDynamic.d.ts +12 -7
  71. package/dist/types/useDictionaryDynamic.d.ts.map +1 -1
  72. package/package.json +18 -22
  73. package/dist/cjs/react/IntlProvider.cjs.map +0 -1
  74. package/dist/cjs/react/helpers.cjs.map +0 -1
  75. package/dist/cjs/react/index.cjs +0 -27
  76. package/dist/cjs/react/index.cjs.map +0 -1
  77. package/dist/cjs/react/useLocale.cjs.map +0 -1
  78. package/dist/cjs/react/useTranslations.cjs.map +0 -1
  79. package/dist/esm/react/IntlProvider.mjs.map +0 -1
  80. package/dist/esm/react/helpers.mjs.map +0 -1
  81. package/dist/esm/react/index.mjs.map +0 -1
  82. package/dist/esm/react/useLocale.mjs.map +0 -1
  83. package/dist/esm/react/useTranslations.mjs.map +0 -1
  84. package/dist/types/react/IntlProvider.d.ts.map +0 -1
  85. package/dist/types/react/helpers.d.ts.map +0 -1
  86. package/dist/types/react/index.d.ts.map +0 -1
  87. package/dist/types/react/useLocale.d.ts.map +0 -1
  88. package/dist/types/react/useTranslations.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"namespaceTranslator.mjs","names":[],"sources":["../../../src/shared/namespaceTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\n/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */\nexport type RichChunkRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Chunk renderer used by `t.markup()` — maps tag children to a string. */\nexport type MarkupChunkRenderer = (chunks: string) => string;\n\n/**\n * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.\n *\n * @param objectValue - The object to read from.\n * @param path - Dot-separated path. An empty path returns `objectValue`.\n * @returns The value found at `path`, or `undefined` when any segment is absent.\n */\nexport const navigatePath = (objectValue: unknown, path: string): unknown => {\n if (!path) return objectValue;\n const parts = path.split('.');\n let current: unknown = objectValue;\n for (const part of parts) {\n if (\n current === null ||\n current === undefined ||\n typeof current !== 'object'\n ) {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n return current;\n};\n\n/** Splits rich values into scalar interpolation values and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown> = {}\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n\n for (const [valueKey, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[valueKey] = value;\n else scalarValues[valueKey] = value;\n }\n\n return { scalarValues, renderers };\n};\n\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichChunkRenderer)(children)}\n </Fragment>\n );\n }\n\n // No renderer provided for the tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\nconst renderMarkupTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): string =>\n tokens\n .map((token) => {\n if (typeof token === 'string') return token;\n\n const children = renderMarkupTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (renderer as MarkupChunkRenderer)(children);\n }\n\n return children;\n })\n .join('');\n\n/**\n * The untyped runtime translator shared by `useTranslations` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / next-intl:\n * - namespace `'about'` → keys resolved inside the `about` dictionary\n * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`\n * - no namespace → the first segment of each key is the dictionary key\n * - messages support ICU syntax (plural, select, `#`, formatted arguments)\n * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided\n * renderers; `t.raw` returns the raw value; `t.has` checks existence\n *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (key: string): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment;\n path = restSegments.join('.');\n }\n\n try {\n const dictionary = getIntlayer(\n targetDictionaryKey as DictionaryKeys,\n locale\n );\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n };\n\n const resolveToString = (\n key: string,\n values: MessageValues = {}\n ): string | undefined => {\n const rawValue = lookup(key);\n if (rawValue === null || rawValue === undefined) return undefined;\n return resolveMessage(rawValue, values, locale, 'icu');\n };\n\n const missingKeyFallback = (key: string): string =>\n namespace ? `${namespace}.${key}` : key;\n\n const translate = (key: string, values?: MessageValues): string =>\n resolveToString(key, values) ?? missingKeyFallback(key);\n\n return Object.assign(translate, {\n /** Returns `true` if the given key exists in the namespace. */\n has: (key: string): boolean => lookup(key) !== undefined,\n\n /** Returns the raw unprocessed content for the given key. */\n raw: (key: string): unknown => lookup(key),\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup, mapping each\n * tag through the matching renderer in `values`.\n */\n rich: (key: string, values?: Record<string, unknown>): ReactNode => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return <>{renderRichTokens(parseTaggedMessage(message), renderers)}</>;\n },\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup into a string,\n * mapping each tag through the matching string renderer in `values`.\n */\n markup: (key: string, values?: Record<string, unknown>): string => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return renderMarkupTokens(parseTaggedMessage(message), renderers);\n },\n });\n};\n\nexport type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,aAAsB,SAA0B;AAC3E,KAAI,CAAC,KAAM,QAAO;CAClB,MAAM,QAAQ,KAAK,MAAM,IAAI;CAC7B,IAAI,UAAmB;AACvB,MAAK,MAAM,QAAQ,OAAO;AACxB,MACE,YAAY,QACZ,YAAY,UACZ,OAAO,YAAY,SAEnB;AAEF,YAAW,QAAoC;;AAEjD,QAAO;;;AAIT,MAAM,mBACJ,SAAkC,EAAE,KACoC;CACxE,MAAM,eAA8B,EAAE;CACtC,MAAM,YAAqC,EAAE;AAE7C,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,OAAO,CACpD,KAAI,OAAO,UAAU,WAAY,WAAU,YAAY;KAClD,cAAa,YAAY;AAGhC,QAAO;EAAE;EAAc;EAAW;;AAGpC,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;AAChC,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,UAAU;CAC5D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QACE,oBAAC,UAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,oBAAC,UAAD,EAA4B,UAAoB,EAAjC,WAAiC;EACvD;AAEJ,MAAM,sBACJ,QACA,cAEA,OACG,KAAK,UAAU;AACd,KAAI,OAAO,UAAU,SAAU,QAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,UAAU,UAAU;CAC9D,MAAM,WAAW,UAAU,MAAM;AAEjC,KAAI,OAAO,aAAa,WACtB,QAAQ,SAAiC,SAAS;AAGpD,QAAO;EACP,CACD,KAAK,GAAG;;;;;;;;;;;;;;;;;AAkBb,MAAa,6BACX,QACA,cACG;CACH,MAAM,CAAC,eAAe,GAAG,mBAAmB,aAAa,IAAI,MAAM,IAAI;CACvE,MAAM,YAAY,eAAe,KAAK,IAAI;CAE1C,MAAM,UAAU,QAAyB;EACvC,IAAI,sBAAsB;EAC1B,IAAI,OAAO,YAAY,GAAG,UAAU,GAAG,QAAQ;AAE/C,MAAI,CAAC,qBAAqB;GAExB,MAAM,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,IAAI;AACtD,yBAAsB;AACtB,UAAO,aAAa,KAAK,IAAI;;AAG/B,MAAI;AAKF,UAAO,aAJY,YACjB,qBACA,OAE4B,EAAE,KAAK;UAC/B;AACN;;;CAIJ,MAAM,mBACJ,KACA,SAAwB,EAAE,KACH;EACvB,MAAM,WAAW,OAAO,IAAI;AAC5B,MAAI,aAAa,QAAQ,aAAa,OAAW,QAAO;AACxD,SAAO,eAAe,UAAU,QAAQ,QAAQ,MAAM;;CAGxD,MAAM,sBAAsB,QAC1B,YAAY,GAAG,UAAU,GAAG,QAAQ;CAEtC,MAAM,aAAa,KAAa,WAC9B,gBAAgB,KAAK,OAAO,IAAI,mBAAmB,IAAI;AAEzD,QAAO,OAAO,OAAO,WAAW;;EAE9B,MAAM,QAAyB,OAAO,IAAI,KAAK;;EAG/C,MAAM,QAAyB,OAAO,IAAI;;;;;EAM1C,OAAO,KAAa,WAAgD;GAClE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,4CAAG,iBAAiB,mBAAmB,QAAQ,EAAE,UAAU,EAAI;;;;;;EAOxE,SAAS,KAAa,WAA6C;GACjE,MAAM,EAAE,cAAc,cAAc,gBAAgB,OAAO;GAC3D,MAAM,UAAU,gBAAgB,KAAK,aAAa;AAClD,OAAI,YAAY,OAAW,QAAO,mBAAmB,IAAI;AACzD,UAAO,mBAAmB,mBAAmB,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
1
+ {"version":3,"file":"namespaceTranslator.mjs","names":["navigatePath"],"sources":["../../../src/shared/namespaceTranslator.tsx"],"sourcesContent":["import { getIntlayer } from '@intlayer/core/interpreter';\nimport {\n type MessageValues,\n navigatePath,\n parseTaggedMessage,\n resolveMessage,\n type TaggedMessageToken,\n} from '@intlayer/core/messageFormat';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { Fragment, type ReactNode } from 'react';\n\nexport { navigatePath } from '@intlayer/core/messageFormat';\n\n/** Chunk renderer used by `t.rich()` — maps tag children to a React node. */\nexport type RichChunkRenderer = (chunks: ReactNode) => ReactNode;\n\n/** Chunk renderer used by `t.markup()` — maps tag children to a string. */\nexport type MarkupChunkRenderer = (chunks: string) => string;\n\n/** Splits rich values into scalar interpolation values and tag renderers. */\nconst splitRichValues = (\n values: Record<string, unknown> = {}\n): { scalarValues: MessageValues; renderers: Record<string, unknown> } => {\n const scalarValues: MessageValues = {};\n const renderers: Record<string, unknown> = {};\n\n for (const [valueKey, value] of Object.entries(values)) {\n if (typeof value === 'function') renderers[valueKey] = value;\n else scalarValues[valueKey] = value;\n }\n\n return { scalarValues, renderers };\n};\n\nconst renderRichTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): ReactNode[] =>\n tokens.map((token, tokenIndex) => {\n if (typeof token === 'string') return token;\n\n const children = renderRichTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (\n <Fragment key={tokenIndex}>\n {(renderer as RichChunkRenderer)(children)}\n </Fragment>\n );\n }\n\n // No renderer provided for the tag — render its children unwrapped\n return <Fragment key={tokenIndex}>{children}</Fragment>;\n });\n\nconst renderMarkupTokens = (\n tokens: TaggedMessageToken[],\n renderers: Record<string, unknown>\n): string =>\n tokens\n .map((token) => {\n if (typeof token === 'string') return token;\n\n const children = renderMarkupTokens(token.children, renderers);\n const renderer = renderers[token.tag];\n\n if (typeof renderer === 'function') {\n return (renderer as MarkupChunkRenderer)(children);\n }\n\n return children;\n })\n .join('');\n\n/**\n * The untyped runtime translator shared by `useTranslations` (React hook) and\n * `createTranslator` (non-React core).\n *\n * Behaviour matches use-intl / next-intl:\n * - namespace `'about'` → keys resolved inside the `about` dictionary\n * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`\n * - no namespace → the first segment of each key is the dictionary key\n * - messages support ICU syntax (plural, select, `#`, formatted arguments)\n * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided\n * renderers; `t.raw` returns the raw value; `t.has` checks existence\n *\n * @param locale - The locale dictionaries are resolved for.\n * @param namespace - Optional dictionary key, optionally with a nested scope.\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createNamespaceTranslator = (\n locale: LocalesValues,\n namespace?: string\n) => {\n const [dictionaryKey, ...prefixSegments] = (namespace ?? '').split('.');\n const keyPrefix = prefixSegments.join('.');\n\n const lookup = (lookupKey: string): unknown =>\n lookupNamespaceKey(locale, dictionaryKey ?? '', keyPrefix, lookupKey);\n\n return createLookupTranslator(locale, lookup, (key) =>\n namespace ? `${namespace}.${key}` : key\n );\n};\n\n/**\n * Key-based lookup used by {@link createNamespaceTranslator}: resolves the\n * dictionary through the runtime registry (`getIntlayer`).\n */\nconst lookupNamespaceKey = (\n locale: LocalesValues,\n dictionaryKey: string,\n keyPrefix: string,\n key: string\n): unknown => {\n let targetDictionaryKey = dictionaryKey;\n let path = keyPrefix ? `${keyPrefix}.${key}` : key;\n\n const dictionaries = getDictionaries();\n\n if (!targetDictionaryKey) {\n // Root scope — the first key segment usually designates the dictionary\n const [firstSegment, ...restSegments] = key.split('.');\n targetDictionaryKey = firstSegment ?? key;\n path = restSegments.join('.');\n\n // If the assumed dictionary doesn't exist, we must fall back to searching all dictionaries.\n // This supports apps migrating from standard next-intl where all messages were grouped together.\n if (!dictionaries[targetDictionaryKey as DictionaryKeys]) {\n for (const dictKey of Object.keys(dictionaries)) {\n try {\n const dictionary = getIntlayer(dictKey as DictionaryKeys, locale);\n const result = navigatePath(dictionary, key);\n if (result !== undefined) {\n return result;\n }\n } catch {\n // Ignore if getIntlayer throws\n }\n }\n }\n }\n\n try {\n const dictionary = getIntlayer(\n targetDictionaryKey as DictionaryKeys,\n locale\n );\n return navigatePath(dictionary, path);\n } catch {\n return undefined;\n }\n};\n\n/**\n * Dictionary-bound translator used by the build-optimized `useDictionary` /\n * `getDictionary` variants: instead of resolving the dictionary by key at\n * runtime, the pre-resolved content is supplied directly (the babel/swc\n * optimize pass imports the dictionary JSON at build time).\n *\n * @param locale - The locale messages are resolved for.\n * @param content - The dictionary content, already resolved for `locale`.\n * @param namespacePrefix - Optional key prefix for nested namespaces\n * (`useTranslations('about.counter')` → content of `about`, prefix `counter`).\n * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.\n */\nexport const createDictionaryTranslator = (\n locale: LocalesValues,\n content: unknown,\n namespacePrefix?: string\n) => {\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return createLookupTranslator(\n locale,\n (key) => navigatePath(content, resolveKey(key)),\n resolveKey\n );\n};\n\n/**\n * The untyped runtime translator core shared by every factory above:\n * ICU message resolution plus the `has` / `raw` / `rich` / `markup` helpers.\n *\n * @param locale - The locale messages are resolved for.\n * @param lookup - Reads the raw content value for a message key.\n * @param missingKeyFallback - Builds the echoed key on lookup miss\n * (use-intl convention: `namespace.key`).\n */\nconst createLookupTranslator = (\n locale: LocalesValues,\n lookup: (key: string) => unknown,\n missingKeyFallback: (key: string) => string\n) => {\n const resolveToString = (\n key: string,\n values: MessageValues = {}\n ): string | undefined => {\n const rawValue = lookup(key);\n if (rawValue === null || rawValue === undefined) return undefined;\n return resolveMessage(rawValue, values, locale, 'icu');\n };\n\n const translate = (key: string, values?: MessageValues): string =>\n resolveToString(key, values) ?? missingKeyFallback(key);\n\n return Object.assign(translate, {\n /** Returns `true` if the given key exists in the namespace. */\n has: (key: string): boolean => lookup(key) !== undefined,\n\n /** Returns the raw unprocessed content for the given key. */\n raw: (key: string): unknown => lookup(key),\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup, mapping each\n * tag through the matching renderer in `values`.\n */\n rich: (key: string, values?: Record<string, unknown>): ReactNode => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return <>{renderRichTokens(parseTaggedMessage(message), renderers)}</>;\n },\n\n /**\n * Resolves a message containing `<tag>chunks</tag>` markup into a string,\n * mapping each tag through the matching string renderer in `values`.\n */\n markup: (key: string, values?: Record<string, unknown>): string => {\n const { scalarValues, renderers } = splitRichValues(values);\n const message = resolveToString(key, scalarValues);\n if (message === undefined) return missingKeyFallback(key);\n return renderMarkupTokens(parseTaggedMessage(message), renderers);\n },\n });\n};\n\nexport type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;\n"],"mappings":";;;;;;;;AAwBA,MAAM,mBACJ,SAAkC,CAAC,MACqC;CACxE,MAAM,eAA8B,CAAC;CACrC,MAAM,YAAqC,CAAC;CAE5C,KAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,MAAM,GACnD,IAAI,OAAO,UAAU,YAAY,UAAU,YAAY;MAClD,aAAa,YAAY;CAGhC,OAAO;EAAE;EAAc;CAAU;AACnC;AAEA,MAAM,oBACJ,QACA,cAEA,OAAO,KAAK,OAAO,eAAe;CAChC,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,MAAM,WAAW,iBAAiB,MAAM,UAAU,SAAS;CAC3D,MAAM,WAAW,UAAU,MAAM;CAEjC,IAAI,OAAO,aAAa,YACtB,OACE,oBAAC,UAAD,YACI,SAA+B,QAAQ,EACjC,GAFK,UAEL;CAKd,OAAO,oBAAC,UAAD,EAA4B,SAAmB,GAAhC,UAAgC;AACxD,CAAC;AAEH,MAAM,sBACJ,QACA,cAEA,OACG,KAAK,UAAU;CACd,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,UAAU,SAAS;CAC7D,MAAM,WAAW,UAAU,MAAM;CAEjC,IAAI,OAAO,aAAa,YACtB,OAAQ,SAAiC,QAAQ;CAGnD,OAAO;AACT,CAAC,CAAC,CACD,KAAK,EAAE;;;;;;;;;;;;;;;;;AAkBZ,MAAa,6BACX,QACA,cACG;CACH,MAAM,CAAC,eAAe,GAAG,mBAAmB,aAAa,GAAE,CAAE,MAAM,GAAG;CACtE,MAAM,YAAY,eAAe,KAAK,GAAG;CAEzC,MAAM,UAAU,cACd,mBAAmB,QAAQ,iBAAiB,IAAI,WAAW,SAAS;CAEtE,OAAO,uBAAuB,QAAQ,SAAS,QAC7C,YAAY,GAAG,UAAU,GAAG,QAAQ,GACtC;AACF;;;;;AAMA,MAAM,sBACJ,QACA,eACA,WACA,QACY;CACZ,IAAI,sBAAsB;CAC1B,IAAI,OAAO,YAAY,GAAG,UAAU,GAAG,QAAQ;CAE/C,MAAM,eAAe,gBAAgB;CAErC,IAAI,CAAC,qBAAqB;EAExB,MAAM,CAAC,cAAc,GAAG,gBAAgB,IAAI,MAAM,GAAG;EACrD,sBAAsB,gBAAgB;EACtC,OAAO,aAAa,KAAK,GAAG;EAI5B,IAAI,CAAC,aAAa,sBAChB,KAAK,MAAM,WAAW,OAAO,KAAK,YAAY,GAC5C,IAAI;GAEF,MAAM,SAASA,eADI,YAAY,SAA2B,MACrB,GAAG,GAAG;GAC3C,IAAI,WAAW,QACb,OAAO;EAEX,QAAQ,CAER;CAGN;CAEA,IAAI;EAKF,OAAOA,eAJY,YACjB,qBACA,MAE2B,GAAG,IAAI;CACtC,QAAQ;EACN;CACF;AACF;;;;;;;;;;;;;AAcA,MAAa,8BACX,QACA,SACA,oBACG;CACH,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;CAElD,OAAO,uBACL,SACC,QAAQA,eAAa,SAAS,WAAW,GAAG,CAAC,GAC9C,UACF;AACF;;;;;;;;;;AAWA,MAAM,0BACJ,QACA,QACA,uBACG;CACH,MAAM,mBACJ,KACA,SAAwB,CAAC,MACF;EACvB,MAAM,WAAW,OAAO,GAAG;EAC3B,IAAI,aAAa,QAAQ,aAAa,QAAW,OAAO;EACxD,OAAO,eAAe,UAAU,QAAQ,QAAQ,KAAK;CACvD;CAEA,MAAM,aAAa,KAAa,WAC9B,gBAAgB,KAAK,MAAM,KAAK,mBAAmB,GAAG;CAExD,OAAO,OAAO,OAAO,WAAW;;EAE9B,MAAM,QAAyB,OAAO,GAAG,MAAM;;EAG/C,MAAM,QAAyB,OAAO,GAAG;;;;;EAMzC,OAAO,KAAa,WAAgD;GAClE,MAAM,EAAE,cAAc,cAAc,gBAAgB,MAAM;GAC1D,MAAM,UAAU,gBAAgB,KAAK,YAAY;GACjD,IAAI,YAAY,QAAW,OAAO,mBAAmB,GAAG;GACxD,OAAO,4CAAG,iBAAiB,mBAAmB,OAAO,GAAG,SAAS,EAAI;EACvE;;;;;EAMA,SAAS,KAAa,WAA6C;GACjE,MAAM,EAAE,cAAc,cAAc,gBAAgB,MAAM;GAC1D,MAAM,UAAU,gBAAgB,KAAK,YAAY;GACjD,IAAI,YAAY,QAAW,OAAO,mBAAmB,GAAG;GACxD,OAAO,mBAAmB,mBAAmB,OAAO,GAAG,SAAS;EAClE;CACF,CAAC;AACH"}
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
 
3
- import { navigatePath } from "./shared/namespaceTranslator.mjs";
4
- import { useDictionary as useDictionary$1 } from "react-intlayer";
3
+ import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
4
+ import { useContext } from "react";
5
+ import { IntlayerClientContext, useDictionary as useDictionary$1 } from "react-intlayer";
5
6
 
6
7
  //#region src/useDictionary.ts
7
8
  /**
@@ -12,23 +13,17 @@ import { useDictionary as useDictionary$1 } from "react-intlayer";
12
13
  * JSON at build time and passes it directly here. This enables tree-shaking of
13
14
  * unused locale content.
14
15
  *
16
+ * The returned translator matches `useTranslations` exactly (ICU messages,
17
+ * `has`, `raw`, `rich`, `markup`).
18
+ *
15
19
  * @example (generated by the plugin, not written manually)
16
20
  * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
17
21
  * const t = useDictionary(_abc);
18
22
  */
19
- const useDictionary = (dictionary, namespacePrefix) => {
20
- const content = useDictionary$1(dictionary);
21
- const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
22
- return Object.assign((lookup, params) => {
23
- const rawValue = navigatePath(content, resolveKey(String(lookup)));
24
- const text = String(rawValue ?? resolveKey(String(lookup)));
25
- if (!params) return text;
26
- return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
27
- }, {
28
- has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
29
- raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
30
- });
31
- };
23
+ const useDictionary = ((dictionary, namespacePrefix) => {
24
+ const { locale } = useContext(IntlayerClientContext) ?? {};
25
+ return createDictionaryTranslator(locale, useDictionary$1(dictionary), namespacePrefix);
26
+ });
32
27
 
33
28
  //#endregion
34
29
  export { useDictionary };
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dictionary-accepting variant of `useTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * @example (generated by the plugin, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const t = useDictionary(_abc);\n */\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = useDictionaryBase(dictionary);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,MAAa,iBACX,YACA,oBACG;CACH,MAAM,UAAUA,gBAAkB,WAAW;CAE7C,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;AAElD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
1
+ {"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport {\n IntlayerClientContext,\n useDictionary as useDictionaryBase,\n} from 'react-intlayer';\nimport { createDictionaryTranslator } from './shared/namespaceTranslator';\nimport type {\n ScopedTranslateFunction,\n TranslateFunction,\n} from './shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useDictionary}: without a prefix the translator is\n * typed against the dictionary's dot-paths; with a prefix the keys are\n * relative dot-paths under that scope.\n */\ntype UseDictionary = {\n <T extends Dictionary>(\n dictionary: T\n ): TranslateFunction<T['key'] & DictionaryKeys>;\n <T extends Dictionary, Prefix extends string>(\n dictionary: T,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>;\n};\n\n/**\n * Dictionary-accepting variant of `useTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * The returned translator matches `useTranslations` exactly (ICU messages,\n * `has`, `raw`, `rich`, `markup`).\n *\n * @example (generated by the plugin, not written manually)\n * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };\n * const t = useDictionary(_abc);\n */\nexport const useDictionary = (<T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const content = useDictionaryBase(dictionary);\n\n return createDictionaryTranslator(\n locale as LocalesValues,\n content,\n namespacePrefix\n );\n}) as UseDictionary;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,kBACX,YACA,oBACG;CACH,MAAM,EAAE,WAAW,WAAW,qBAAqB,KAAK,CAAC;CAGzD,OAAO,2BACL,QAHcA,gBAAkB,UAI1B,GACN,eACF;AACF"}
@@ -1,7 +1,8 @@
1
1
  'use client';
2
2
 
3
- import { navigatePath } from "./shared/namespaceTranslator.mjs";
4
- import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
3
+ import { createDictionaryTranslator } from "./shared/namespaceTranslator.mjs";
4
+ import { useContext } from "react";
5
+ import { IntlayerClientContext, useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
5
6
 
6
7
  //#region src/useDictionaryDynamic.ts
7
8
  /**
@@ -10,19 +11,10 @@ import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
10
11
  * Counterpart to {@link useDictionary} for dictionaries imported lazily per
11
12
  * locale. Used internally by the build-time optimization.
12
13
  */
13
- const useDictionaryDynamic = (dictionaryPromise, key, namespacePrefix) => {
14
- const content = useDictionaryDynamic$1(dictionaryPromise, key);
15
- const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
16
- return Object.assign((lookup, params) => {
17
- const rawValue = navigatePath(content, resolveKey(String(lookup)));
18
- const text = String(rawValue ?? resolveKey(String(lookup)));
19
- if (!params) return text;
20
- return text.replace(/\{(\w+)\}/g, (_match, key) => params[key] != null ? String(params[key]) : `{${key}}`);
21
- }, {
22
- has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
23
- raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
24
- });
25
- };
14
+ const useDictionaryDynamic = ((dictionaryPromise, key, namespacePrefix) => {
15
+ const { locale } = useContext(IntlayerClientContext) ?? {};
16
+ return createDictionaryTranslator(locale, useDictionaryDynamic$1(dictionaryPromise, key), namespacePrefix);
17
+ });
26
18
 
27
19
  //#endregion
28
20
  export { useDictionaryDynamic };
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer';\nimport { navigatePath } from './shared/namespaceTranslator';\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n *\n * Counterpart to {@link useDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends string,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<string>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const text = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return text;\n return text.replace(/\\{(\\w+)\\}/g, (_match, key) =>\n params[key] != null ? String(params[key]) : `{${key}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<string>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<string>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,wBAIX,mBACA,KACA,oBACG;CACH,MAAM,UAAUA,uBAA+B,mBAAmB,IAAI;CAEtE,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,OAAO,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC3D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,KAAK,QAAQ,eAAe,QAAQ,QACzC,OAAO,QAAQ,OAAO,OAAO,OAAO,KAAK,GAAG,IAAI,IAAI,GACrD;IAEH;EACE,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAA0C,WACxC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
1
+ {"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../src/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport {\n IntlayerClientContext,\n useDictionaryDynamic as useDictionaryDynamicBase,\n} from 'react-intlayer';\nimport { createDictionaryTranslator } from './shared/namespaceTranslator';\nimport type {\n ScopedTranslateFunction,\n TranslateFunction,\n} from './shared/translateFunctionTypes';\n\n/**\n * Overload set for {@link useDictionaryDynamic}: without a prefix the\n * translator is typed against the dictionary's dot-paths; with a prefix the\n * keys are relative dot-paths under that scope.\n */\ntype UseDictionaryDynamic = {\n <T extends Dictionary, K extends DictionaryKeys>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K\n ): TranslateFunction<K>;\n <T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<K, Prefix>;\n};\n\n/**\n * Dynamic dictionary-accepting variant of `useTranslations`.\n *\n * Counterpart to {@link useDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const useDictionaryDynamic = (<\n const T extends Dictionary,\n const K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const content = useDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n return createDictionaryTranslator(\n locale as LocalesValues,\n content,\n namespacePrefix\n );\n}) as UseDictionaryDynamic;\n"],"mappings":";;;;;;;;;;;;;AA0CA,MAAa,yBAIX,mBACA,KACA,oBACG;CACH,MAAM,EAAE,WAAW,WAAW,qBAAqB,KAAK,CAAC;CAGzD,OAAO,2BACL,QAHcA,uBAA+B,mBAAmB,GAI1D,GACN,eACF;AACF"}
@@ -1,8 +1,7 @@
1
- import { IntlProvider as IntlProvider$1 } from "use-intl";
2
1
  import { LocalesValues } from "@intlayer/types/module_augmentation";
3
2
  import { ComponentProps } from "react";
4
-
5
- //#region src/react/IntlProvider.d.ts
3
+ import { IntlProvider as IntlProvider$1 } from "use-intl";
4
+ //#region src/client/IntlProvider.d.ts
6
5
  /**
7
6
  * Drop-in for use-intl's `IntlProvider`.
8
7
  *
@@ -21,7 +20,8 @@ type IntlProviderProps = Omit<ComponentProps<typeof IntlProvider$1>, 'messages'
21
20
  * @deprecated has no use case with intlayer. Messages are loaded
22
21
  * automatically under the hood for bundle optimization reason.
23
22
  */
24
- messages?: never; /** The active locale. */
23
+ messages?: never;
24
+ /** The active locale. */
25
25
  locale: LocalesValues;
26
26
  };
27
27
  //#endregion
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProvider.d.ts","names":[],"sources":["../../../src/client/IntlProvider.tsx"],"mappings":";;;;;;;;;;;;cAkBa,qBAAqB;;;;;KAiCtB,oBAAoB,KAC9B,sBAAsB;;;;;EAOtB;;EAEA,QAAQ"}
@@ -1,6 +1,5 @@
1
1
  import { useFormatter as useFormatter$1, useMessages as useMessages$1, useNow as useNow$1, useTimeZone as useTimeZone$1 } from "use-intl";
2
-
3
- //#region src/react/helpers.d.ts
2
+ //#region src/client/helpers.d.ts
4
3
  /**
5
4
  * Drop-in for use-intl's `useNow`.
6
5
  * Returns the current `Date`. The `updateInterval` option is ignored.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/client/helpers.ts"],"mappings":";;;;;;cAkBa,eAAe;;;;;cAMf,oBAAoB;;;;;;;;cAUpB,oBAAoB;;;;;;;cAiBpB,qBAAqB"}
@@ -1,11 +1,10 @@
1
1
  import { IntlProvider, IntlProviderProps } from "./IntlProvider.js";
2
2
  import { useFormatter, useMessages, useNow, useTimeZone } from "./helpers.js";
3
- import { useLocale } from "./useLocale.js";
4
- import { useTranslations } from "./useTranslations.js";
5
3
  import { useDictionary } from "../useDictionary.js";
6
4
  import { useDictionaryDynamic } from "../useDictionaryDynamic.js";
7
-
8
- //#region src/react/index.d.ts
5
+ import { useLocale } from "./useLocale.js";
6
+ import { useTranslations } from "./useTranslations.js";
7
+ //#region src/client/index.d.ts
9
8
  /**
10
9
  * @internal Private use-intl export, kept so aliased `_useExtracted` imports
11
10
  * resolve. Not part of the supported public surface.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/client/index.ts"],"mappings":";;;;;;;;;;;cAWa,qBAAoB"}
@@ -1,6 +1,5 @@
1
1
  import { useLocale as useLocale$1 } from "use-intl";
2
-
3
- //#region src/react/useLocale.d.ts
2
+ //#region src/client/useLocale.d.ts
4
3
  /**
5
4
  * Drop-in for use-intl's `useLocale`.
6
5
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;;;;;cAUa,kBAAkB"}
@@ -1,19 +1,19 @@
1
- import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
1
+ import { LooseTranslateFunction, TranslateFunction, TranslateFunctionForNamespace } from "../shared/translateFunctionTypes.js";
2
2
  import { DictionaryKeys } from "@intlayer/types/module_augmentation";
3
-
4
- //#region src/react/useTranslations.d.ts
3
+ //#region src/client/useTranslations.d.ts
5
4
  /**
6
5
  * Overload set for {@link useTranslations}:
7
6
  *
8
7
  * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
9
8
  * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
10
- * `string` paths, matching use-intl's scoped-namespace behaviour.
9
+ * dot-paths under the scope, typed against the dictionary, matching
10
+ * use-intl's scoped-namespace behaviour.
11
11
  * 3. No namespace → root scope; the first segment of each key designates
12
12
  * the dictionary (`t('about.title')`).
13
13
  */
14
14
  type UseTranslations = {
15
15
  <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;
16
- (namespace: `${string}.${string}`): LooseTranslateFunction;
16
+ <N extends `${string}.${string}`>(namespace: N): TranslateFunctionForNamespace<N>;
17
17
  (): LooseTranslateFunction;
18
18
  };
19
19
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../../src/client/useTranslations.ts"],"mappings":";;;;;;;;;;;;;KAyBK;GACF,UAAU,gBAAgB,WAAW,IAAI,kBAAkB;GAC3D,iCACC,WAAW,IACV,8BAA8B;MAC7B;;;;;;;;;;;;;;;;;;;;;;;;cAyBO,iBAOP"}
@@ -1,5 +1,4 @@
1
1
  import { createFormatter as createFormatter$1 } from "use-intl";
2
-
3
2
  //#region src/core/createFormatter.d.ts
4
3
  /**
5
4
  * Drop-in for use-intl's `createFormatter`.
@@ -1 +1 @@
1
- {"version":3,"file":"createFormatter.d.ts","names":[],"sources":["../../../src/core/createFormatter.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;;;cAAa,eAAA,SAAwB,iBAAA"}
1
+ {"version":3,"file":"createFormatter.d.ts","names":[],"sources":["../../../src/core/createFormatter.ts"],"mappings":";;;;;;;;;;;;;;;;cAiBa,wBAAwB"}
@@ -1,6 +1,5 @@
1
- import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
1
+ import { LooseTranslateFunction, TranslateFunction, TranslateFunctionForNamespace } from "../shared/translateFunctionTypes.js";
2
2
  import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
3
-
4
3
  //#region src/core/createTranslator.d.ts
5
4
  /**
6
5
  * Configuration accepted by {@link createTranslator}.
@@ -10,7 +9,9 @@ import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentati
10
9
  * resolves content from its own compiled dictionaries.
11
10
  */
12
11
  type CreateTranslatorConfig<N extends DictionaryKeys> = {
13
- /** The locale dictionaries are resolved for. */locale: LocalesValues; /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */
12
+ /** The locale dictionaries are resolved for. */
13
+ locale: LocalesValues;
14
+ /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */
14
15
  namespace?: N | (string & {});
15
16
  /**
16
17
  * @deprecated has no use case with intlayer. Messages are loaded
@@ -23,7 +24,8 @@ type CreateTranslatorConfig<N extends DictionaryKeys> = {
23
24
  *
24
25
  * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
25
26
  * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
26
- * `string` paths, matching use-intl's scoped-namespace behaviour.
27
+ * dot-paths under the scope, typed against the dictionary, matching
28
+ * use-intl's scoped-namespace behaviour.
27
29
  * 3. No namespace → root scope; the first segment of each key designates
28
30
  * the dictionary (`t('about.title')`).
29
31
  */
@@ -31,9 +33,9 @@ type CreateTranslator = {
31
33
  <N extends DictionaryKeys>(config: CreateTranslatorConfig<N> & {
32
34
  namespace: N;
33
35
  }): TranslateFunction<N>;
34
- (config: CreateTranslatorConfig<DictionaryKeys> & {
35
- namespace: `${string}.${string}`;
36
- }): LooseTranslateFunction;
36
+ <N extends `${string}.${string}`>(config: CreateTranslatorConfig<DictionaryKeys> & {
37
+ namespace: N;
38
+ }): TranslateFunctionForNamespace<N>;
37
39
  (config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;
38
40
  };
39
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"createTranslator.d.ts","names":[],"sources":["../../../src/core/createTranslator.ts"],"mappings":";;;;;;AAoBA;;;;;KAAY,sBAAA,WAAiC,cAAA;EAUzC,gDARF,MAAA,EAAQ,aAAA,EAQA;EANR,SAAA,GAAY,CAAA;EAJ+B;;;;EAS3C,QAAA;AAAA,IACE,MAAA;;;;AAAwB;;;;;;KAWvB,gBAAA;EAAA,WACQ,cAAA,EACT,MAAA,EAAQ,sBAAA,CAAuB,CAAA;IAAO,SAAA,EAAW,CAAA;EAAA,IAChD,iBAAA,CAAkB,CAAA;EAAA,CAEnB,MAAA,EAAQ,sBAAA,CAAuB,cAAA;IAC7B,SAAA;EAAA,IAED,sBAAA;EAAA,CACF,MAAA,EAAQ,sBAAA,CAAuB,cAAA,IAAkB,sBAAA;AAAA;;;;;;;;;;;;;;;cAiBvC,gBAAA,EAaP,gBAAA"}
1
+ {"version":3,"file":"createTranslator.d.ts","names":[],"sources":["../../../src/core/createTranslator.ts"],"mappings":";;;;;;;;;;KAqBY,uBAAuB,UAAU;;EAE3C,QAAQ;;EAER,YAAY;;;;;EAKZ;IACE;;;;;;;;;;;KAYC;GACF,UAAU,gBACT,QAAQ,uBAAuB;IAAO,WAAW;MAChD,kBAAkB;GACpB,iCACC,QAAQ,uBAAuB;IAAoB,WAAW;MAC7D,8BAA8B;GAChC,QAAQ,uBAAuB,kBAAkB;;;;;;;;;;;;;;;;cAiBvC,kBAaP"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/core/errors.ts"],"mappings":";;AAOA;;;;;;aAAY,aAAA;EACV,eAAA;EACA,cAAA;EACA,oBAAA;EACA,iBAAA;EACA,eAAA;EACA,WAAA;EACA,gBAAA;AAAA;;;;;;;cASW,SAAA,SAAkB,KAAA;EAAA,SACb,IAAA,EAAM,aAAA;EAAA,SACN,eAAA;cAEJ,IAAA,EAAM,aAAA,EAAe,eAAA;AAAA"}
1
+ {"version":3,"file":"errors.d.ts","names":[],"sources":["../../../src/core/errors.ts"],"mappings":";;;;;;;;aAOY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;;cASW,kBAAkB;WACb,MAAM;WACN;EAEhB,YAAY,MAAM,eAAe"}
@@ -1,5 +1,4 @@
1
1
  import { hasLocale as hasLocale$1 } from "use-intl";
2
-
3
2
  //#region src/core/hasLocale.d.ts
4
3
  /**
5
4
  * Drop-in for use-intl's `hasLocale`.
@@ -1 +1 @@
1
- {"version":3,"file":"hasLocale.d.ts","names":[],"sources":["../../../src/core/hasLocale.ts"],"mappings":";;;;;AAcA;;;;;;;;;cAAa,SAAA,SAAkB,WAAA"}
1
+ {"version":3,"file":"hasLocale.d.ts","names":[],"sources":["../../../src/core/hasLocale.ts"],"mappings":";;;;;;;;;;;;;cAca,kBAAkB"}
@@ -4,4 +4,4 @@ import { IntlError, IntlErrorCode } from "./errors.js";
4
4
  import { hasLocale } from "./hasLocale.js";
5
5
  import { initializeConfig } from "./initializeConfig.js";
6
6
  import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "./types.js";
7
- export { AbstractIntlMessages, AppConfig, type CreateTranslatorConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, IntlError, IntlErrorCode, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues, createFormatter, createTranslator, hasLocale, initializeConfig };
7
+ export { type AbstractIntlMessages, type AppConfig, type CreateTranslatorConfig, type DateTimeFormatOptions, type Formats, type ICUArgs, type ICUTags, type IntlConfig, IntlError, IntlErrorCode, type Locale, type MarkupTagsFunction, type MarkupTranslationValues, type MessageKeys, type Messages, type NamespaceKeys, type NestedKeyOf, type NestedValueOf, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichTagsFunction, type RichTranslationValues, type Timezone, type TranslationValues, createFormatter, createTranslator, hasLocale, initializeConfig };
@@ -1,5 +1,4 @@
1
1
  import { initializeConfig as initializeConfig$1 } from "use-intl";
2
-
3
2
  //#region src/core/initializeConfig.d.ts
4
3
  /**
5
4
  * Drop-in for use-intl's `initializeConfig`.
@@ -1 +1 @@
1
- {"version":3,"file":"initializeConfig.d.ts","names":[],"sources":["../../../src/core/initializeConfig.ts"],"mappings":";;;;;AASA;;;;;cAAa,gBAAA,SAAyB,kBAAA"}
1
+ {"version":3,"file":"initializeConfig.d.ts","names":[],"sources":["../../../src/core/initializeConfig.ts"],"mappings":";;;;;;;;;cASa,yBAAyB"}
@@ -1,2 +1,2 @@
1
1
  import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "use-intl";
2
- export { type AbstractIntlMessages, type AppConfig, type DateTimeFormatOptions, type Formats, type ICUArgs, type ICUTags, type IntlConfig, type Locale, type MarkupTagsFunction, type MarkupTranslationValues, type MessageKeys, type Messages, type NamespaceKeys, type NestedKeyOf, type NestedValueOf, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichTagsFunction, type RichTranslationValues, type Timezone, type TranslationValues };
2
+ export type { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues };
@@ -1,14 +1,17 @@
1
+ import { IntlProvider, IntlProviderProps } from "./client/IntlProvider.js";
2
+ import { useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.js";
3
+ import { MarkupChunkRenderer, RichChunkRenderer, createDictionaryTranslator } from "./shared/namespaceTranslator.js";
4
+ import { ContentAtPath, LooseTranslateFunction, ScopedDotPaths, ScopedTranslateFunction, TranslateFunction, TranslateFunctionForNamespace, TranslatedValue } from "./shared/translateFunctionTypes.js";
5
+ import { useDictionary } from "./useDictionary.js";
6
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
7
+ import { useLocale } from "./client/useLocale.js";
8
+ import { useTranslations } from "./client/useTranslations.js";
9
+ import { _useExtracted } from "./client/index.js";
1
10
  import { createFormatter } from "./core/createFormatter.js";
2
11
  import { CreateTranslatorConfig, createTranslator } from "./core/createTranslator.js";
3
12
  import { IntlError, IntlErrorCode } from "./core/errors.js";
4
13
  import { hasLocale } from "./core/hasLocale.js";
5
14
  import { initializeConfig } from "./core/initializeConfig.js";
6
15
  import { AbstractIntlMessages, AppConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues } from "./core/types.js";
7
- import { IntlProvider, IntlProviderProps } from "./react/IntlProvider.js";
8
- import { useFormatter, useMessages, useNow, useTimeZone } from "./react/helpers.js";
9
- import { useLocale } from "./react/useLocale.js";
10
- import { useTranslations } from "./react/useTranslations.js";
11
- import { useDictionary } from "./useDictionary.js";
12
- import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
13
- import { _useExtracted } from "./react/index.js";
14
- export { AbstractIntlMessages, AppConfig, CreateTranslatorConfig, DateTimeFormatOptions, Formats, ICUArgs, ICUTags, IntlConfig, IntlError, IntlErrorCode, IntlProvider, IntlProviderProps, Locale, MarkupTagsFunction, MarkupTranslationValues, MessageKeys, Messages, NamespaceKeys, NestedKeyOf, NestedValueOf, NumberFormatOptions, RelativeTimeFormatOptions, RichTagsFunction, RichTranslationValues, Timezone, TranslationValues, _useExtracted, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
16
+ import "./core/index.js";
17
+ export { type AbstractIntlMessages, type AppConfig, type ContentAtPath, type CreateTranslatorConfig, type DateTimeFormatOptions, type Formats, type ICUArgs, type ICUTags, type IntlConfig, IntlError, IntlErrorCode, IntlProvider, type IntlProviderProps, type Locale, type LooseTranslateFunction, type MarkupChunkRenderer, type MarkupTagsFunction, type MarkupTranslationValues, type MessageKeys, type Messages, type NamespaceKeys, type NestedKeyOf, type NestedValueOf, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichChunkRenderer, type RichTagsFunction, type RichTranslationValues, type ScopedDotPaths, type ScopedTranslateFunction, type Timezone, type TranslateFunction, type TranslateFunctionForNamespace, type TranslatedValue, type TranslationValues, _useExtracted, createDictionaryTranslator, createFormatter, createTranslator, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
@@ -1,6 +1,5 @@
1
1
  import { PluginOption } from "vite";
2
2
  import { intlayer } from "vite-intlayer";
3
-
4
3
  //#region src/plugin/index.d.ts
5
4
  /**
6
5
  * A Vite plugin for use-intl compat that wraps vite-intlayer and configures
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;AA6CA;;;;;;;;;;;;cAAa,iBAAA,GACX,OAAA,GAAU,UAAA,QAAkB,QAAA,SAC3B,YAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/plugin/index.ts"],"mappings":";;;;;;;;;;;;;;;;;cAuBa,oBAAiB,UAClB,kBAAkB,iBAC3B"}
@@ -1,5 +1,4 @@
1
1
  import { createFormatter } from "use-intl";
2
-
3
2
  //#region src/shared/intlFormatter.d.ts
4
3
  /** The formatter object shape exposed by use-intl. */
5
4
  type Formatter = ReturnType<typeof createFormatter>;
@@ -1 +1 @@
1
- {"version":3,"file":"intlFormatter.d.ts","names":[],"sources":["../../../src/shared/intlFormatter.ts"],"mappings":";;;;KAGY,SAAA,GAAY,UAAA,QAAkB,eAAA;AAA1C;;;;;AA0BA;;;;;AA1BA,cA0Ba,kBAAA,GAAsB,MAAA,aAAiB,SAAA"}
1
+ {"version":3,"file":"intlFormatter.d.ts","names":[],"sources":["../../../src/shared/intlFormatter.ts"],"mappings":";;;KAGY,YAAY,kBAAkB;;;;;;;;;;;cA0B7B,qBAAkB,mBAAqB"}
@@ -1,20 +1,11 @@
1
1
  import { LocalesValues } from "@intlayer/types/module_augmentation";
2
2
  import { ReactNode } from "react";
3
- import { MessageValues } from "@intlayer/core/messageFormat";
4
-
3
+ import { MessageValues, navigatePath } from "@intlayer/core/messageFormat";
5
4
  //#region src/shared/namespaceTranslator.d.ts
6
5
  /** Chunk renderer used by `t.rich()` — maps tag children to a React node. */
7
6
  type RichChunkRenderer = (chunks: ReactNode) => ReactNode;
8
7
  /** Chunk renderer used by `t.markup()` — maps tag children to a string. */
9
8
  type MarkupChunkRenderer = (chunks: string) => string;
10
- /**
11
- * Reads a dotted `path` (e.g. `counter.label`) out of a nested object value.
12
- *
13
- * @param objectValue - The object to read from.
14
- * @param path - Dot-separated path. An empty path returns `objectValue`.
15
- * @returns The value found at `path`, or `undefined` when any segment is absent.
16
- */
17
- declare const navigatePath: (objectValue: unknown, path: string) => unknown;
18
9
  /**
19
10
  * The untyped runtime translator shared by `useTranslations` (React hook) and
20
11
  * `createTranslator` (non-React core).
@@ -32,7 +23,37 @@ declare const navigatePath: (objectValue: unknown, path: string) => unknown;
32
23
  * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
33
24
  */
34
25
  declare const createNamespaceTranslator: (locale: LocalesValues, namespace?: string) => ((key: string, values?: MessageValues) => string) & {
35
- /** Returns `true` if the given key exists in the namespace. */has: (key: string) => boolean; /** Returns the raw unprocessed content for the given key. */
26
+ /** Returns `true` if the given key exists in the namespace. */
27
+ has: (key: string) => boolean;
28
+ /** Returns the raw unprocessed content for the given key. */
29
+ raw: (key: string) => unknown;
30
+ /**
31
+ * Resolves a message containing `<tag>chunks</tag>` markup, mapping each
32
+ * tag through the matching renderer in `values`.
33
+ */
34
+ rich: (key: string, values?: Record<string, unknown>) => ReactNode;
35
+ /**
36
+ * Resolves a message containing `<tag>chunks</tag>` markup into a string,
37
+ * mapping each tag through the matching string renderer in `values`.
38
+ */
39
+ markup: (key: string, values?: Record<string, unknown>) => string;
40
+ };
41
+ /**
42
+ * Dictionary-bound translator used by the build-optimized `useDictionary` /
43
+ * `getDictionary` variants: instead of resolving the dictionary by key at
44
+ * runtime, the pre-resolved content is supplied directly (the babel/swc
45
+ * optimize pass imports the dictionary JSON at build time).
46
+ *
47
+ * @param locale - The locale messages are resolved for.
48
+ * @param content - The dictionary content, already resolved for `locale`.
49
+ * @param namespacePrefix - Optional key prefix for nested namespaces
50
+ * (`useTranslations('about.counter')` → content of `about`, prefix `counter`).
51
+ * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
52
+ */
53
+ declare const createDictionaryTranslator: (locale: LocalesValues, content: unknown, namespacePrefix?: string) => ((key: string, values?: MessageValues) => string) & {
54
+ /** Returns `true` if the given key exists in the namespace. */
55
+ has: (key: string) => boolean;
56
+ /** Returns the raw unprocessed content for the given key. */
36
57
  raw: (key: string) => unknown;
37
58
  /**
38
59
  * Resolves a message containing `<tag>chunks</tag>` markup, mapping each
@@ -47,5 +68,5 @@ declare const createNamespaceTranslator: (locale: LocalesValues, namespace?: str
47
68
  };
48
69
  type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;
49
70
  //#endregion
50
- export { CompatTranslator, MarkupChunkRenderer, RichChunkRenderer, createNamespaceTranslator, navigatePath };
71
+ export { CompatTranslator, MarkupChunkRenderer, RichChunkRenderer, createDictionaryTranslator, createNamespaceTranslator, navigatePath };
51
72
  //# sourceMappingURL=namespaceTranslator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"namespaceTranslator.d.ts","names":[],"sources":["../../../src/shared/namespaceTranslator.tsx"],"mappings":";;;;;;KAcY,iBAAA,IAAqB,MAAA,EAAQ,SAAA,KAAc,SAAA;AAAvD;AAAA,KAGY,mBAAA,IAAuB,MAAA;;;;;;;;cAStB,YAAA,GAAgB,WAAA,WAAsB,IAAA;;;;;AAAnD;;;;;AAyFA;;;;;;;cAAa,yBAAA,GACX,MAAA,EAAQ,aAAA,EACR,SAAA,gBAAkB,GAAA,UAuCY,MAAA,GAAW,aAAA;EAyBF,8FAjE/B;;EACR;;;;sBAqDoB,MAAA,GAAW,MAAA,sBAA0B,SAAA;;;;;wBAWnC,MAAA,GAAW,MAAA;AAAA;AAAA,KASvB,gBAAA,GAAmB,UAAA,QAAkB,yBAAA"}
1
+ {"version":3,"file":"namespaceTranslator.d.ts","names":[],"sources":["../../../src/shared/namespaceTranslator.tsx"],"mappings":";;;;;KAkBY,qBAAqB,QAAQ,cAAc;;KAG3C,uBAAuB;;;;;;;;;;;;;;;;;cA0EtB,4BAAyB,QAC5B,eAAa,yBACH,aAgHY,SAAW;;EAK5B,MAAA;;EAGA,MAAA;;;;;EAMC,OAAA,aAAM,SAAW,4BAA0B;;;;;EAWzC,SAAA,aAAM,SAAW;;;;;;;;;;;;;;cA/DtB,6BAA0B,QAC7B,eAAa,kBACL,+BACQ,aAmCM,SAAW;;EAK5B,MAAA;;EAGA,MAAA;;;;;EAMC,OAAA,aAAM,SAAW,4BAA0B;;;;;EAWzC,SAAA,aAAM,SAAW;;KASvB,mBAAmB,kBAAkB"}
@@ -1,9 +1,25 @@
1
1
  import { MarkupChunkRenderer, RichChunkRenderer } from "./namespaceTranslator.js";
2
2
  import { DictionaryKeys } from "@intlayer/types/module_augmentation";
3
- import { ValidDotPathsFor } from "@intlayer/core/transpiler";
4
3
  import { ReactNode } from "react";
5
-
4
+ import { GetNestingResult } from "@intlayer/core/interpreter";
5
+ import { ValidDotPathsFor } from "@intlayer/core/transpiler";
6
6
  //#region src/shared/translateFunctionTypes.d.ts
7
+ /**
8
+ * The interpreter-resolved content type at dot-path `P` of dictionary `N` —
9
+ * the same type strength as the base `useIntlayer` hook.
10
+ */
11
+ type ContentAtPath<N extends DictionaryKeys, P> = GetNestingResult<N, P>;
12
+ /**
13
+ * The value returned by `t()` for key `P` of dictionary `N`: string literals
14
+ * declared in the dictionary keep their literal type (matching the strength of
15
+ * `useIntlayer`), every other node resolves to `string` at runtime.
16
+ */
17
+ type TranslatedValue<N extends DictionaryKeys, P> = ContentAtPath<N, P> extends string ? ContentAtPath<N, P> : string;
18
+ /**
19
+ * The dot-paths of dictionary `D` relative to the nested namespace scope
20
+ * `Prefix` (`useTranslations('about.counter')` → paths under `about.counter`).
21
+ */
22
+ type ScopedDotPaths<D extends DictionaryKeys, Prefix extends string> = ValidDotPathsFor<D> extends (infer AllPaths) ? AllPaths extends `${Prefix}.${infer RelativePath}` ? RelativePath : never : never;
7
23
  /**
8
24
  * The translation function returned for a bare dictionary key namespace.
9
25
  *
@@ -15,13 +31,42 @@ import { ReactNode } from "react";
15
31
  * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.
16
32
  */
17
33
  type TranslateFunction<N extends DictionaryKeys> = {
18
- /** Translate a key to a string, with optional ICU interpolation params. */<P extends ValidDotPathsFor<N>>(key: P, params?: Record<string, unknown>): string; /** Returns `true` if the given key exists in the namespace. */
19
- has<P extends ValidDotPathsFor<N>>(key: P): boolean; /** Returns the raw unprocessed content for the given key. */
20
- raw<P extends ValidDotPathsFor<N>>(key: P): unknown; /** Resolves rich-text markup, mapping tags through React renderers. */
21
- rich<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode; /** Resolves rich-text markup, mapping tags through string renderers. */
34
+ /** Translate a key to a string, with optional ICU interpolation params. */
35
+ <P extends ValidDotPathsFor<N>>(key: P, params?: Record<string, unknown>): TranslatedValue<N, P>;
36
+ /** Returns `true` if the given key exists in the namespace. */
37
+ has<P extends ValidDotPathsFor<N>>(key: P): boolean;
38
+ /** Returns the raw unprocessed content for the given key. */
39
+ raw<P extends ValidDotPathsFor<N>>(key: P): ContentAtPath<N, P>;
40
+ /** Resolves rich-text markup, mapping tags through React renderers. */
41
+ rich<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode;
42
+ /** Resolves rich-text markup, mapping tags through string renderers. */
22
43
  markup<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
23
44
  };
24
- /** Loosely-typed function returned for nested `'dict.scope'` namespaces. */
45
+ /**
46
+ * The translation function returned for a nested `'dictionary.scope'`
47
+ * namespace: keys are relative dot-paths under the scope, and return types are
48
+ * resolved against the absolute path in the dictionary.
49
+ */
50
+ type ScopedTranslateFunction<D extends DictionaryKeys, Prefix extends string> = {
51
+ /** Translate a scoped key to a string, with optional ICU interpolation params. */
52
+ <P extends ScopedDotPaths<D, Prefix>>(key: P, params?: Record<string, unknown>): TranslatedValue<D, `${Prefix}.${P}`>;
53
+ /** Returns `true` if the given key exists in the scoped namespace. */
54
+ has<P extends ScopedDotPaths<D, Prefix>>(key: P): boolean;
55
+ /** Returns the raw unprocessed content for the given scoped key. */
56
+ raw<P extends ScopedDotPaths<D, Prefix>>(key: P): ContentAtPath<D, `${Prefix}.${P}`>;
57
+ /** Resolves rich-text markup, mapping tags through React renderers. */
58
+ rich<P extends ScopedDotPaths<D, Prefix>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode;
59
+ /** Resolves rich-text markup, mapping tags through string renderers. */
60
+ markup<P extends ScopedDotPaths<D, Prefix>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
61
+ };
62
+ /**
63
+ * Resolves the translation function type for a namespace argument: a bare
64
+ * dictionary key keeps the fully-typed dot-paths, a nested
65
+ * `'dictionary.scope'` namespace is split at the first dot and typed
66
+ * relative to the scope, anything else falls back to loose typing.
67
+ */
68
+ type TranslateFunctionForNamespace<N extends string> = N extends DictionaryKeys ? TranslateFunction<N> : N extends `${infer D extends DictionaryKeys & string}.${infer Prefix}` ? ScopedTranslateFunction<D, Prefix> : LooseTranslateFunction;
69
+ /** Loosely-typed function returned for untyped namespaces (root scope). */
25
70
  type LooseTranslateFunction = {
26
71
  (key: string, params?: Record<string, unknown>): string;
27
72
  has(key: string): boolean;
@@ -30,5 +75,5 @@ type LooseTranslateFunction = {
30
75
  markup(key: string, values?: Record<string, MarkupChunkRenderer | string | number>): string;
31
76
  };
32
77
  //#endregion
33
- export { LooseTranslateFunction, TranslateFunction };
78
+ export { ContentAtPath, LooseTranslateFunction, ScopedDotPaths, ScopedTranslateFunction, TranslateFunction, TranslateFunctionForNamespace, TranslatedValue };
34
79
  //# sourceMappingURL=translateFunctionTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateFunctionTypes.d.ts","names":[],"sources":["../../../src/shared/translateFunctionTypes.ts"],"mappings":";;;;;;;;AAkBA;;;;;;;;KAAY,iBAAA,WAA4B,cAAA;EAOxB,sFALH,gBAAA,CAAiB,CAAA,GAC1B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,4BAKoB;EAF/B,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,YAEA;EAAxC,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,YAEzB;EAAf,IAAA,WAAe,gBAAA,CAAiB,CAAA,GAC9B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA,EADuB;EAG1B,MAAA,WAAiB,gBAAA,CAAiB,CAAA,GAChC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA;;KAKhB,sBAAA;EAAA,CACT,GAAA,UAAa,MAAA,GAAS,MAAA;EACvB,GAAA,CAAI,GAAA;EACJ,GAAA,CAAI,GAAA;EACJ,IAAA,CACE,GAAA,UACA,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA;EACH,MAAA,CACE,GAAA,UACA,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA"}
1
+ {"version":3,"file":"translateFunctionTypes.d.ts","names":[],"sources":["../../../src/shared/translateFunctionTypes.ts"],"mappings":";;;;;;;;;;KAaY,cAAc,UAAU,gBAAgB,KAAK,iBAAiB,GAAG;;;;;;KAOjE,gBAAgB,UAAU,gBAAgB,KACpD,cAAc,GAAG,oBAAoB,cAAc,GAAG;;;;;KAM5C,eAAe,UAAU,gBAAgB,yBACnD,iBAAiB,kBAAiB,YAC9B,oBAAoB,gBAAgB,iBAClC;;;;;;;;;;;KAcI,kBAAkB,UAAU;;GAErC,UAAU,iBAAiB,IAC1B,KAAK,GACL,SAAS,0BACR,gBAAgB,GAAG;;EAEtB,IAAI,UAAU,iBAAiB,IAAI,KAAK;;EAExC,IAAI,UAAU,iBAAiB,IAAI,KAAK,IAAI,cAAc,GAAG;;EAE7D,KAAK,UAAU,iBAAiB,IAC9B,KAAK,GACL,SAAS,eAAe,oBAAoB,aAC3C;;EAEH,OAAO,UAAU,iBAAiB,IAChC,KAAK,GACL,SAAS,eAAe;;;;;;;KAShB,wBACV,UAAU,gBACV;;GAGC,UAAU,eAAe,GAAG,SAC3B,KAAK,GACL,SAAS,0BACR,gBAAgB,MAAM,UAAU;;EAEnC,IAAI,UAAU,eAAe,GAAG,SAAS,KAAK;;EAE9C,IAAI,UAAU,eAAe,GAAG,SAC9B,KAAK,IACJ,cAAc,MAAM,UAAU;;EAEjC,KAAK,UAAU,eAAe,GAAG,SAC/B,KAAK,GACL,SAAS,eAAe,oBAAoB,aAC3C;;EAEH,OAAO,UAAU,eAAe,GAAG,SACjC,KAAK,GACL,SAAS,eAAe;;;;;;;;KAUhB,8BAA8B,oBACxC,UAAU,iBACN,kBAAkB,KAClB,mBAAmB,UAAU,iCAAiC,WAC5D,wBAAwB,GAAG,UAC3B;;KAGI;GACT,aAAa,SAAS;EACvB,IAAI;EACJ,IAAI;EACJ,KACE,aACA,SAAS,eAAe,oBAAoB,aAC3C;EACH,OACE,aACA,SAAS,eAAe"}