@intlayer/next-intl 9.0.0-canary.2 → 9.0.0-canary.3

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 (109) hide show
  1. package/dist/cjs/client/NextIntlClientProvider.cjs +1 -1
  2. package/dist/cjs/client/index.cjs +56 -13
  3. package/dist/cjs/index.cjs +92 -15
  4. package/dist/cjs/navigation/Link.cjs +1 -1
  5. package/dist/cjs/server/getRequestConfig.cjs +28 -0
  6. package/dist/cjs/server/getRequestConfig.cjs.map +1 -0
  7. package/dist/cjs/server/getTranslations.cjs +9 -4
  8. package/dist/cjs/server/getTranslations.cjs.map +1 -1
  9. package/dist/cjs/server/helpers.cjs +5 -3
  10. package/dist/cjs/server/helpers.cjs.map +1 -1
  11. package/dist/cjs/server/index.cjs +5 -1
  12. package/dist/cjs/server/setRequestLocale.cjs +30 -0
  13. package/dist/cjs/server/setRequestLocale.cjs.map +1 -0
  14. package/dist/esm/client/NextIntlClientProvider.mjs +1 -1
  15. package/dist/esm/client/index.mjs +1 -4
  16. package/dist/esm/index.mjs +3 -6
  17. package/dist/esm/navigation/Link.mjs +1 -1
  18. package/dist/esm/server/getRequestConfig.mjs +25 -0
  19. package/dist/esm/server/getRequestConfig.mjs.map +1 -0
  20. package/dist/esm/server/getTranslations.mjs +8 -4
  21. package/dist/esm/server/getTranslations.mjs.map +1 -1
  22. package/dist/esm/server/helpers.mjs +4 -3
  23. package/dist/esm/server/helpers.mjs.map +1 -1
  24. package/dist/esm/server/index.mjs +3 -1
  25. package/dist/esm/server/setRequestLocale.mjs +28 -0
  26. package/dist/esm/server/setRequestLocale.mjs.map +1 -0
  27. package/dist/types/client/index.d.ts +1 -4
  28. package/dist/types/index.d.ts +3 -6
  29. package/dist/types/server/getRequestConfig.d.ts +19 -0
  30. package/dist/types/server/getRequestConfig.d.ts.map +1 -0
  31. package/dist/types/server/getTranslations.d.ts +7 -29
  32. package/dist/types/server/getTranslations.d.ts.map +1 -1
  33. package/dist/types/server/helpers.d.ts +2 -1
  34. package/dist/types/server/helpers.d.ts.map +1 -1
  35. package/dist/types/server/index.d.ts +3 -1
  36. package/dist/types/server/setRequestLocale.d.ts +23 -0
  37. package/dist/types/server/setRequestLocale.d.ts.map +1 -0
  38. package/package.json +9 -8
  39. package/dist/cjs/client/helpers.cjs +0 -66
  40. package/dist/cjs/client/helpers.cjs.map +0 -1
  41. package/dist/cjs/client/useTranslations.cjs +0 -39
  42. package/dist/cjs/client/useTranslations.cjs.map +0 -1
  43. package/dist/cjs/createFormatter.cjs +0 -59
  44. package/dist/cjs/createFormatter.cjs.map +0 -1
  45. package/dist/cjs/createTranslator.cjs +0 -111
  46. package/dist/cjs/createTranslator.cjs.map +0 -1
  47. package/dist/cjs/getTranslationsDictionary.cjs +0 -31
  48. package/dist/cjs/getTranslationsDictionary.cjs.map +0 -1
  49. package/dist/cjs/getTranslationsDictionaryDynamic.cjs +0 -27
  50. package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +0 -1
  51. package/dist/cjs/hasLocale.cjs +0 -25
  52. package/dist/cjs/hasLocale.cjs.map +0 -1
  53. package/dist/cjs/package.cjs +0 -122
  54. package/dist/cjs/package.cjs.map +0 -1
  55. package/dist/cjs/useDictionary.cjs +0 -45
  56. package/dist/cjs/useDictionary.cjs.map +0 -1
  57. package/dist/cjs/useDictionaryDynamic.cjs +0 -37
  58. package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
  59. package/dist/cjs/useTranslationsDictionary.cjs +0 -37
  60. package/dist/cjs/useTranslationsDictionary.cjs.map +0 -1
  61. package/dist/cjs/useTranslationsDictionaryDynamic.cjs +0 -29
  62. package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +0 -1
  63. package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
  64. package/dist/esm/client/helpers.mjs +0 -59
  65. package/dist/esm/client/helpers.mjs.map +0 -1
  66. package/dist/esm/client/useTranslations.mjs +0 -37
  67. package/dist/esm/client/useTranslations.mjs.map +0 -1
  68. package/dist/esm/createFormatter.mjs +0 -57
  69. package/dist/esm/createFormatter.mjs.map +0 -1
  70. package/dist/esm/createTranslator.mjs +0 -108
  71. package/dist/esm/createTranslator.mjs.map +0 -1
  72. package/dist/esm/getTranslationsDictionary.mjs +0 -29
  73. package/dist/esm/getTranslationsDictionary.mjs.map +0 -1
  74. package/dist/esm/getTranslationsDictionaryDynamic.mjs +0 -25
  75. package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +0 -1
  76. package/dist/esm/hasLocale.mjs +0 -23
  77. package/dist/esm/hasLocale.mjs.map +0 -1
  78. package/dist/esm/package.mjs +0 -119
  79. package/dist/esm/package.mjs.map +0 -1
  80. package/dist/esm/useDictionary.mjs +0 -43
  81. package/dist/esm/useDictionary.mjs.map +0 -1
  82. package/dist/esm/useDictionaryDynamic.mjs +0 -35
  83. package/dist/esm/useDictionaryDynamic.mjs.map +0 -1
  84. package/dist/esm/useTranslationsDictionary.mjs +0 -35
  85. package/dist/esm/useTranslationsDictionary.mjs.map +0 -1
  86. package/dist/esm/useTranslationsDictionaryDynamic.mjs +0 -27
  87. package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +0 -1
  88. package/dist/types/client/helpers.d.ts +0 -45
  89. package/dist/types/client/helpers.d.ts.map +0 -1
  90. package/dist/types/client/useTranslations.d.ts +0 -74
  91. package/dist/types/client/useTranslations.d.ts.map +0 -1
  92. package/dist/types/createFormatter.d.ts +0 -15
  93. package/dist/types/createFormatter.d.ts.map +0 -1
  94. package/dist/types/createTranslator.d.ts +0 -40
  95. package/dist/types/createTranslator.d.ts.map +0 -1
  96. package/dist/types/getTranslationsDictionary.d.ts +0 -15
  97. package/dist/types/getTranslationsDictionary.d.ts.map +0 -1
  98. package/dist/types/getTranslationsDictionaryDynamic.d.ts +0 -12
  99. package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +0 -1
  100. package/dist/types/hasLocale.d.ts +0 -20
  101. package/dist/types/hasLocale.d.ts.map +0 -1
  102. package/dist/types/useDictionary.d.ts +0 -22
  103. package/dist/types/useDictionary.d.ts.map +0 -1
  104. package/dist/types/useDictionaryDynamic.d.ts +0 -15
  105. package/dist/types/useDictionaryDynamic.d.ts.map +0 -1
  106. package/dist/types/useTranslationsDictionary.d.ts +0 -19
  107. package/dist/types/useTranslationsDictionary.d.ts.map +0 -1
  108. package/dist/types/useTranslationsDictionaryDynamic.d.ts +0 -12
  109. package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +0 -1
