@intlayer/use-intl 9.0.0-canary.2

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 (106) hide show
  1. package/README.md +330 -0
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/cjs/core/createFormatter.cjs +23 -0
  4. package/dist/cjs/core/createFormatter.cjs.map +1 -0
  5. package/dist/cjs/core/createTranslator.cjs +30 -0
  6. package/dist/cjs/core/createTranslator.cjs.map +1 -0
  7. package/dist/cjs/core/errors.cjs +42 -0
  8. package/dist/cjs/core/errors.cjs.map +1 -0
  9. package/dist/cjs/core/hasLocale.cjs +23 -0
  10. package/dist/cjs/core/hasLocale.cjs.map +1 -0
  11. package/dist/cjs/core/index.cjs +13 -0
  12. package/dist/cjs/core/initializeConfig.cjs +25 -0
  13. package/dist/cjs/core/initializeConfig.cjs.map +1 -0
  14. package/dist/cjs/core/types.cjs +0 -0
  15. package/dist/cjs/index.cjs +30 -0
  16. package/dist/cjs/plugin/index.cjs +80 -0
  17. package/dist/cjs/plugin/index.cjs.map +1 -0
  18. package/dist/cjs/react/IntlProvider.cjs +30 -0
  19. package/dist/cjs/react/IntlProvider.cjs.map +1 -0
  20. package/dist/cjs/react/helpers.cjs +49 -0
  21. package/dist/cjs/react/helpers.cjs.map +1 -0
  22. package/dist/cjs/react/index.cjs +27 -0
  23. package/dist/cjs/react/index.cjs.map +1 -0
  24. package/dist/cjs/react/useLocale.cjs +20 -0
  25. package/dist/cjs/react/useLocale.cjs.map +1 -0
  26. package/dist/cjs/react/useTranslations.cjs +39 -0
  27. package/dist/cjs/react/useTranslations.cjs.map +1 -0
  28. package/dist/cjs/shared/intlFormatter.cjs +63 -0
  29. package/dist/cjs/shared/intlFormatter.cjs.map +1 -0
  30. package/dist/cjs/shared/namespaceTranslator.cjs +122 -0
  31. package/dist/cjs/shared/namespaceTranslator.cjs.map +1 -0
  32. package/dist/cjs/shared/translateFunctionTypes.cjs +0 -0
  33. package/dist/cjs/useDictionary.cjs +37 -0
  34. package/dist/cjs/useDictionary.cjs.map +1 -0
  35. package/dist/cjs/useDictionaryDynamic.cjs +31 -0
  36. package/dist/cjs/useDictionaryDynamic.cjs.map +1 -0
  37. package/dist/esm/core/createFormatter.mjs +22 -0
  38. package/dist/esm/core/createFormatter.mjs.map +1 -0
  39. package/dist/esm/core/createTranslator.mjs +28 -0
  40. package/dist/esm/core/createTranslator.mjs.map +1 -0
  41. package/dist/esm/core/errors.mjs +39 -0
  42. package/dist/esm/core/errors.mjs.map +1 -0
  43. package/dist/esm/core/hasLocale.mjs +21 -0
  44. package/dist/esm/core/hasLocale.mjs.map +1 -0
  45. package/dist/esm/core/index.mjs +7 -0
  46. package/dist/esm/core/initializeConfig.mjs +23 -0
  47. package/dist/esm/core/initializeConfig.mjs.map +1 -0
  48. package/dist/esm/core/types.mjs +0 -0
  49. package/dist/esm/index.mjs +14 -0
  50. package/dist/esm/plugin/index.mjs +76 -0
  51. package/dist/esm/plugin/index.mjs.map +1 -0
  52. package/dist/esm/react/IntlProvider.mjs +28 -0
  53. package/dist/esm/react/IntlProvider.mjs.map +1 -0
  54. package/dist/esm/react/helpers.mjs +44 -0
  55. package/dist/esm/react/helpers.mjs.map +1 -0
  56. package/dist/esm/react/index.mjs +17 -0
  57. package/dist/esm/react/index.mjs.map +1 -0
  58. package/dist/esm/react/useLocale.mjs +18 -0
  59. package/dist/esm/react/useLocale.mjs.map +1 -0
  60. package/dist/esm/react/useTranslations.mjs +37 -0
  61. package/dist/esm/react/useTranslations.mjs.map +1 -0
  62. package/dist/esm/shared/intlFormatter.mjs +61 -0
  63. package/dist/esm/shared/intlFormatter.mjs.map +1 -0
  64. package/dist/esm/shared/namespaceTranslator.mjs +119 -0
  65. package/dist/esm/shared/namespaceTranslator.mjs.map +1 -0
  66. package/dist/esm/shared/translateFunctionTypes.mjs +0 -0
  67. package/dist/esm/useDictionary.mjs +35 -0
  68. package/dist/esm/useDictionary.mjs.map +1 -0
  69. package/dist/esm/useDictionaryDynamic.mjs +29 -0
  70. package/dist/esm/useDictionaryDynamic.mjs.map +1 -0
  71. package/dist/types/core/createFormatter.d.ts +21 -0
  72. package/dist/types/core/createFormatter.d.ts.map +1 -0
  73. package/dist/types/core/createTranslator.d.ts +56 -0
  74. package/dist/types/core/createTranslator.d.ts.map +1 -0
  75. package/dist/types/core/errors.d.ts +31 -0
  76. package/dist/types/core/errors.d.ts.map +1 -0
  77. package/dist/types/core/hasLocale.d.ts +18 -0
  78. package/dist/types/core/hasLocale.d.ts.map +1 -0
  79. package/dist/types/core/index.d.ts +7 -0
  80. package/dist/types/core/initializeConfig.d.ts +14 -0
  81. package/dist/types/core/initializeConfig.d.ts.map +1 -0
  82. package/dist/types/core/types.d.ts +2 -0
  83. package/dist/types/index.d.ts +14 -0
  84. package/dist/types/plugin/index.d.ts +22 -0
  85. package/dist/types/plugin/index.d.ts.map +1 -0
  86. package/dist/types/react/IntlProvider.d.ts +29 -0
  87. package/dist/types/react/IntlProvider.d.ts.map +1 -0
  88. package/dist/types/react/helpers.d.ts +31 -0
  89. package/dist/types/react/helpers.d.ts.map +1 -0
  90. package/dist/types/react/index.d.ts +16 -0
  91. package/dist/types/react/index.d.ts.map +1 -0
  92. package/dist/types/react/useLocale.d.ts +12 -0
  93. package/dist/types/react/useLocale.d.ts.map +1 -0
  94. package/dist/types/react/useTranslations.d.ts +44 -0
  95. package/dist/types/react/useTranslations.d.ts.map +1 -0
  96. package/dist/types/shared/intlFormatter.d.ts +19 -0
  97. package/dist/types/shared/intlFormatter.d.ts.map +1 -0
  98. package/dist/types/shared/namespaceTranslator.d.ts +51 -0
  99. package/dist/types/shared/namespaceTranslator.d.ts.map +1 -0
  100. package/dist/types/shared/translateFunctionTypes.d.ts +34 -0
  101. package/dist/types/shared/translateFunctionTypes.d.ts.map +1 -0
  102. package/dist/types/useDictionary.d.ts +23 -0
  103. package/dist/types/useDictionary.d.ts.map +1 -0
  104. package/dist/types/useDictionaryDynamic.d.ts +18 -0
  105. package/dist/types/useDictionaryDynamic.d.ts.map +1 -0
  106. package/package.json +131 -0
@@ -0,0 +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"}
File without changes
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+
3
+ import { navigatePath } from "./shared/namespaceTranslator.mjs";
4
+ import { useDictionary as useDictionary$1 } from "react-intlayer";
5
+
6
+ //#region src/useDictionary.ts
7
+ /**
8
+ * Dictionary-accepting variant of `useTranslations`.
9
+ *
10
+ * Used internally by the build-time optimization: instead of looking up the
11
+ * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
12
+ * JSON at build time and passes it directly here. This enables tree-shaking of
13
+ * unused locale content.
14
+ *
15
+ * @example (generated by the plugin, not written manually)
16
+ * import _abc from '.intlayer/dictionaries/about.json' with { type: 'json' };
17
+ * const t = useDictionary(_abc);
18
+ */
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
+ };
32
+
33
+ //#endregion
34
+ export { useDictionary };
35
+ //# sourceMappingURL=useDictionary.mjs.map
@@ -0,0 +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"}
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+
3
+ import { navigatePath } from "./shared/namespaceTranslator.mjs";
4
+ import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer";
5
+
6
+ //#region src/useDictionaryDynamic.ts
7
+ /**
8
+ * Dynamic dictionary-accepting variant of `useTranslations`.
9
+ *
10
+ * Counterpart to {@link useDictionary} for dictionaries imported lazily per
11
+ * locale. Used internally by the build-time optimization.
12
+ */
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
+ };
26
+
27
+ //#endregion
28
+ export { useDictionaryDynamic };
29
+ //# sourceMappingURL=useDictionaryDynamic.mjs.map
@@ -0,0 +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"}
@@ -0,0 +1,21 @@
1
+ import { createFormatter as createFormatter$1 } from "use-intl";
2
+
3
+ //#region src/core/createFormatter.d.ts
4
+ /**
5
+ * Drop-in for use-intl's `createFormatter`.
6
+ *
7
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs:
8
+ * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
9
+ * `displayName`. `now`, `timeZone`, `formats`, and `onError` are accepted for
10
+ * API compatibility but only `locale` influences the output.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const format = createFormatter({ locale: 'en' });
15
+ * format.number(1234.5, { style: 'currency', currency: 'USD' });
16
+ * ```
17
+ */
18
+ declare const createFormatter: typeof createFormatter$1;
19
+ //#endregion
20
+ export { createFormatter };
21
+ //# sourceMappingURL=createFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormatter.d.ts","names":[],"sources":["../../../src/core/createFormatter.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;;;cAAa,eAAA,SAAwB,iBAAA"}
@@ -0,0 +1,56 @@
1
+ import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
2
+ import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
3
+
4
+ //#region src/core/createTranslator.d.ts
5
+ /**
6
+ * Configuration accepted by {@link createTranslator}.
7
+ *
8
+ * Mirrors use-intl's `IntlConfig`, but `messages`, `formats`, `now`,
9
+ * `timeZone`, `onError`, and `getMessageFallback` have no effect — Intlayer
10
+ * resolves content from its own compiled dictionaries.
11
+ */
12
+ type CreateTranslatorConfig<N extends DictionaryKeys> = {
13
+ /** The locale dictionaries are resolved for. */locale: LocalesValues; /** A bare dictionary key, or a nested `'dictionary.scope'` namespace. */
14
+ namespace?: N | (string & {});
15
+ /**
16
+ * @deprecated has no use case with intlayer. Messages are loaded
17
+ * automatically under the hood for bundle optimization reason.
18
+ */
19
+ messages?: never;
20
+ } & Record<string, unknown>;
21
+ /**
22
+ * Overload set for {@link createTranslator}:
23
+ *
24
+ * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
25
+ * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
26
+ * `string` paths, matching use-intl's scoped-namespace behaviour.
27
+ * 3. No namespace → root scope; the first segment of each key designates
28
+ * the dictionary (`t('about.title')`).
29
+ */
30
+ type CreateTranslator = {
31
+ <N extends DictionaryKeys>(config: CreateTranslatorConfig<N> & {
32
+ namespace: N;
33
+ }): TranslateFunction<N>;
34
+ (config: CreateTranslatorConfig<DictionaryKeys> & {
35
+ namespace: `${string}.${string}`;
36
+ }): LooseTranslateFunction;
37
+ (config: CreateTranslatorConfig<DictionaryKeys>): LooseTranslateFunction;
38
+ };
39
+ /**
40
+ * Drop-in for use-intl's `createTranslator`.
41
+ *
42
+ * Returns a translate function (with `rich`, `markup`, `raw`, `has`) that
43
+ * resolves messages from Intlayer's compiled dictionaries for the given
44
+ * `locale`. Messages support ICU MessageFormat syntax.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const t = createTranslator({ locale: 'en', namespace: 'about' });
49
+ * t('counter.label'); // ✓ typed
50
+ * t('items', { count: 3 }); // ICU plural
51
+ * ```
52
+ */
53
+ declare const createTranslator: CreateTranslator;
54
+ //#endregion
55
+ export { CreateTranslatorConfig, createTranslator };
56
+ //# sourceMappingURL=createTranslator.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,31 @@
1
+ //#region src/core/errors.d.ts
2
+ /**
3
+ * Drop-in for use-intl's `IntlErrorCode` enum.
4
+ *
5
+ * Re-implemented locally (rather than re-exported) because `use-intl` is
6
+ * aliased to this package at build time, so importing its runtime value would
7
+ * be circular.
8
+ */
9
+ declare enum IntlErrorCode {
10
+ MISSING_MESSAGE = "MISSING_MESSAGE",
11
+ MISSING_FORMAT = "MISSING_FORMAT",
12
+ ENVIRONMENT_FALLBACK = "ENVIRONMENT_FALLBACK",
13
+ INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
14
+ INVALID_MESSAGE = "INVALID_MESSAGE",
15
+ INVALID_KEY = "INVALID_KEY",
16
+ FORMATTING_ERROR = "FORMATTING_ERROR"
17
+ }
18
+ /**
19
+ * Drop-in for use-intl's `IntlError`.
20
+ *
21
+ * Carries the {@link IntlErrorCode} and the original message, matching
22
+ * use-intl's error shape so consumer `onError` handlers keep working.
23
+ */
24
+ declare class IntlError extends Error {
25
+ readonly code: IntlErrorCode;
26
+ readonly originalMessage: string | undefined;
27
+ constructor(code: IntlErrorCode, originalMessage?: string);
28
+ }
29
+ //#endregion
30
+ export { IntlError, IntlErrorCode };
31
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,18 @@
1
+ import { hasLocale as hasLocale$1 } from "use-intl";
2
+
3
+ //#region src/core/hasLocale.d.ts
4
+ /**
5
+ * Drop-in for use-intl's `hasLocale`.
6
+ *
7
+ * Narrows a locale candidate to the given locales list. When the list is
8
+ * omitted, the locales configured in intlayer are used.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * if (hasLocale(['en', 'fr'], requested)) { … }
13
+ * ```
14
+ */
15
+ declare const hasLocale: typeof hasLocale$1;
16
+ //#endregion
17
+ export { hasLocale };
18
+ //# sourceMappingURL=hasLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasLocale.d.ts","names":[],"sources":["../../../src/core/hasLocale.ts"],"mappings":";;;;;AAcA;;;;;;;;;cAAa,SAAA,SAAkB,WAAA"}
@@ -0,0 +1,7 @@
1
+ import { createFormatter } from "./createFormatter.js";
2
+ import { CreateTranslatorConfig, createTranslator } from "./createTranslator.js";
3
+ import { IntlError, IntlErrorCode } from "./errors.js";
4
+ import { hasLocale } from "./hasLocale.js";
5
+ import { initializeConfig } from "./initializeConfig.js";
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 };
@@ -0,0 +1,14 @@
1
+ import { initializeConfig as initializeConfig$1 } from "use-intl";
2
+
3
+ //#region src/core/initializeConfig.d.ts
4
+ /**
5
+ * Drop-in for use-intl's `initializeConfig`.
6
+ *
7
+ * Enhances an incoming config with defaults. With intlayer, `messages` and
8
+ * `formats` are not consumed at runtime (content comes from compiled
9
+ * dictionaries) but the shape is preserved so callers keep type-checking.
10
+ */
11
+ declare const initializeConfig: typeof initializeConfig$1;
12
+ //#endregion
13
+ export { initializeConfig };
14
+ //# sourceMappingURL=initializeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeConfig.d.ts","names":[],"sources":["../../../src/core/initializeConfig.ts"],"mappings":";;;;;AASA;;;;;cAAa,gBAAA,SAAyB,kBAAA"}
@@ -0,0 +1,2 @@
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 };
@@ -0,0 +1,14 @@
1
+ import { createFormatter } from "./core/createFormatter.js";
2
+ import { CreateTranslatorConfig, createTranslator } from "./core/createTranslator.js";
3
+ import { IntlError, IntlErrorCode } from "./core/errors.js";
4
+ import { hasLocale } from "./core/hasLocale.js";
5
+ import { initializeConfig } from "./core/initializeConfig.js";
6
+ 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 };
@@ -0,0 +1,22 @@
1
+ import { PluginOption } from "vite";
2
+ import { intlayer } from "vite-intlayer";
3
+
4
+ //#region src/plugin/index.d.ts
5
+ /**
6
+ * A Vite plugin for use-intl compat that wraps vite-intlayer and configures
7
+ * resolve aliases so `use-intl` imports are served by `@intlayer/use-intl`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // vite.config.ts
12
+ * import useIntlVitePlugin from '@intlayer/use-intl/plugin';
13
+ *
14
+ * export default defineConfig({
15
+ * plugins: [useIntlVitePlugin()],
16
+ * });
17
+ * ```
18
+ */
19
+ declare const useIntlVitePlugin: (options?: Parameters<typeof intlayer>[0]) => PluginOption[];
20
+ //#endregion
21
+ export { useIntlVitePlugin as default, useIntlVitePlugin };
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,29 @@
1
+ import { IntlProvider as IntlProvider$1 } from "use-intl";
2
+ import { LocalesValues } from "@intlayer/types/module_augmentation";
3
+ import { ComponentProps } from "react";
4
+
5
+ //#region src/react/IntlProvider.d.ts
6
+ /**
7
+ * Drop-in for use-intl's `IntlProvider`.
8
+ *
9
+ * Wraps Intlayer's `IntlayerProvider`, seeding the client locale from the
10
+ * `locale` prop. `messages`, `formats`, `now`, `timeZone`, `onError`, and
11
+ * `getMessageFallback` are accepted for API compatibility but have no effect —
12
+ * Intlayer uses its own compiled dictionaries.
13
+ */
14
+ declare const IntlProvider: typeof IntlProvider$1;
15
+ /**
16
+ * Props accepted by {@link IntlProvider}. `messages` is deprecated — Intlayer
17
+ * loads content from compiled dictionaries automatically.
18
+ */
19
+ type IntlProviderProps = Omit<ComponentProps<typeof IntlProvider$1>, 'messages' | 'locale'> & {
20
+ /**
21
+ * @deprecated has no use case with intlayer. Messages are loaded
22
+ * automatically under the hood for bundle optimization reason.
23
+ */
24
+ messages?: never; /** The active locale. */
25
+ locale: LocalesValues;
26
+ };
27
+ //#endregion
28
+ export { IntlProvider, IntlProviderProps };
29
+ //# sourceMappingURL=IntlProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlProvider.d.ts","names":[],"sources":["../../../src/react/IntlProvider.tsx"],"mappings":";;;;;;;AAkBA;;;;;AAoCA;cApCa,YAAA,SAAqB,cAAA;;;;;KAoCtB,iBAAA,GAAoB,IAAA,CAC9B,cAAA,QAAsB,cAAA;EASD;;;;EAFrB,QAAA;EAEA,MAAA,EAAQ,aAAA;AAAA"}
@@ -0,0 +1,31 @@
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
4
+ /**
5
+ * Drop-in for use-intl's `useNow`.
6
+ * Returns the current `Date`. The `updateInterval` option is ignored.
7
+ */
8
+ declare const useNow: typeof useNow$1;
9
+ /**
10
+ * Drop-in for use-intl's `useTimeZone`.
11
+ * Returns the system time zone resolved from `Intl.DateTimeFormat`.
12
+ */
13
+ declare const useTimeZone: typeof useTimeZone$1;
14
+ /**
15
+ * Drop-in for use-intl's `useMessages`.
16
+ *
17
+ * @deprecated useMessages has no use case with intlayer.
18
+ * Messages are loaded automatically under the hood.
19
+ * @returns An empty object.
20
+ */
21
+ declare const useMessages: typeof useMessages$1;
22
+ /**
23
+ * Drop-in for use-intl's `useFormatter`.
24
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs:
25
+ * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
26
+ * `displayName`.
27
+ */
28
+ declare const useFormatter: typeof useFormatter$1;
29
+ //#endregion
30
+ export { useFormatter, useMessages, useNow, useTimeZone };
31
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/react/helpers.ts"],"mappings":";;;;;AAkBA;;cAAa,MAAA,SAAe,QAAA;;;AAM5B;;cAAa,WAAA,SAAoB,aAAA;;;AAUjC;;;;;cAAa,WAAA,SAAoB,aAAA;;;;;;;cAiBpB,YAAA,SAAqB,cAAA"}
@@ -0,0 +1,16 @@
1
+ import { IntlProvider, IntlProviderProps } from "./IntlProvider.js";
2
+ import { useFormatter, useMessages, useNow, useTimeZone } from "./helpers.js";
3
+ import { useLocale } from "./useLocale.js";
4
+ import { useTranslations } from "./useTranslations.js";
5
+ import { useDictionary } from "../useDictionary.js";
6
+ import { useDictionaryDynamic } from "../useDictionaryDynamic.js";
7
+
8
+ //#region src/react/index.d.ts
9
+ /**
10
+ * @internal Private use-intl export, kept so aliased `_useExtracted` imports
11
+ * resolve. Not part of the supported public surface.
12
+ */
13
+ declare const _useExtracted: () => Record<string, never>;
14
+ //#endregion
15
+ export { IntlProvider, type IntlProviderProps, _useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/react/index.ts"],"mappings":";;;;;;;;;;AAWA;;cAAa,aAAA,QAAoB,MAAA"}
@@ -0,0 +1,12 @@
1
+ import { useLocale as useLocale$1 } from "use-intl";
2
+
3
+ //#region src/react/useLocale.d.ts
4
+ /**
5
+ * Drop-in for use-intl's `useLocale`.
6
+ *
7
+ * Returns the active locale string from Intlayer's client context.
8
+ */
9
+ declare const useLocale: typeof useLocale$1;
10
+ //#endregion
11
+ export { useLocale };
12
+ //# sourceMappingURL=useLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/react/useLocale.ts"],"mappings":";;;;;AAUA;;;cAAa,SAAA,SAAkB,WAAA"}
@@ -0,0 +1,44 @@
1
+ import { LooseTranslateFunction, TranslateFunction } from "../shared/translateFunctionTypes.js";
2
+ import { DictionaryKeys } from "@intlayer/types/module_augmentation";
3
+
4
+ //#region src/react/useTranslations.d.ts
5
+ /**
6
+ * Overload set for {@link useTranslations}:
7
+ *
8
+ * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).
9
+ * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative
10
+ * `string` paths, matching use-intl's scoped-namespace behaviour.
11
+ * 3. No namespace → root scope; the first segment of each key designates
12
+ * the dictionary (`t('about.title')`).
13
+ */
14
+ type UseTranslations = {
15
+ <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;
16
+ (namespace: `${string}.${string}`): LooseTranslateFunction;
17
+ (): LooseTranslateFunction;
18
+ };
19
+ /**
20
+ * Drop-in for use-intl's `useTranslations`.
21
+ *
22
+ * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
23
+ * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
24
+ * arguments (`{value, number}`). Rich text is available through `t.rich()`
25
+ * and `t.markup()`.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * const t = useTranslations('about');
30
+ * t('counter.label'); // ✓ typed
31
+ * t('items', { count: 3 }); // ICU plural
32
+ *
33
+ * // Scoped to a nested object (use-intl idiom)
34
+ * const t = useTranslations('about.counter');
35
+ * t('label'); // resolves about → counter.label
36
+ *
37
+ * // Rich text
38
+ * t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
39
+ * ```
40
+ */
41
+ declare const useTranslations: UseTranslations;
42
+ //#endregion
43
+ export { useTranslations };
44
+ //# sourceMappingURL=useTranslations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.d.ts","names":[],"sources":["../../../src/react/useTranslations.ts"],"mappings":";;;;;;AAY0C;;;;;;;KAWrC,eAAA;EAAA,WACQ,cAAA,EAAgB,SAAA,EAAW,CAAA,GAAI,iBAAA,CAAkB,CAAA;EAAA,CAC3D,SAAA,0BAAmC,sBAAA;EAAA,IAChC,sBAAA;AAAA;;;;;;;;;;;AAyBN;;;;;;;;;;;;cAAa,eAAA,EAOP,eAAA"}
@@ -0,0 +1,19 @@
1
+ import { createFormatter } from "use-intl";
2
+
3
+ //#region src/shared/intlFormatter.d.ts
4
+ /** The formatter object shape exposed by use-intl. */
5
+ type Formatter = ReturnType<typeof createFormatter>;
6
+ /**
7
+ * Builds a use-intl compatible formatter backed by the native `Intl.*` APIs
8
+ * for the given locale.
9
+ *
10
+ * Shared by `useFormatter` (React hook) and `createFormatter` (non-React core).
11
+ *
12
+ * @param locale - The locale used by every `Intl.*` formatter instance.
13
+ * @returns A formatter exposing `dateTime`, `number`, `dateTimeRange`,
14
+ * `relativeTime`, `list`, and `displayName`.
15
+ */
16
+ declare const buildIntlFormatter: (locale: string) => Formatter;
17
+ //#endregion
18
+ export { Formatter, buildIntlFormatter };
19
+ //# sourceMappingURL=intlFormatter.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,51 @@
1
+ import { LocalesValues } from "@intlayer/types/module_augmentation";
2
+ import { ReactNode } from "react";
3
+ import { MessageValues } from "@intlayer/core/messageFormat";
4
+
5
+ //#region src/shared/namespaceTranslator.d.ts
6
+ /** Chunk renderer used by `t.rich()` — maps tag children to a React node. */
7
+ type RichChunkRenderer = (chunks: ReactNode) => ReactNode;
8
+ /** Chunk renderer used by `t.markup()` — maps tag children to a string. */
9
+ 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
+ /**
19
+ * The untyped runtime translator shared by `useTranslations` (React hook) and
20
+ * `createTranslator` (non-React core).
21
+ *
22
+ * Behaviour matches use-intl / next-intl:
23
+ * - namespace `'about'` → keys resolved inside the `about` dictionary
24
+ * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
25
+ * - no namespace → the first segment of each key is the dictionary key
26
+ * - messages support ICU syntax (plural, select, `#`, formatted arguments)
27
+ * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
28
+ * renderers; `t.raw` returns the raw value; `t.has` checks existence
29
+ *
30
+ * @param locale - The locale dictionaries are resolved for.
31
+ * @param namespace - Optional dictionary key, optionally with a nested scope.
32
+ * @returns A translate function augmented with `has`, `raw`, `rich`, `markup`.
33
+ */
34
+ 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. */
36
+ raw: (key: string) => unknown;
37
+ /**
38
+ * Resolves a message containing `<tag>chunks</tag>` markup, mapping each
39
+ * tag through the matching renderer in `values`.
40
+ */
41
+ rich: (key: string, values?: Record<string, unknown>) => ReactNode;
42
+ /**
43
+ * Resolves a message containing `<tag>chunks</tag>` markup into a string,
44
+ * mapping each tag through the matching string renderer in `values`.
45
+ */
46
+ markup: (key: string, values?: Record<string, unknown>) => string;
47
+ };
48
+ type CompatTranslator = ReturnType<typeof createNamespaceTranslator>;
49
+ //#endregion
50
+ export { CompatTranslator, MarkupChunkRenderer, RichChunkRenderer, createNamespaceTranslator, navigatePath };
51
+ //# sourceMappingURL=namespaceTranslator.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,34 @@
1
+ import { MarkupChunkRenderer, RichChunkRenderer } from "./namespaceTranslator.js";
2
+ import { DictionaryKeys } from "@intlayer/types/module_augmentation";
3
+ import { ValidDotPathsFor } from "@intlayer/core/transpiler";
4
+ import { ReactNode } from "react";
5
+
6
+ //#region src/shared/translateFunctionTypes.d.ts
7
+ /**
8
+ * The translation function returned for a bare dictionary key namespace.
9
+ *
10
+ * `key` is validated against the dictionary's dot-paths. Beyond the call
11
+ * signature, the function exposes:
12
+ * - `has(key)` — returns `true` when the key exists in the namespace.
13
+ * - `raw(key)` — returns the unprocessed content value.
14
+ * - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.
15
+ * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.
16
+ */
17
+ 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. */
22
+ markup<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
23
+ };
24
+ /** Loosely-typed function returned for nested `'dict.scope'` namespaces. */
25
+ type LooseTranslateFunction = {
26
+ (key: string, params?: Record<string, unknown>): string;
27
+ has(key: string): boolean;
28
+ raw(key: string): unknown;
29
+ rich(key: string, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode;
30
+ markup(key: string, values?: Record<string, MarkupChunkRenderer | string | number>): string;
31
+ };
32
+ //#endregion
33
+ export { LooseTranslateFunction, TranslateFunction };
34
+ //# sourceMappingURL=translateFunctionTypes.d.ts.map
@@ -0,0 +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"}