@@ -1,7 +1,4 @@
1
1
  import { NextIntlClientProvider, NextIntlClientProviderProps } from "./NextIntlClientProvider.js";
2
- import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./helpers.js";
3
- import { useDictionary } from "../useDictionary.js";
4
- import { useDictionaryDynamic } from "../useDictionaryDynamic.js";
5
2
  import { useLocale } from "./useLocale.js";
6
- import { useTranslations } from "./useTranslations.js";
3
+ import { IntlProvider, _useExtracted as useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "@intlayer/use-intl";
7
4
  export { IntlProvider, NextIntlClientProvider, type NextIntlClientProviderProps, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
@@ -1,9 +1,6 @@
1
1
  import { NextIntlClientProvider, NextIntlClientProviderProps } from "./client/NextIntlClientProvider.js";
2
- import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./client/helpers.js";
3
- import { useDictionary } from "./useDictionary.js";
4
- import { useDictionaryDynamic } from "./useDictionaryDynamic.js";
5
2
  import { useLocale } from "./client/useLocale.js";
6
- import { useTranslations } from "./client/useTranslations.js";
7
- import { hasLocale } from "./hasLocale.js";
3
+ import { IntlProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "./client/index.js";
8
4
  import { Routing, defineRouting } from "./routing.js";
9
- export { IntlProvider, NextIntlClientProvider, NextIntlClientProviderProps, type Routing, defineRouting, hasLocale, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
5
+ import { IntlError, IntlErrorCode, createFormatter, createTranslator, hasLocale, initializeConfig } from "@intlayer/use-intl";
6
+ export { IntlError, IntlErrorCode, IntlProvider, NextIntlClientProvider, NextIntlClientProviderProps, type Routing, createFormatter, createTranslator, defineRouting, hasLocale, initializeConfig, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
@@ -0,0 +1,19 @@
1
+ import { getRequestConfig as getRequestConfig$1 } from "next-intl/server";
2
+
3
+ //#region src/server/getRequestConfig.d.ts
4
+ /**
5
+ * Drop-in for next-intl's `getRequestConfig`.
6
+ *
7
+ * In next-intl this registers the per-request config (locale + messages) read
8
+ * by its own plugin. With intlayer the locale is resolved from routing /
9
+ * storage and messages come from compiled dictionaries, so the returned config
10
+ * is never consumed — this is an identity passthrough kept so existing
11
+ * `i18n/request.ts` files keep resolving and type-checking.
12
+ *
13
+ * @deprecated getRequestConfig has no use case with intlayer. The locale and
14
+ * messages are resolved automatically; the file can be removed.
15
+ */
16
+ declare const getRequestConfig: typeof getRequestConfig$1;
17
+ //#endregion
18
+ export { getRequestConfig as default, getRequestConfig };
19
+ //# sourceMappingURL=getRequestConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRequestConfig.d.ts","names":[],"sources":["../../../src/server/getRequestConfig.ts"],"mappings":";;;;;AAiBA;;;;;;;;;;cAAa,gBAAA,SAAyB,kBAAA"}
@@ -1,7 +1,5 @@
1
- import { MarkupChunkRenderer, RichChunkRenderer } from "../createTranslator.js";
2
1
  import { DictionaryKeys, LocalesValues } from "@intlayer/types/module_augmentation";
3
- import { ReactNode } from "react";
4
- import { ValidDotPathsFor } from "@intlayer/core/transpiler";
2
+ import { LooseTranslateFunction, TranslateFunction } from "@intlayer/use-intl";
5
3
 
6
4
  //#region src/server/getTranslations.d.ts
7
5
  /**
@@ -11,30 +9,6 @@ type GetTranslationsOptions<N extends DictionaryKeys> = {
11
9
  /** The dictionary namespace to scope translations to. */namespace?: N; /** Override the locale instead of reading it from the current request. */
12
10
  locale?: LocalesValues;
13
11
  };
14
- /**
15
- * The translation function returned by {@link getTranslations}.
16
- *
17
- * Beyond the plain call signature, the function exposes:
18
- * - `has(key)` — returns `true` when the key exists in the namespace.
19
- * - `raw(key)` — returns the unprocessed message value.
20
- * - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.
21
- * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.
22
- */
23
- type TranslateFunction<N extends DictionaryKeys> = {
24
- /** 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. */
25
- has<P extends ValidDotPathsFor<N>>(key: P): boolean; /** Returns the raw unprocessed message for the given key. */
26
- raw<P extends ValidDotPathsFor<N>>(key: P): unknown; /** Resolves rich-text markup, mapping tags through React renderers. */
27
- rich<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode; /** Resolves rich-text markup, mapping tags through string renderers. */
28
- markup<P extends ValidDotPathsFor<N>>(key: P, values?: Record<string, MarkupChunkRenderer | string | number>): string;
29
- };
30
- /** Loosely-typed function returned for nested `'dict.scope'` namespaces. */
31
- type LooseTranslateFunction = {
32
- (key: string, params?: Record<string, unknown>): string;
33
- has(key: string): boolean;
34
- raw(key: string): unknown;
35
- rich(key: string, values?: Record<string, RichChunkRenderer | ReactNode>): ReactNode;
36
- markup(key: string, values?: Record<string, MarkupChunkRenderer | string | number>): string;
37
- };
38
12
  /**
39
13
  * Overload set for {@link getTranslations}:
40
14
  *
@@ -45,6 +19,9 @@ type LooseTranslateFunction = {
45
19
  * `string` paths, matching next-intl's scoped-namespace behaviour.
46
20
  * 4. No namespace → root scope; the first segment of each key designates
47
21
  * the dictionary (`t('about.title')`).
22
+ *
23
+ * The translate function shape (`t`, `t.rich`, `t.markup`, `t.raw`, `t.has`)
24
+ * is shared with `@intlayer/use-intl`.
48
25
  */
49
26
  type GetTranslations = {
50
27
  <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;
@@ -60,8 +37,9 @@ type GetTranslations = {
60
37
  * arguments (`{value, number}`). Rich text is available through `t.rich()`
61
38
  * and `t.markup()`.
62
39
  *
63
- * Also accepts an options object `{ namespace, locale }` to match next-intl's
64
- * full server API surface.
40
+ * Resolves the active locale from the current request (or the `locale` option)
41
+ * and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime
42
+ * that backs the client `useTranslations`.
65
43
  *
66
44
  * @example
67
45
  * ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslations.d.ts","names":[],"sources":["../../../src/server/getTranslations.ts"],"mappings":";;;;;;;;AAU6B;KAMxB,sBAAA,WAAiC,cAAA;EAAX,yDAEzB,SAAA,GAAY,CAAA,EAAA;EAEZ,MAAA,GAAS,aAAA;AAAA;;;;;;;;;;KAYN,iBAAA,WAA4B,cAAA;EAAX,sFAET,gBAAA,CAAiB,CAAA,GAC1B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,4BAJoB;EAO/B,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,YAL7B;EAOX,GAAA,WAAc,gBAAA,CAAiB,CAAA,GAAI,GAAA,EAAK,CAAA,YAL7B;EAOX,IAAA,WAAe,gBAAA,CAAiB,CAAA,GAC9B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,iBAAA,GAAoB,SAAA,IAC3C,SAAA,EAPW;EASd,MAAA,WAAiB,gBAAA,CAAiB,CAAA,GAChC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,MAAA,SAAe,mBAAA;AAAA;;KAKvB,sBAAA;EAAA,CACF,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;;;;;;;;;;;;KAevB,eAAA;EAAA,WACQ,cAAA,EAAgB,SAAA,EAAW,CAAA,GAAI,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAAA,WACzD,cAAA,EACT,OAAA,EAAS,sBAAA,CAAuB,CAAA,IAC/B,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAAA,CAC5B,SAAA,0BAAmC,OAAA,CAAQ,sBAAA;EAAA,IACxC,OAAA,CAAQ,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BD,eAAA,EAAiB,eAAA"}
1
+ {"version":3,"file":"getTranslations.d.ts","names":[],"sources":["../../../src/server/getTranslations.ts"],"mappings":";;;;;;AAQ4B;KAMvB,sBAAA,WAAiC,cAAA;EAAX,yDAEzB,SAAA,GAAY,CAAA,EAAA;EAEZ,MAAA,GAAS,aAAA;AAAA;;;;;;;;;;AAAa;;;;;KAiBnB,eAAA;EAAA,WACQ,cAAA,EAAgB,SAAA,EAAW,CAAA,GAAI,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAAA,WACzD,cAAA,EACT,OAAA,EAAS,sBAAA,CAAuB,CAAA,IAC/B,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAAA,CAC5B,SAAA,0BAAmC,OAAA,CAAQ,sBAAA;EAAA,IACxC,OAAA,CAAQ,sBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BD,eAAA,EAAiB,eAAA"}
@@ -3,7 +3,8 @@ import { getFormatter as getFormatter$1, getNow as getNow$1, getTimeZone as getT
3
3
  //#region src/server/helpers.d.ts
4
4
  /**
5
5
  * Drop-in for next-intl's server `getFormatter()`.
6
- * Returns locale-aware formatters backed by the native `Intl.*` APIs.
6
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs,
7
+ * built by `@intlayer/use-intl`'s `createFormatter`.
7
8
  */
8
9
  declare const getFormatter: typeof getFormatter$1;
9
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/server/helpers.ts"],"mappings":";;;;;AAYA;;cAAa,YAAA,SAAqB,cAAA;;;AAWlC;;cAAa,MAAA,SAAe,QAAA;;;AAO5B;;cAAa,WAAA,SAAoB,aAAA"}
1
+ {"version":3,"file":"helpers.d.ts","names":[],"sources":["../../../src/server/helpers.ts"],"mappings":";;;;;AAaA;;;cAAa,YAAA,SAAqB,cAAA;;AAWlC;;;cAAa,MAAA,SAAe,QAAA;;AAO5B;;;cAAa,WAAA,SAAoB,aAAA"}
@@ -2,7 +2,9 @@ import { getDictionary } from "../getDictionary.js";
2
2
  import { getDictionaryDynamic } from "../getDictionaryDynamic.js";
3
3
  import { getLocale } from "./getLocale.js";
4
4
  import { getMessages } from "./getMessages.js";
5
+ import getRequestConfig from "./getRequestConfig.js";
5
6
  import { getTranslations } from "./getTranslations.js";
6
7
  import { getFormatter, getNow, getTimeZone } from "./helpers.js";
7
8
  import { setLocale } from "./setLocale.js";
8
- export { getDictionary, getDictionaryDynamic, getFormatter, getLocale, getMessages, getNow, getTimeZone, getTranslations, setLocale };
9
+ import { setRequestLocale } from "./setRequestLocale.js";
10
+ export { getDictionary, getDictionaryDynamic, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setLocale, setRequestLocale };
@@ -0,0 +1,23 @@
1
+ import { setRequestLocale as setRequestLocale$1 } from "next-intl/server";
2
+
3
+ //#region src/server/setRequestLocale.d.ts
4
+ /**
5
+ * Drop-in for next-intl's `setRequestLocale`.
6
+ *
7
+ * In next-intl this stores the locale in a request-scoped cache to opt into
8
+ * static rendering. Intlayer resolves the active locale from the configured
9
+ * `routing.storage` (cookie / header) or the localized route segment, so there
10
+ * is nothing to set here — this is a no-op kept for API compatibility.
11
+ *
12
+ * @deprecated setRequestLocale has no use case with intlayer. The locale is
13
+ * resolved automatically from routing / storage.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * setRequestLocale(locale); // safe to keep, but has no effect
18
+ * ```
19
+ */
20
+ declare const setRequestLocale: typeof setRequestLocale$1;
21
+ //#endregion
22
+ export { setRequestLocale };
23
+ //# sourceMappingURL=setRequestLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setRequestLocale.d.ts","names":[],"sources":["../../../src/server/setRequestLocale.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;;;cAAa,gBAAA,SAAyB,kBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/next-intl",
3
- "version": "9.0.0-canary.2",
3
+ "version": "9.0.0-canary.3",
4
4
  "private": false,
5
5
  "description": "next-intl API adapter for intlayer — useTranslations, useLocale, getTranslations, getLocale, NextIntlClientProvider backed by next-intlayer",
6
6
  "keywords": [
@@ -110,13 +110,14 @@
110
110
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
111
111
  },
112
112
  "dependencies": {
113
- "@intlayer/chokidar": "9.0.0-canary.2",
114
- "@intlayer/config": "9.0.0-canary.2",
115
- "@intlayer/core": "9.0.0-canary.2",
116
- "@intlayer/dictionaries-entry": "9.0.0-canary.2",
117
- "@intlayer/types": "9.0.0-canary.2",
118
- "next-intlayer": "9.0.0-canary.2",
119
- "react-intlayer": "9.0.0-canary.2"
113
+ "@intlayer/chokidar": "9.0.0-canary.3",
114
+ "@intlayer/config": "9.0.0-canary.3",
115
+ "@intlayer/core": "9.0.0-canary.3",
116
+ "@intlayer/dictionaries-entry": "9.0.0-canary.3",
117
+ "@intlayer/types": "9.0.0-canary.3",
118
+ "@intlayer/use-intl": "9.0.0-canary.3",
119
+ "next-intlayer": "9.0.0-canary.3",
120
+ "react-intlayer": "9.0.0-canary.3"
120
121
  },
121
122
  "devDependencies": {
122
123
  "@types/node": "25.9.3",
@@ -1,66 +0,0 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_createFormatter = require('../createFormatter.cjs');
6
- let _intlayer_config_built = require("@intlayer/config/built");
7
- let next_intlayer = require("next-intlayer");
8
- let react_jsx_runtime = require("react/jsx-runtime");
9
- let _intlayer_config_colors = require("@intlayer/config/colors");
10
- let _intlayer_config_logger = require("@intlayer/config/logger");
11
-
12
- //#region src/client/helpers.tsx
13
- /**
14
- * Drop-in for next-intl's `useNow`.
15
- * Returns the current `Date`. The `updateInterval` option is ignored.
16
- */
17
- const useNow = () => /* @__PURE__ */ new Date();
18
- /**
19
- * Drop-in for next-intl's `useTimeZone`.
20
- * Returns the system time zone resolved from `Intl.DateTimeFormat`.
21
- */
22
- const useTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
23
- /**
24
- * Drop-in for next-intl's `useMessages`.
25
- *
26
- * @deprecated useMessages has no use case with intlayer.
27
- * Messages are loaded automatically under the hood.
28
- * @returns An empty object.
29
- */
30
- const useMessages = () => {
31
- if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("useMessages", _intlayer_config_colors.CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
32
- return {};
33
- };
34
- /**
35
- * Drop-in for next-intl's `useFormatter`.
36
- * Returns locale-aware formatters backed by the native `Intl.*` APIs:
37
- * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and
38
- * `displayName`.
39
- */
40
- const useFormatter = () => {
41
- const { locale } = (0, next_intlayer.useLocale)();
42
- return require_createFormatter.createFormatter(locale ?? "en");
43
- };
44
- /**
45
- * Drop-in for next-intl's `IntlProvider`.
46
- * Renders children as-is — Intlayer provides its own context via
47
- * `IntlayerClientProvider`.
48
- *
49
- * @deprecated IntlProvider has no use case with intlayer.
50
- * Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.
51
- */
52
- const IntlProvider = ({ children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children });
53
- /**
54
- * @internal Not part of the public next-intl API surface; provided for
55
- * internal compatibility shims only.
56
- */
57
- const useExtracted = (..._args) => ({});
58
-
59
- //#endregion
60
- exports.IntlProvider = IntlProvider;
61
- exports.useExtracted = useExtracted;
62
- exports.useFormatter = useFormatter;
63
- exports.useMessages = useMessages;
64
- exports.useNow = useNow;
65
- exports.useTimeZone = useTimeZone;
66
- //# sourceMappingURL=helpers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.cjs","names":["CYAN","createFormatter"],"sources":["../../../src/client/helpers.tsx"],"sourcesContent":["'use client';\n\nimport { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type {\n IntlProvider as _IntlProvider,\n useFormatter as _useFormatter,\n useMessages as _useMessages,\n useNow as _useNow,\n useTimeZone as _useTimeZone,\n} from 'next-intl';\nimport { useLocale } from 'next-intlayer';\nimport type * as React from 'react';\nimport { createFormatter } from '../createFormatter';\n\n/**\n * Drop-in for next-intl's `useNow`.\n * Returns the current `Date`. The `updateInterval` option is ignored.\n */\nexport const useNow: typeof _useNow = () => new Date();\n\n/**\n * Drop-in for next-intl's `useTimeZone`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const useTimeZone: typeof _useTimeZone = () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n/**\n * Drop-in for next-intl's `useMessages`.\n *\n * @deprecated useMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood.\n * @returns An empty object.\n */\nexport const useMessages: typeof _useMessages = () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('useMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {} as ReturnType<typeof _useMessages>;\n};\n\n/**\n * Drop-in for next-intl's `useFormatter`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs:\n * `dateTime`, `number`, `dateTimeRange`, `relativeTime`, `list`, and\n * `displayName`.\n */\nexport const useFormatter: typeof _useFormatter = () => {\n const { locale } = useLocale();\n return createFormatter((locale as string) ?? 'en');\n};\n\ninterface ProviderProps {\n children?: React.ReactNode;\n [key: string]: unknown;\n}\n\n/**\n * Drop-in for next-intl's `IntlProvider`.\n * Renders children as-is — Intlayer provides its own context via\n * `IntlayerClientProvider`.\n *\n * @deprecated IntlProvider has no use case with intlayer.\n * Use `IntlayerClientProvider` or `NextIntlClientProvider` instead.\n */\nexport const IntlProvider: typeof _IntlProvider = ({\n children,\n}: ProviderProps) => <>{children}</>;\n\n/**\n * @internal Not part of the public next-intl API surface; provided for\n * internal compatibility shims only.\n */\nexport const useExtracted = (..._args: unknown[]) => ({});\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAa,+BAA+B,IAAI,MAAM;;;;;AAMtD,MAAa,oBACX,KAAK,gBAAgB,CAAC,iBAAiB,CAAC;;;;;;;;AAS1C,MAAa,oBAAyC;AACpD,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE;;;;;;;;AASX,MAAa,qBAA2C;CACtD,MAAM,EAAE,yCAAsB;AAC9B,QAAOC,wCAAiB,UAAqB,KAAK;;;;;;;;;;AAgBpD,MAAa,gBAAsC,EACjD,eACmB,yEAAG,UAAY;;;;;AAMpC,MAAa,gBAAgB,GAAG,WAAsB,EAAE"}
@@ -1,39 +0,0 @@
1
- 'use client';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_createTranslator = require('../createTranslator.cjs');
6
- let next_intlayer = require("next-intlayer");
7
- let react = require("react");
8
-
9
- //#region src/client/useTranslations.ts
10
- /**
11
- * Drop-in for next-intl's `useTranslations`.
12
- *
13
- * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),
14
- * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted
15
- * arguments (`{value, number}`). Rich text is available through `t.rich()`
16
- * and `t.markup()`.
17
- *
18
- * @example
19
- * ```tsx
20
- * const t = useTranslations('about');
21
- * t('counter.label'); // ✓ typed
22
- * t('items', { count: 3 }); // ICU plural
23
- *
24
- * // Scoped to a nested object (next-intl idiom)
25
- * const t = useTranslations('about.counter');
26
- * t('label'); // resolves about → counter.label
27
- *
28
- * // Rich text
29
- * t.rich('terms', { link: (chunks) => <a href="/terms">{chunks}</a> });
30
- * ```
31
- */
32
- const useTranslations = ((namespace) => {
33
- const { locale: currentLocale } = (0, react.useContext)(next_intlayer.IntlayerClientContext) ?? {};
34
- return (0, react.useMemo)(() => require_createTranslator.createTranslator(currentLocale, namespace), [currentLocale, namespace]);
35
- });
36
-
37
- //#endregion
38
- exports.useTranslations = useTranslations;
39
- //# sourceMappingURL=useTranslations.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTranslations.cjs","names":["IntlayerClientContext","createTranslator"],"sources":["../../../src/client/useTranslations.ts"],"sourcesContent":["'use client';\n\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerClientContext } from 'next-intlayer';\nimport { type ReactNode, useContext, useMemo } from 'react';\nimport {\n createTranslator,\n type MarkupChunkRenderer,\n type RichChunkRenderer,\n} from '../createTranslator';\n\n/**\n * The translation function returned by {@link useTranslations}.\n *\n * When the namespace is a bare dictionary key, `key` is validated against the\n * dictionary's dot-paths. When the namespace is a nested scope\n * (`'about.counter'`), `key` is a relative `string` path.\n *\n * Beyond the call signature, the function exposes:\n * - `has(key)` — returns `true` when the key exists in the namespace.\n * - `raw(key)` — returns the unprocessed content value.\n * - `rich(key, values)` — resolves `<tag>chunks</tag>` markup to React nodes.\n * - `markup(key, values)` — resolves `<tag>chunks</tag>` markup to a string.\n */\ntype TranslateFunction<N extends DictionaryKeys> = {\n /** Translate a key to a string, with optional ICU interpolation params. */\n <P extends ValidDotPathsFor<N>>(\n key: P,\n params?: Record<string, unknown>\n ): string;\n /** Returns `true` if the given key exists in the namespace. */\n has<P extends ValidDotPathsFor<N>>(key: P): boolean;\n /** Returns the raw unprocessed content for the given key. */\n raw<P extends ValidDotPathsFor<N>>(key: P): unknown;\n /** Resolves rich-text markup, mapping tags through React renderers. */\n rich<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n /** Resolves rich-text markup, mapping tags through string renderers. */\n markup<P extends ValidDotPathsFor<N>>(\n key: P,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/** Loosely-typed function returned for nested `'dict.scope'` namespaces. */\ntype LooseTranslateFunction = {\n (key: string, params?: Record<string, unknown>): string;\n has(key: string): boolean;\n raw(key: string): unknown;\n rich(\n key: string,\n values?: Record<string, RichChunkRenderer | ReactNode>\n ): ReactNode;\n markup(\n key: string,\n values?: Record<string, MarkupChunkRenderer | string | number>\n ): string;\n};\n\n/**\n * Overload set for {@link useTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 3. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n (namespace: `${string}.${string}`): LooseTranslateFunction;\n (): LooseTranslateFunction;\n};\n\n/**\n * Drop-in for next-intl's `useTranslations`.\n *\n * Messages support ICU MessageFormat syntax: simple arguments (`{name}`),\n * plural (`{count, plural, one {…} other {…}}`, `#`), select, and formatted\n * arguments (`{value, number}`). Rich text is available through `t.rich()`\n * and `t.markup()`.\n *\n * @example\n * ```tsx\n * const t = useTranslations('about');\n * t('counter.label'); // ✓ typed\n * t('items', { count: 3 }); // ICU plural\n *\n * // Scoped to a nested object (next-intl idiom)\n * const t = useTranslations('about.counter');\n * t('label'); // resolves about → counter.label\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const useTranslations = ((namespace?: string) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n return useMemo(\n () => createTranslator(currentLocale as LocalesValues, namespace),\n [currentLocale, namespace]\n );\n}) as UseTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,EAAE,QAAQ,wCAA6BA,oCAAsB,IAAI,EAAE;AAEzE,iCACQC,0CAAiB,eAAgC,UAAU,EACjE,CAAC,eAAe,UAAU,CAC3B"}
@@ -1,59 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
-
3
- //#region src/createFormatter.ts
4
- /** Time units orderable by their duration in seconds. */
5
- const RELATIVE_TIME_UNITS = [
6
- ["year", 31536e3],
7
- ["month", 2628e3],
8
- ["week", 604800],
9
- ["day", 86400],
10
- ["hour", 3600],
11
- ["minute", 60],
12
- ["second", 1]
13
- ];
14
- const toDate = (value) => value instanceof Date ? value : new Date(value);
15
- /**
16
- * Builds a next-intl compatible formatter backed by the native `Intl.*`
17
- * APIs for the given locale.
18
- *
19
- * Shared by `useFormatter` (client) and `getFormatter` (server).
20
- */
21
- const createFormatter = (locale) => ({
22
- dateTime: (value, options) => new Intl.DateTimeFormat(locale, options).format(value),
23
- number: (value, options) => new Intl.NumberFormat(locale, options).format(value),
24
- /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */
25
- dateTimeRange: (start, end, options) => new Intl.DateTimeFormat(locale, options).formatRange(toDate(start), toDate(end)),
26
- /**
27
- * Formats a date relative to now (or a reference date), automatically
28
- * selecting the largest fitting unit.
29
- */
30
- relativeTime: (date, nowOrOptions) => {
31
- const options = nowOrOptions instanceof Date || typeof nowOrOptions === "number" ? { now: nowOrOptions } : nowOrOptions ?? {};
32
- const nowDate = options.now !== void 0 ? toDate(options.now) : /* @__PURE__ */ new Date();
33
- const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1e3;
34
- let unit = options.unit;
35
- if (!unit) {
36
- const absoluteDiff = Math.abs(diffInSeconds);
37
- unit = RELATIVE_TIME_UNITS.find(([, unitSeconds]) => absoluteDiff >= unitSeconds)?.[0] ?? "second";
38
- }
39
- const unitSeconds = RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;
40
- return new Intl.RelativeTimeFormat(locale, {
41
- numeric: "auto",
42
- style: options.style
43
- }).format(Math.round(diffInSeconds / unitSeconds), unit);
44
- },
45
- /** Formats a list with `Intl.ListFormat`. */
46
- list: (value, options) => new Intl.ListFormat(locale, options).format(value),
47
- displayName: (value, optionsOrFormat, extraOptions) => {
48
- const resolvedOptions = typeof optionsOrFormat === "string" ? extraOptions : optionsOrFormat;
49
- try {
50
- return new Intl.DisplayNames([locale], resolvedOptions ?? { type: "language" }).of(value) ?? value;
51
- } catch {
52
- return value;
53
- }
54
- }
55
- });
56
-
57
- //#endregion
58
- exports.createFormatter = createFormatter;
59
- //# sourceMappingURL=createFormatter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFormatter.cjs","names":[],"sources":["../../src/createFormatter.ts"],"sourcesContent":["import type { useFormatter as _useFormatter } from 'next-intl';\n\n/** The formatter object shape exposed by next-intl. */\nexport type Formatter = ReturnType<typeof _useFormatter>;\n\n/** Time units orderable by their duration in seconds. */\nconst RELATIVE_TIME_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 31536000],\n ['month', 2628000],\n ['week', 604800],\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n];\n\nconst toDate = (value: Date | number | string): Date =>\n value instanceof Date ? value : new Date(value);\n\n/**\n * Builds a next-intl compatible formatter backed by the native `Intl.*`\n * APIs for the given locale.\n *\n * Shared by `useFormatter` (client) and `getFormatter` (server).\n */\nexport const createFormatter = (locale: string): Formatter =>\n ({\n dateTime: (value: Date | number, options?: Intl.DateTimeFormatOptions) =>\n new Intl.DateTimeFormat(locale, options).format(value),\n\n number: (value: number | bigint, options?: Intl.NumberFormatOptions) =>\n new Intl.NumberFormat(locale, options).format(value),\n\n /** Formats a date range with `Intl.DateTimeFormat#formatRange`. */\n dateTimeRange: (\n start: Date | number,\n end: Date | number,\n options?: Intl.DateTimeFormatOptions\n ) =>\n new Intl.DateTimeFormat(locale, options).formatRange(\n toDate(start),\n toDate(end)\n ),\n\n /**\n * Formats a date relative to now (or a reference date), automatically\n * selecting the largest fitting unit.\n */\n relativeTime: (\n date: Date | number | string,\n nowOrOptions?:\n | Date\n | number\n | {\n now?: Date | number;\n unit?: Intl.RelativeTimeFormatUnit;\n style?: Intl.RelativeTimeFormatStyle;\n numberingSystem?: string;\n }\n ) => {\n const options =\n nowOrOptions instanceof Date || typeof nowOrOptions === 'number'\n ? { now: nowOrOptions }\n : (nowOrOptions ?? {});\n\n const nowDate =\n options.now !== undefined ? toDate(options.now) : new Date();\n const diffInSeconds = (toDate(date).getTime() - nowDate.getTime()) / 1000;\n\n let unit = options.unit;\n if (!unit) {\n const absoluteDiff = Math.abs(diffInSeconds);\n unit =\n RELATIVE_TIME_UNITS.find(\n ([, unitSeconds]) => absoluteDiff >= unitSeconds\n )?.[0] ?? 'second';\n }\n\n const unitSeconds =\n RELATIVE_TIME_UNITS.find(([unitName]) => unitName === unit)?.[1] ?? 1;\n\n return new Intl.RelativeTimeFormat(locale, {\n numeric: 'auto',\n style: options.style,\n }).format(Math.round(diffInSeconds / unitSeconds), unit);\n },\n\n /** Formats a list with `Intl.ListFormat`. */\n list: (value: Iterable<string>, options?: Intl.ListFormatOptions): string =>\n new Intl.ListFormat(locale, options).format(value),\n\n displayName: (\n value: string,\n optionsOrFormat?: Intl.DisplayNamesOptions | string,\n extraOptions?: Intl.DisplayNamesOptions\n ): string => {\n const resolvedOptions =\n typeof optionsOrFormat === 'string' ? extraOptions : optionsOrFormat;\n try {\n return (\n new Intl.DisplayNames(\n [locale],\n resolvedOptions ?? { type: 'language' }\n ).of(value) ?? value\n );\n } catch {\n return value;\n }\n },\n }) as unknown as Formatter;\n"],"mappings":";;;;AAMA,MAAM,sBAA+D;CACnE,CAAC,QAAQ,QAAS;CAClB,CAAC,SAAS,OAAQ;CAClB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ,KAAK;CACd,CAAC,UAAU,GAAG;CACd,CAAC,UAAU,EAAE;CACd;AAED,MAAM,UAAU,UACd,iBAAiB,OAAO,QAAQ,IAAI,KAAK,MAAM;;;;;;;AAQjD,MAAa,mBAAmB,YAC7B;CACC,WAAW,OAAsB,YAC/B,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAExD,SAAS,OAAwB,YAC/B,IAAI,KAAK,aAAa,QAAQ,QAAQ,CAAC,OAAO,MAAM;;CAGtD,gBACE,OACA,KACA,YAEA,IAAI,KAAK,eAAe,QAAQ,QAAQ,CAAC,YACvC,OAAO,MAAM,EACb,OAAO,IAAI,CACZ;;;;;CAMH,eACE,MACA,iBASG;EACH,MAAM,UACJ,wBAAwB,QAAQ,OAAO,iBAAiB,WACpD,EAAE,KAAK,cAAc,GACpB,gBAAgB,EAAE;EAEzB,MAAM,UACJ,QAAQ,QAAQ,SAAY,OAAO,QAAQ,IAAI,mBAAG,IAAI,MAAM;EAC9D,MAAM,iBAAiB,OAAO,KAAK,CAAC,SAAS,GAAG,QAAQ,SAAS,IAAI;EAErE,IAAI,OAAO,QAAQ;AACnB,MAAI,CAAC,MAAM;GACT,MAAM,eAAe,KAAK,IAAI,cAAc;AAC5C,UACE,oBAAoB,MACjB,GAAG,iBAAiB,gBAAgB,YACtC,GAAG,MAAM;;EAGd,MAAM,cACJ,oBAAoB,MAAM,CAAC,cAAc,aAAa,KAAK,GAAG,MAAM;AAEtE,SAAO,IAAI,KAAK,mBAAmB,QAAQ;GACzC,SAAS;GACT,OAAO,QAAQ;GAChB,CAAC,CAAC,OAAO,KAAK,MAAM,gBAAgB,YAAY,EAAE,KAAK;;;CAI1D,OAAO,OAAyB,YAC9B,IAAI,KAAK,WAAW,QAAQ,QAAQ,CAAC,OAAO,MAAM;CAEpD,cACE,OACA,iBACA,iBACW;EACX,MAAM,kBACJ,OAAO,oBAAoB,WAAW,eAAe;AACvD,MAAI;AACF,UACE,IAAI,KAAK,aACP,CAAC,OAAO,EACR,mBAAmB,EAAE,MAAM,YAAY,CACxC,CAAC,GAAG,MAAM,IAAI;UAEX;AACN,UAAO;;;CAGZ"}
@@ -1,111 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
4
- let _intlayer_core_messageFormat = require("@intlayer/core/messageFormat");
5
- let react = require("react");
6
- let react_jsx_runtime = require("react/jsx-runtime");
7
-
8
- //#region src/createTranslator.tsx
9
- const navigatePath = (objectValue, path) => {
10
- if (!path) return objectValue;
11
- const parts = path.split(".");
12
- let current = objectValue;
13
- for (const part of parts) {
14
- if (current === null || current === void 0 || typeof current !== "object") return;
15
- current = current[part];
16
- }
17
- return current;
18
- };
19
- /** Splits rich values into scalar interpolation values and tag renderers. */
20
- const splitRichValues = (values = {}) => {
21
- const scalarValues = {};
22
- const renderers = {};
23
- for (const [valueKey, value] of Object.entries(values)) if (typeof value === "function") renderers[valueKey] = value;
24
- else scalarValues[valueKey] = value;
25
- return {
26
- scalarValues,
27
- renderers
28
- };
29
- };
30
- const renderRichTokens = (tokens, renderers) => tokens.map((token, tokenIndex) => {
31
- if (typeof token === "string") return token;
32
- const children = renderRichTokens(token.children, renderers);
33
- const renderer = renderers[token.tag];
34
- if (typeof renderer === "function") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderer(children) }, tokenIndex);
35
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children }, tokenIndex);
36
- });
37
- const renderMarkupTokens = (tokens, renderers) => tokens.map((token) => {
38
- if (typeof token === "string") return token;
39
- const children = renderMarkupTokens(token.children, renderers);
40
- const renderer = renderers[token.tag];
41
- if (typeof renderer === "function") return renderer(children);
42
- return children;
43
- }).join("");
44
- /**
45
- * The untyped runtime translator shared by `useTranslations` (client) and
46
- * `getTranslations` (server).
47
- *
48
- * Behaviour matches next-intl:
49
- * - namespace `'about'` → keys resolved inside the `about` dictionary
50
- * - namespace `'about.counter'` → dictionary `about`, key prefix `counter`
51
- * - no namespace → the first segment of each key is the dictionary key
52
- * - messages support ICU syntax (plural, select, `#`, formatted arguments)
53
- * - `t.rich` / `t.markup` map `<tag>chunks</tag>` through the provided
54
- * renderers; `t.raw` returns the raw value; `t.has` checks existence
55
- */
56
- const createTranslator = (locale, namespace) => {
57
- const [dictionaryKey, ...prefixSegments] = (namespace ?? "").split(".");
58
- const keyPrefix = prefixSegments.join(".");
59
- const lookup = (key) => {
60
- let targetDictionaryKey = dictionaryKey;
61
- let path = keyPrefix ? `${keyPrefix}.${key}` : key;
62
- if (!targetDictionaryKey) {
63
- const [firstSegment, ...restSegments] = key.split(".");
64
- targetDictionaryKey = firstSegment;
65
- path = restSegments.join(".");
66
- }
67
- try {
68
- return navigatePath((0, _intlayer_core_interpreter.getIntlayer)(targetDictionaryKey, locale), path);
69
- } catch {
70
- return;
71
- }
72
- };
73
- const resolveToString = (key, values = {}) => {
74
- const rawValue = lookup(key);
75
- if (rawValue === null || rawValue === void 0) return void 0;
76
- return (0, _intlayer_core_messageFormat.resolveMessage)(rawValue, values, locale, "icu");
77
- };
78
- const missingKeyFallback = (key) => namespace ? `${namespace}.${key}` : key;
79
- const translate = (key, values) => resolveToString(key, values) ?? missingKeyFallback(key);
80
- return Object.assign(translate, {
81
- /** Returns `true` if the given key exists in the namespace. */
82
- has: (key) => lookup(key) !== void 0,
83
- /** Returns the raw unprocessed content for the given key. */
84
- raw: (key) => lookup(key),
85
- /**
86
- * Resolves a message containing `<tag>chunks</tag>` markup, mapping each
87
- * tag through the matching renderer in `values`.
88
- */
89
- rich: (key, values) => {
90
- const { scalarValues, renderers } = splitRichValues(values);
91
- const message = resolveToString(key, scalarValues);
92
- if (message === void 0) return missingKeyFallback(key);
93
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: renderRichTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers) });
94
- },
95
- /**
96
- * Resolves a message containing `<tag>chunks</tag>` markup into a string,
97
- * mapping each tag through the matching string renderer in `values`.
98
- */
99
- markup: (key, values) => {
100
- const { scalarValues, renderers } = splitRichValues(values);
101
- const message = resolveToString(key, scalarValues);
102
- if (message === void 0) return missingKeyFallback(key);
103
- return renderMarkupTokens((0, _intlayer_core_messageFormat.parseTaggedMessage)(message), renderers);
104
- }
105
- });
106
- };
107
-
108
- //#endregion
109
- exports.createTranslator = createTranslator;
110
- exports.navigatePath = navigatePath;
111
- //# sourceMappingURL=createTranslator.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTranslator.cjs","names":["Fragment"],"sources":["../../src/createTranslator.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\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` (client) and\n * `getTranslations` (server).\n *\n * Behaviour matches 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 */\nexport const createTranslator = (locale: LocalesValues, namespace?: string) => {\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 createTranslator>;\n"],"mappings":";;;;;;;;AAmBA,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,2CAACA,gBAAD,YACI,SAA+B,SAAS,EACjC,EAFI,WAEJ;AAKf,QAAO,2CAACA,gBAAD,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;;;;;;;;;;;;;AAcb,MAAa,oBAAoB,QAAuB,cAAuB;CAC7E,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,yDAHL,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,0DAAsB,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,mFAAG,sEAAoC,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,wEAAsC,QAAQ,EAAE,UAAU;;EAEpE,CAAC"}
@@ -1,31 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let next_intlayer_server = require("next-intlayer/server");
4
-
5
- //#region src/getTranslationsDictionary.ts
6
- /**
7
- * Dictionary-accepting variant of `getTranslations`.
8
- *
9
- * Used internally by the SWC optimization: instead of looking up the dictionary
10
- * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
11
- * and passes it directly here. This enables tree-shaking of unused locale content.
12
- */
13
- const getTranslationsDictionary = async (dictionary, namespacePrefix) => {
14
- const content = (0, next_intlayer_server.getDictionary)(dictionary);
15
- return (lookup, params) => {
16
- const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
17
- const parts = lookupKey.split(".");
18
- let current = content;
19
- for (const part of parts) {
20
- if (current == null) break;
21
- current = current[part];
22
- }
23
- const str = String(current ?? lookupKey);
24
- if (!params) return str;
25
- return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
26
- };
27
- };
28
-
29
- //#endregion
30
- exports.getTranslationsDictionary = getTranslationsDictionary;
31
- //# sourceMappingURL=getTranslationsDictionary.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTranslationsDictionary.cjs","names":[],"sources":["../../src/getTranslationsDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getDictionary } from 'next-intlayer/server';\n\n/**\n * Dictionary-accepting variant of `getTranslations`.\n *\n * Used internally by the SWC optimization: instead of looking up the dictionary\n * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time\n * and passes it directly here. This enables tree-shaking of unused locale content.\n */\nexport const getTranslationsDictionary = async <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const content = getDictionary(dictionary);\n\n return <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,4BAA4B,OACvC,YACA,oBACG;CACH,MAAM,kDAAwB,WAAW;AAEzC,SACE,QACA,WACW;EACX,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C"}
@@ -1,27 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let next_intlayer_server = require("next-intlayer/server");
4
-
5
- //#region src/getTranslationsDictionaryDynamic.ts
6
- /**
7
- * Dynamic dictionary-accepting variant of `getTranslations`.
8
- */
9
- const getTranslationsDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
10
- const content = await (0, next_intlayer_server.getDictionaryDynamic)(dictionaryPromise, key);
11
- return (lookup, params) => {
12
- const lookupKey = namespacePrefix ? `${namespacePrefix}.${String(lookup)}` : String(lookup);
13
- const parts = lookupKey.split(".");
14
- let current = content;
15
- for (const part of parts) {
16
- if (current == null) break;
17
- current = current[part];
18
- }
19
- const str = String(current ?? lookupKey);
20
- if (!params) return str;
21
- return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
22
- };
23
- };
24
-
25
- //#endregion
26
- exports.getTranslationsDictionaryDynamic = getTranslationsDictionaryDynamic;
27
- //# sourceMappingURL=getTranslationsDictionaryDynamic.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTranslationsDictionaryDynamic.cjs","names":[],"sources":["../../src/getTranslationsDictionaryDynamic.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { getDictionaryDynamic } from 'next-intlayer/server';\n\n/**\n * Dynamic dictionary-accepting variant of `getTranslations`.\n */\nexport const getTranslationsDictionaryDynamic = async <\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 = await getDictionaryDynamic<T, any>(\n dictionaryPromise,\n key as any\n );\n\n return <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const lookupKey = namespacePrefix\n ? `${namespacePrefix}.${String(lookup)}`\n : String(lookup);\n const parts = lookupKey.split('.');\n let current: any = content;\n for (const part of parts) {\n if (current == null) break;\n current = current[part];\n }\n const str = String(current ?? lookupKey);\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n };\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,mCAAmC,OAI9C,mBACA,KACA,oBACG;CACH,MAAM,UAAU,qDACd,mBACA,IACD;AAED,SACE,QACA,WACW;EACX,MAAM,YAAY,kBACd,GAAG,gBAAgB,GAAG,OAAO,OAAO,KACpC,OAAO,OAAO;EAClB,MAAM,QAAQ,UAAU,MAAM,IAAI;EAClC,IAAI,UAAe;AACnB,OAAK,MAAM,QAAQ,OAAO;AACxB,OAAI,WAAW,KAAM;AACrB,aAAU,QAAQ;;EAEpB,MAAM,MAAM,OAAO,WAAW,UAAU;AACxC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C"}