@intlayer/next-intl 9.4.3 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +0 -2
  2. package/dist/cjs/plugin/index.cjs +36 -11
  3. package/dist/cjs/plugin/index.cjs.map +1 -1
  4. package/dist/cjs/react-server/helpers.cjs +20 -0
  5. package/dist/cjs/react-server/helpers.cjs.map +1 -0
  6. package/dist/cjs/react-server/index.cjs +61 -0
  7. package/dist/cjs/react-server/resolveLocale.cjs +19 -0
  8. package/dist/cjs/react-server/resolveLocale.cjs.map +1 -0
  9. package/dist/cjs/react-server/useDictionary.cjs +23 -0
  10. package/dist/cjs/react-server/useDictionary.cjs.map +1 -0
  11. package/dist/cjs/react-server/useDictionaryDynamic.cjs +19 -0
  12. package/dist/cjs/react-server/useDictionaryDynamic.cjs.map +1 -0
  13. package/dist/cjs/react-server/useLocale.cjs +13 -0
  14. package/dist/cjs/react-server/useLocale.cjs.map +1 -0
  15. package/dist/cjs/react-server/useTranslations.cjs +42 -0
  16. package/dist/cjs/react-server/useTranslations.cjs.map +1 -0
  17. package/dist/cjs/server/react/helpers.cjs +23 -0
  18. package/dist/cjs/server/react/helpers.cjs.map +1 -0
  19. package/dist/cjs/server/react/index.cjs +61 -0
  20. package/dist/cjs/server/react/resolveLocale.cjs +27 -0
  21. package/dist/cjs/server/react/resolveLocale.cjs.map +1 -0
  22. package/dist/cjs/server/react/useDictionary.cjs +23 -0
  23. package/dist/cjs/server/react/useDictionary.cjs.map +1 -0
  24. package/dist/cjs/server/react/useDictionaryDynamic.cjs +19 -0
  25. package/dist/cjs/server/react/useDictionaryDynamic.cjs.map +1 -0
  26. package/dist/cjs/server/react/useLocale.cjs +13 -0
  27. package/dist/cjs/server/react/useLocale.cjs.map +1 -0
  28. package/dist/cjs/server/react/useTranslations.cjs +42 -0
  29. package/dist/cjs/server/react/useTranslations.cjs.map +1 -0
  30. package/dist/esm/plugin/index.mjs +37 -12
  31. package/dist/esm/plugin/index.mjs.map +1 -1
  32. package/dist/esm/react-server/helpers.mjs +17 -0
  33. package/dist/esm/react-server/helpers.mjs.map +1 -0
  34. package/dist/esm/react-server/index.mjs +10 -0
  35. package/dist/esm/react-server/resolveLocale.mjs +18 -0
  36. package/dist/esm/react-server/resolveLocale.mjs.map +1 -0
  37. package/dist/esm/react-server/useDictionary.mjs +22 -0
  38. package/dist/esm/react-server/useDictionary.mjs.map +1 -0
  39. package/dist/esm/react-server/useDictionaryDynamic.mjs +18 -0
  40. package/dist/esm/react-server/useDictionaryDynamic.mjs.map +1 -0
  41. package/dist/esm/react-server/useLocale.mjs +12 -0
  42. package/dist/esm/react-server/useLocale.mjs.map +1 -0
  43. package/dist/esm/react-server/useTranslations.mjs +41 -0
  44. package/dist/esm/react-server/useTranslations.mjs.map +1 -0
  45. package/dist/esm/server/react/helpers.mjs +20 -0
  46. package/dist/esm/server/react/helpers.mjs.map +1 -0
  47. package/dist/esm/server/react/index.mjs +10 -0
  48. package/dist/esm/server/react/resolveLocale.mjs +26 -0
  49. package/dist/esm/server/react/resolveLocale.mjs.map +1 -0
  50. package/dist/esm/server/react/useDictionary.mjs +22 -0
  51. package/dist/esm/server/react/useDictionary.mjs.map +1 -0
  52. package/dist/esm/server/react/useDictionaryDynamic.mjs +18 -0
  53. package/dist/esm/server/react/useDictionaryDynamic.mjs.map +1 -0
  54. package/dist/esm/server/react/useLocale.mjs +12 -0
  55. package/dist/esm/server/react/useLocale.mjs.map +1 -0
  56. package/dist/esm/server/react/useTranslations.mjs +41 -0
  57. package/dist/esm/server/react/useTranslations.mjs.map +1 -0
  58. package/dist/types/client/NextIntlClientProvider.d.ts +2 -3
  59. package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -1
  60. package/dist/types/client/useLocale.d.ts +1 -2
  61. package/dist/types/client/useLocale.d.ts.map +1 -1
  62. package/dist/types/getDictionary.d.ts +1 -2
  63. package/dist/types/getDictionary.d.ts.map +1 -1
  64. package/dist/types/getDictionaryDynamic.d.ts +1 -2
  65. package/dist/types/getDictionaryDynamic.d.ts.map +1 -1
  66. package/dist/types/middleware.d.ts +2 -2
  67. package/dist/types/middleware.d.ts.map +1 -1
  68. package/dist/types/navigation/Link.d.ts +2 -3
  69. package/dist/types/navigation/Link.d.ts.map +1 -1
  70. package/dist/types/navigation/createNavigation.d.ts +2 -2
  71. package/dist/types/navigation/createNavigation.d.ts.map +1 -1
  72. package/dist/types/navigation/hooks.d.ts +2 -3
  73. package/dist/types/navigation/hooks.d.ts.map +1 -1
  74. package/dist/types/navigation/localizeHref.d.ts +2 -3
  75. package/dist/types/navigation/localizeHref.d.ts.map +1 -1
  76. package/dist/types/plugin/index.d.ts +2 -2
  77. package/dist/types/plugin/index.d.ts.map +1 -1
  78. package/dist/types/react-server/helpers.d.ts +12 -0
  79. package/dist/types/react-server/helpers.d.ts.map +1 -0
  80. package/dist/types/react-server/index.d.ts +9 -0
  81. package/dist/types/react-server/resolveLocale.d.ts +14 -0
  82. package/dist/types/react-server/resolveLocale.d.ts.map +1 -0
  83. package/dist/types/react-server/useDictionary.d.ts +24 -0
  84. package/dist/types/react-server/useDictionary.d.ts.map +1 -0
  85. package/dist/types/react-server/useDictionaryDynamic.d.ts +15 -0
  86. package/dist/types/react-server/useDictionaryDynamic.d.ts.map +1 -0
  87. package/dist/types/react-server/useLocale.d.ts +9 -0
  88. package/dist/types/react-server/useLocale.d.ts.map +1 -0
  89. package/dist/types/react-server/useTranslations.d.ts +23 -0
  90. package/dist/types/react-server/useTranslations.d.ts.map +1 -0
  91. package/dist/types/routing.d.ts +2 -3
  92. package/dist/types/routing.d.ts.map +1 -1
  93. package/dist/types/server/getLocale.d.ts +1 -2
  94. package/dist/types/server/getLocale.d.ts.map +1 -1
  95. package/dist/types/server/getMessages.d.ts +1 -2
  96. package/dist/types/server/getMessages.d.ts.map +1 -1
  97. package/dist/types/server/getRequestConfig.d.ts +2 -2
  98. package/dist/types/server/getRequestConfig.d.ts.map +1 -1
  99. package/dist/types/server/getTranslations.d.ts +1 -2
  100. package/dist/types/server/getTranslations.d.ts.map +1 -1
  101. package/dist/types/server/helpers.d.ts +3 -4
  102. package/dist/types/server/helpers.d.ts.map +1 -1
  103. package/dist/types/server/react/helpers.d.ts +15 -0
  104. package/dist/types/server/react/helpers.d.ts.map +1 -0
  105. package/dist/types/server/react/index.d.ts +9 -0
  106. package/dist/types/server/react/resolveLocale.d.ts +18 -0
  107. package/dist/types/server/react/resolveLocale.d.ts.map +1 -0
  108. package/dist/types/server/react/useDictionary.d.ts +24 -0
  109. package/dist/types/server/react/useDictionary.d.ts.map +1 -0
  110. package/dist/types/server/react/useDictionaryDynamic.d.ts +15 -0
  111. package/dist/types/server/react/useDictionaryDynamic.d.ts.map +1 -0
  112. package/dist/types/server/react/useLocale.d.ts +9 -0
  113. package/dist/types/server/react/useLocale.d.ts.map +1 -0
  114. package/dist/types/server/react/useTranslations.d.ts +23 -0
  115. package/dist/types/server/react/useTranslations.d.ts.map +1 -0
  116. package/dist/types/server/requestLocaleCache.d.ts +2 -3
  117. package/dist/types/server/requestLocaleCache.d.ts.map +1 -1
  118. package/dist/types/server/setLocale.d.ts +1 -2
  119. package/dist/types/server/setLocale.d.ts.map +1 -1
  120. package/dist/types/server/setRequestLocale.d.ts +1 -2
  121. package/dist/types/server/setRequestLocale.d.ts.map +1 -1
  122. package/package.json +14 -13
package/README.md CHANGED
@@ -69,8 +69,6 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
69
69
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/interoperability.png?raw=true" alt="Feature" width="700"> | **Interoperability**<br><br>Allow interoperability with react-i18next, next-i18next, next-intl, react-intl, vue-i18n. <br><br> - [Intlayer and react-intl](https://intlayer.org/blog/intlayer-with-react-intl) <br> - [Intlayer and next-intl](https://intlayer.org/blog/intlayer-with-next-intl) <br> - [Intlayer and next-i18next](https://intlayer.org/blog/intlayer-with-next-i18next) <br> - [Intlayer and vue-i18n](https://intlayer.org/blog/intlayer-with-vue-i18n) <br> - [Intlayer compat adapters](https://intlayer.org/doc/compatibility) |
70
70
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/benchmark.png?raw=true" alt="Feature" width="700"> | **Performances & Benchmark**<br><br>Uses advanced tree-shaking and dynamic loading to boost performances and keep the solution as light as possible. <br><br> - [Performances & Benchmark](https://intlayer.org/doc/benchmark) |
71
71
 
72
- ---
73
-
74
72
  ## 📦 Installation
75
73
 
76
74
  Start your journey with Intlayer today and experience a smoother, more powerful approach to internationalization.
@@ -80,6 +80,24 @@ const resolveEsmPath = (specifier) => {
80
80
  return (0, node_path.resolve)(packageDir, relativeFile);
81
81
  };
82
82
  /**
83
+ * Absolute path of a specifier's `react-server` export condition, when the
84
+ * package declares one.
85
+ *
86
+ * Aliasing to a file bypasses the package's `exports` map, so the condition
87
+ * would never be consulted — the alias itself has to carry it. Without this,
88
+ * every Server Component resolves the client build of `useTranslations`, gets
89
+ * pulled across the client boundary, and drags its dictionary into a chunk
90
+ * Next shares across every locale.
91
+ */
92
+ const resolveReactServerPath = (specifier) => {
93
+ const { packageName, exportKey } = splitSpecifier(specifier);
94
+ const packageJson = compatRequire(`${packageName}/package.json`);
95
+ const packageDir = (0, node_path.dirname)(compatRequire.resolve(`${packageName}/package.json`));
96
+ const exportEntry = packageJson.exports?.[exportKey];
97
+ const relativeFile = typeof exportEntry === "string" ? void 0 : exportEntry?.["react-server"];
98
+ return relativeFile ? (0, node_path.resolve)(packageDir, relativeFile) : void 0;
99
+ };
100
+ /**
83
101
  * Format an absolute path as a project-root-relative specifier (prefixed with
84
102
  * `./` and using forward slashes). Turbopack only honours `resolveAlias` values
85
103
  * that are project-root-relative paths — bare specifiers are ignored and
@@ -91,12 +109,6 @@ const resolveEsmPath = (specifier) => {
91
109
  */
92
110
  const toTurbopackAlias = (absolutePath) => `./${(0, node_path.relative)(process.cwd(), absolutePath).split(node_path.sep).join("/")}`;
93
111
  /**
94
- * SWC extra-caller configs derived from the shared caller registry
95
- * (`@intlayer/config/callers`) — the single source of truth also consumed by
96
- * the babel analyzer/optimizer and the LSP.
97
- */
98
- const NEXT_INTL_SWC_CALLERS = (0, _intlayer_config_callers.toSwcExtraCallers)(_intlayer_config_callers.NEXT_INTL_CALLERS);
99
- /**
100
112
  * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin
101
113
  * and configures resolve aliases so `next-intl` imports are served by
102
114
  * `@intlayer/next-intl`.
@@ -111,10 +123,23 @@ const createNextIntlPlugin = (_i18nPath) => {
111
123
  const customWebpack = nextConfig.webpack;
112
124
  const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({
113
125
  request,
114
- absolutePath: resolveEsmPath(replacement)
126
+ replacement,
127
+ hasReactServerBuild: Boolean(resolveReactServerPath(replacement))
115
128
  }));
116
- const webpackAlias = Object.fromEntries(resolvedTargets.map(({ request, absolutePath }) => [request, absolutePath]));
117
- const turboAlias = Object.fromEntries(resolvedTargets.map(({ request, absolutePath }) => [request, toTurbopackAlias(absolutePath)]));
129
+ /**
130
+ * Aliasing to a resolved *file* pins one build of the target and bypasses
131
+ * its `exports` map — so the `react-server` condition is never consulted
132
+ * and a Server Component silently gets the client build of
133
+ * `useTranslations`. That drags every component calling it across the
134
+ * client boundary, and with it the multi-locale dictionary, into a chunk
135
+ * Next serves to every locale.
136
+ *
137
+ * Aliasing to the package specifier instead lets the bundler resolve
138
+ * normally, so each layer picks its own condition.
139
+ */
140
+ const aliasTarget = ({ replacement, hasReactServerBuild }) => hasReactServerBuild ? replacement : toTurbopackAlias(resolveEsmPath(replacement));
141
+ const webpackAlias = Object.fromEntries(resolvedTargets.map(({ request, replacement, hasReactServerBuild }) => [request, hasReactServerBuild ? replacement : resolveEsmPath(replacement)]));
142
+ const turboAlias = Object.fromEntries(resolvedTargets.map((target) => [target.request, aliasTarget(target)]));
118
143
  const aliasConfig = { webpack: (config, options) => {
119
144
  config.resolve.alias = {
120
145
  ...config.resolve.alias,
@@ -138,7 +163,7 @@ const createNextIntlPlugin = (_i18nPath) => {
138
163
  try {
139
164
  hasUserDefinedStorage = !!(intlayerConfig?.routing && "storage" in intlayerConfig.routing && intlayerConfig.routing.storage !== void 0);
140
165
  } catch {}
141
- return (0, next_intlayer_server.withIntlayer)(mergedConfig, hasUserDefinedStorage ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS } : {
166
+ return (0, next_intlayer_server.withIntlayer)(mergedConfig, hasUserDefinedStorage ? { compatCallers: _intlayer_config_callers.NEXT_INTL_CALLERS } : {
142
167
  override: { routing: { storage: [{
143
168
  type: "cookie",
144
169
  name: "NEXT_LOCALE"
@@ -146,7 +171,7 @@ const createNextIntlPlugin = (_i18nPath) => {
146
171
  type: "header",
147
172
  name: "x-intlayer-locale"
148
173
  }] } },
149
- swcExtraCallers: NEXT_INTL_SWC_CALLERS
174
+ compatCallers: _intlayer_config_callers.NEXT_INTL_CALLERS
150
175
  });
151
176
  };
152
177
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["createRequire","dirname","resolve","relative","sep","toSwcExtraCallers","NEXT_INTL_CALLERS","getConfiguration","getAppLogger","join","colorize","ANSIColors","withIntlayer"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { NEXT_INTL_CALLERS, toSwcExtraCallers } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original `next-intl` import specifier to the `@intlayer/next-intl`\n * specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-intl/server', replacement: '@intlayer/next-intl/server' },\n { request: 'next-intl/routing', replacement: '@intlayer/next-intl/routing' },\n {\n request: 'next-intl/navigation',\n replacement: '@intlayer/next-intl/navigation',\n },\n {\n request: 'next-intl/middleware',\n replacement: '@intlayer/next-intl/middleware',\n },\n { request: 'next-intl', replacement: '@intlayer/next-intl' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName?.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n string | { import?: string; require?: string; default?: string }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * SWC extra-caller configs derived from the shared caller registry\n * (`@intlayer/config/callers`) — the single source of truth also consumed by\n * the babel analyzer/optimizer and the LSP.\n */\nconst NEXT_INTL_SWC_CALLERS = toSwcExtraCallers(NEXT_INTL_CALLERS);\n\n/**\n * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-intl` imports are served by\n * `@intlayer/next-intl`.\n */\nexport const createNextIntlPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig?.system?.baseDir ?? process.cwd(),\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n absolutePath: resolveEsmPath(replacement),\n }));\n\n // Webpack resolves aliases from absolute paths.\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n absolutePath,\n ])\n );\n\n // Turbopack only honours project-root-relative `./` paths.\n const turboAlias = Object.fromEntries(\n resolvedTargets.map(({ request, absolutePath }) => [\n request,\n toTurbopackAlias(absolutePath),\n ])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n // Only inject the NEXT_LOCALE cookie default when the user has not\n // configured their own routing.storage in intlayer.config.ts.\n // This lets users override via intlayer.config.ts while keeping\n // next-intl compatibility (NEXT_LOCALE) as the default.\n let hasUserDefinedStorage = false;\n try {\n hasUserDefinedStorage = !!(\n intlayerConfig?.routing &&\n 'storage' in intlayerConfig.routing &&\n intlayerConfig.routing.storage !== undefined\n );\n } catch {\n // If the config file cannot be read, fall back to the NEXT_LOCALE default.\n }\n\n const configOptions = hasUserDefinedStorage\n ? { swcExtraCallers: NEXT_INTL_SWC_CALLERS }\n : {\n override: {\n routing: {\n storage: [\n { type: 'cookie' as const, name: 'NEXT_LOCALE' },\n { type: 'header' as const, name: 'x-intlayer-locale' },\n ],\n },\n },\n swcExtraCallers: NEXT_INTL_SWC_CALLERS,\n };\n\n return withIntlayer(mergedConfig, configOptions);\n };\n};\n\nexport default createNextIntlPlugin;\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.cjs","names":["createRequire","dirname","resolve","relative","sep","getConfiguration","getAppLogger","join","colorize","ANSIColors","withIntlayer","NEXT_INTL_CALLERS"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { NEXT_INTL_CALLERS } from '@intlayer/config/callers';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { runOnce } from '@intlayer/engine/utils';\nimport type { NextConfig } from 'next';\nimport { withIntlayer } from 'next-intlayer/server';\n\n/**\n * `require` that works in both the CJS and ESM builds of this plugin.\n * `import.meta.url` is rewritten to the module path in the CJS output by the\n * bundler, so `createRequire` resolves correctly in either format.\n */\nconst compatRequire = createRequire(import.meta.url);\n\n/**\n * Maps each original `next-intl` import specifier to the `@intlayer/next-intl`\n * specifier that should serve it instead.\n */\nconst ALIAS_ENTRIES: { request: string; replacement: string }[] = [\n { request: 'next-intl/server', replacement: '@intlayer/next-intl/server' },\n { request: 'next-intl/routing', replacement: '@intlayer/next-intl/routing' },\n {\n request: 'next-intl/navigation',\n replacement: '@intlayer/next-intl/navigation',\n },\n {\n request: 'next-intl/middleware',\n replacement: '@intlayer/next-intl/middleware',\n },\n { request: 'next-intl', replacement: '@intlayer/next-intl' },\n];\n\n/**\n * Split a package specifier into its package name and export subpath.\n *\n * @param specifier - e.g. `@intlayer/next-intl/server` or `next-intl`.\n * @returns `{ packageName, exportKey }` where `exportKey` is the `exports` map\n * key (`.` for the package root).\n */\nconst splitSpecifier = (\n specifier: string\n): { packageName: string; exportKey: string } => {\n const segments = specifier.split('/');\n const packageName = specifier.startsWith('@')\n ? segments.slice(0, 2).join('/')\n : (segments[0] ?? specifier);\n const subpath = specifier.slice(packageName?.length);\n return { packageName, exportKey: subpath === '' ? '.' : `.${subpath}` };\n};\n\n/**\n * Resolve the absolute path of a package export, preferring the ESM (`import`)\n * condition so Turbopack and modern bundlers load the `.mjs` build (which keeps\n * the `\"use client\"` directives) rather than the CommonJS fallback.\n *\n * Both Turbopack and webpack ignore alias values that are bare package\n * specifiers, so the aliases must point at real files.\n *\n * @param specifier - Package specifier, e.g. `@intlayer/next-intl/server`.\n * @returns Absolute path to the resolved module file.\n */\nconst resolveEsmPath = (specifier: string): string => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<\n string,\n | string\n | {\n 'react-server'?: string;\n import?: string;\n require?: string;\n default?: string;\n }\n >;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string'\n ? exportEntry\n : (exportEntry?.import ?? exportEntry?.require ?? exportEntry?.default);\n\n // Fall back to Node resolution if the exports map is unexpected.\n if (!relativeFile) return compatRequire.resolve(specifier);\n\n return resolve(packageDir, relativeFile);\n};\n\n/**\n * Absolute path of a specifier's `react-server` export condition, when the\n * package declares one.\n *\n * Aliasing to a file bypasses the package's `exports` map, so the condition\n * would never be consulted — the alias itself has to carry it. Without this,\n * every Server Component resolves the client build of `useTranslations`, gets\n * pulled across the client boundary, and drags its dictionary into a chunk\n * Next shares across every locale.\n */\nconst resolveReactServerPath = (specifier: string): string | undefined => {\n const { packageName, exportKey } = splitSpecifier(specifier);\n const packageJson = compatRequire(`${packageName}/package.json`) as {\n exports?: Record<string, string | { 'react-server'?: string }>;\n };\n const packageDir = dirname(\n compatRequire.resolve(`${packageName}/package.json`)\n );\n\n const exportEntry = packageJson.exports?.[exportKey];\n const relativeFile =\n typeof exportEntry === 'string' ? undefined : exportEntry?.['react-server'];\n\n return relativeFile ? resolve(packageDir, relativeFile) : undefined;\n};\n\n/**\n * Format an absolute path as a project-root-relative specifier (prefixed with\n * `./` and using forward slashes). Turbopack only honours `resolveAlias` values\n * that are project-root-relative paths — bare specifiers are ignored and\n * absolute paths are misread as root-relative. Mirrors `withIntlayer`'s\n * Turbopack alias formatter.\n *\n * @param absolutePath - Absolute path to the target module file.\n * @returns Relative specifier such as `./node_modules/@intlayer/next-intl/...`.\n */\nconst toTurbopackAlias = (absolutePath: string): string =>\n `./${relative(process.cwd(), absolutePath).split(sep).join('/')}`;\n\n/**\n * A Next.js plugin for next-intl compat that wraps next-intlayer's plugin\n * and configures resolve aliases so `next-intl` imports are served by\n * `@intlayer/next-intl`.\n */\nexport const createNextIntlPlugin = (_i18nPath?: string) => {\n return async (nextConfig: NextConfig = {}): Promise<NextConfig> => {\n const intlayerConfig = getConfiguration();\n const appLogger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(\n intlayerConfig?.system?.baseDir ?? process.cwd(),\n '.intlayer',\n 'cache',\n 'intlayer-issues-invitation.lock'\n ),\n () => {\n appLogger([\n colorize(\n 'Please report any issues you met on GitHub:',\n ANSIColors.GREY\n ),\n colorize(\n 'https://github.com/aymericzip/intlayer/issues',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n },\n {\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n }\n );\n\n const customWebpack = nextConfig.webpack;\n\n const resolvedTargets = ALIAS_ENTRIES.map(({ request, replacement }) => ({\n request,\n replacement,\n hasReactServerBuild: Boolean(resolveReactServerPath(replacement)),\n }));\n\n /**\n * Aliasing to a resolved *file* pins one build of the target and bypasses\n * its `exports` map — so the `react-server` condition is never consulted\n * and a Server Component silently gets the client build of\n * `useTranslations`. That drags every component calling it across the\n * client boundary, and with it the multi-locale dictionary, into a chunk\n * Next serves to every locale.\n *\n * Aliasing to the package specifier instead lets the bundler resolve\n * normally, so each layer picks its own condition.\n */\n const aliasTarget = ({\n replacement,\n hasReactServerBuild,\n }: {\n replacement: string;\n hasReactServerBuild: boolean;\n }) =>\n hasReactServerBuild\n ? replacement\n : toTurbopackAlias(resolveEsmPath(replacement));\n\n const webpackAlias = Object.fromEntries(\n resolvedTargets.map(({ request, replacement, hasReactServerBuild }) => [\n request,\n hasReactServerBuild ? replacement : resolveEsmPath(replacement),\n ])\n );\n\n const turboAlias = Object.fromEntries(\n resolvedTargets.map((target) => [target.request, aliasTarget(target)])\n );\n\n const aliasConfig = {\n webpack: (config: any, options: any) => {\n config.resolve.alias = {\n ...config.resolve.alias,\n ...webpackAlias,\n };\n\n if (typeof customWebpack === 'function') {\n return customWebpack(config, options);\n }\n return config;\n },\n };\n\n const mergedConfig: NextConfig = {\n ...nextConfig,\n ...aliasConfig,\n turbopack: {\n ...(nextConfig.turbopack ?? {}),\n resolveAlias: {\n ...(nextConfig.turbopack?.resolveAlias ?? {}),\n ...turboAlias,\n },\n },\n };\n\n // Only inject the NEXT_LOCALE cookie default when the user has not\n // configured their own routing.storage in intlayer.config.ts.\n // This lets users override via intlayer.config.ts while keeping\n // next-intl compatibility (NEXT_LOCALE) as the default.\n let hasUserDefinedStorage = false;\n try {\n hasUserDefinedStorage = !!(\n intlayerConfig?.routing &&\n 'storage' in intlayerConfig.routing &&\n intlayerConfig.routing.storage !== undefined\n );\n } catch {\n // If the config file cannot be read, fall back to the NEXT_LOCALE default.\n }\n\n const configOptions = hasUserDefinedStorage\n ? { compatCallers: NEXT_INTL_CALLERS }\n : {\n override: {\n routing: {\n storage: [\n { type: 'cookie' as const, name: 'NEXT_LOCALE' },\n { type: 'header' as const, name: 'x-intlayer-locale' },\n ],\n },\n },\n compatCallers: NEXT_INTL_CALLERS,\n };\n\n return withIntlayer(mergedConfig, configOptions);\n };\n};\n\nexport default createNextIntlPlugin;\n"],"mappings":"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"}
@@ -0,0 +1,20 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_react_server_useLocale = require('./useLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+
5
+ //#region src/react-server/helpers.ts
6
+ /**
7
+ * Server counterparts of use-intl's ambient hooks. They mirror the client
8
+ * versions' signatures so the same component code type-checks on both sides.
9
+ */
10
+ const useFormatter = (() => (0, _intlayer_use_intl.createFormatter)({ locale: require_react_server_useLocale.useLocale() }));
11
+ /** Current time on the server render. */
12
+ const useNow = (() => /* @__PURE__ */ new Date());
13
+ /** Time zone used by the formatters; UTC unless the app overrides it. */
14
+ const useTimeZone = (() => void 0);
15
+
16
+ //#endregion
17
+ exports.useFormatter = useFormatter;
18
+ exports.useNow = useNow;
19
+ exports.useTimeZone = useTimeZone;
20
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","names":["createFormatter","useLocale"],"sources":["../../../src/react-server/helpers.ts"],"sourcesContent":["import { createFormatter } from '@intlayer/use-intl';\nimport { useLocale } from './useLocale';\n\n/**\n * Server counterparts of use-intl's ambient hooks. They mirror the client\n * versions' signatures so the same component code type-checks on both sides.\n */\nexport const useFormatter: typeof import('@intlayer/use-intl').useFormatter =\n (() => createFormatter({ locale: useLocale() as string })) as never;\n\n/** Current time on the server render. */\nexport const useNow: typeof import('@intlayer/use-intl').useNow = (() =>\n new Date()) as never;\n\n/** Time zone used by the formatters; UTC unless the app overrides it. */\nexport const useTimeZone: typeof import('@intlayer/use-intl').useTimeZone =\n (() => undefined) as never;\n"],"mappings":";;;;;;;;;AAOA,MAAa,0BACJA,oCAAgB,EAAE,QAAQC,yCAAU,EAAY,CAAC;;AAG1D,MAAa,gCACX,IAAI,KAAK;;AAGX,MAAa,qBACJ"}
@@ -0,0 +1,61 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_routing = require('../routing.cjs');
3
+ const require_client_NextIntlClientProvider = require('../client/NextIntlClientProvider.cjs');
4
+ const require_react_server_useTranslations = require('./useTranslations.cjs');
5
+ const require_react_server_useLocale = require('./useLocale.cjs');
6
+ const require_react_server_helpers = require('./helpers.cjs');
7
+ const require_react_server_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
8
+ const require_react_server_useDictionary = require('./useDictionary.cjs');
9
+ let _intlayer_use_intl = require("@intlayer/use-intl");
10
+
11
+ Object.defineProperty(exports, 'IntlError', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _intlayer_use_intl.IntlError;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, 'IntlErrorCode', {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _intlayer_use_intl.IntlErrorCode;
21
+ }
22
+ });
23
+ exports.NextIntlClientProvider = require_client_NextIntlClientProvider.NextIntlClientProvider;
24
+ Object.defineProperty(exports, 'createFormatter', {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _intlayer_use_intl.createFormatter;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, 'createTranslator', {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _intlayer_use_intl.createTranslator;
34
+ }
35
+ });
36
+ exports.defineRouting = require_routing.defineRouting;
37
+ Object.defineProperty(exports, 'hasLocale', {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _intlayer_use_intl.hasLocale;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, 'initializeConfig', {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _intlayer_use_intl.initializeConfig;
47
+ }
48
+ });
49
+ exports.useDictionary = require_react_server_useDictionary.useDictionary;
50
+ exports.useDictionaryDynamic = require_react_server_useDictionaryDynamic.useDictionaryDynamic;
51
+ exports.useFormatter = require_react_server_helpers.useFormatter;
52
+ exports.useLocale = require_react_server_useLocale.useLocale;
53
+ Object.defineProperty(exports, 'useMessages', {
54
+ enumerable: true,
55
+ get: function () {
56
+ return _intlayer_use_intl.useMessages;
57
+ }
58
+ });
59
+ exports.useNow = require_react_server_helpers.useNow;
60
+ exports.useTimeZone = require_react_server_helpers.useTimeZone;
61
+ exports.useTranslations = require_react_server_useTranslations.useTranslations;
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_requestLocaleCache = require('../server/requestLocaleCache.cjs');
3
+ let next_intlayer_server = require("next-intlayer/server");
4
+
5
+ //#region src/react-server/resolveLocale.ts
6
+ /**
7
+ * Locale for a synchronous server hook, resolved the same way `getLocale()`
8
+ * resolves it — so server-rendered content and the client provider never
9
+ * disagree about which locale the request is in.
10
+ *
11
+ * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
12
+ * route segment), which is next-intl's source of truth for URL routing.
13
+ * 2. Otherwise Intlayer's ambient locale (server context, then the request).
14
+ */
15
+ const resolveServerLocale = () => require_server_requestLocaleCache.getCachedRequestLocale() ?? (0, next_intlayer_server.useLocale)().locale;
16
+
17
+ //#endregion
18
+ exports.resolveServerLocale = resolveServerLocale;
19
+ //# sourceMappingURL=resolveLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLocale.cjs","names":["getCachedRequestLocale","useLocaleIntlayer"],"sources":["../../../src/react-server/resolveLocale.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useLocale as useLocaleIntlayer } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from '../server/requestLocaleCache';\n\n/**\n * Locale for a synchronous server hook, resolved the same way `getLocale()`\n * resolves it — so server-rendered content and the client provider never\n * disagree about which locale the request is in.\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment), which is next-intl's source of truth for URL routing.\n * 2. Otherwise Intlayer's ambient locale (server context, then the request).\n */\nexport const resolveServerLocale = (): LocalesValues =>\n (getCachedRequestLocale() ??\n useLocaleIntlayer().locale) as LocalesValues;\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,4BACVA,yDAAuB,SACtBC,gCAAkB,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_react_server_resolveLocale = require('./resolveLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+ let next_intlayer_server = require("next-intlayer/server");
5
+
6
+ //#region src/react-server/useDictionary.ts
7
+ /**
8
+ * Server counterpart of `@intlayer/use-intl`'s `useDictionary`.
9
+ *
10
+ * The optimize pass rewrites every `useTranslations(...)` call to this helper
11
+ * with the dictionary pre-imported. Resolving it here — rather than in a client
12
+ * component — keeps the dictionary out of the client bundle entirely: the
13
+ * server renders the text and only the rendered output crosses the boundary.
14
+ */
15
+ const useDictionary = ((dictionary, namespacePrefix) => {
16
+ const locale = require_react_server_resolveLocale.resolveServerLocale();
17
+ const content = (0, next_intlayer_server.useDictionary)(dictionary, locale);
18
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, namespacePrefix);
19
+ });
20
+
21
+ //#endregion
22
+ exports.useDictionary = useDictionary;
23
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["resolveServerLocale","useDictionaryBase","createDictionaryTranslator"],"sources":["../../../src/react-server/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type ScopedTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { useDictionary as useDictionaryBase } from 'next-intlayer/server';\nimport { resolveServerLocale } from './resolveLocale';\n\n/**\n * Overload set mirroring the client `useDictionary` exactly, so the optimize\n * pass can emit the same call shape whichever side of the boundary the\n * component ends up on.\n */\ntype UseDictionary = {\n <T extends Dictionary>(\n dictionary: T\n ): TranslateFunction<T['key'] & DictionaryKeys>;\n <T extends Dictionary, Prefix extends string>(\n dictionary: T,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>;\n};\n\n/**\n * Server counterpart of `@intlayer/use-intl`'s `useDictionary`.\n *\n * The optimize pass rewrites every `useTranslations(...)` call to this helper\n * with the dictionary pre-imported. Resolving it here — rather than in a client\n * component — keeps the dictionary out of the client bundle entirely: the\n * server renders the text and only the rendered output crosses the boundary.\n */\nexport const useDictionary = (<T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const locale = resolveServerLocale();\n const content = useDictionaryBase(dictionary, locale as never);\n\n return createDictionaryTranslator(\n locale,\n content,\n namespacePrefix\n );\n}) as UseDictionary;\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAa,kBACX,YACA,oBACG;CACH,MAAM,SAASA,uDAAoB;CACnC,MAAM,cAAUC,oCAAkB,YAAY,MAAe;CAE7D,WAAOC,+CACL,QACA,SACA,eACF;AACF"}
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_react_server_resolveLocale = require('./resolveLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+ let next_intlayer_server = require("next-intlayer/server");
5
+
6
+ //#region src/react-server/useDictionaryDynamic.ts
7
+ /**
8
+ * Server counterpart of `useDictionaryDynamic`, emitted by the optimize pass
9
+ * for dictionaries on the per-locale loader.
10
+ */
11
+ const useDictionaryDynamic = ((dictionaryPromise, key, namespacePrefix) => {
12
+ const locale = require_react_server_resolveLocale.resolveServerLocale();
13
+ const content = (0, next_intlayer_server.useDictionaryDynamic)(dictionaryPromise, key, locale);
14
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, namespacePrefix);
15
+ });
16
+
17
+ //#endregion
18
+ exports.useDictionaryDynamic = useDictionaryDynamic;
19
+ //# sourceMappingURL=useDictionaryDynamic.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["resolveServerLocale","useDictionaryDynamicBase","createDictionaryTranslator"],"sources":["../../../src/react-server/useDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type ScopedTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'next-intlayer/server';\nimport { resolveServerLocale } from './resolveLocale';\n\ntype UseDictionaryDynamic = {\n <T extends Dictionary, K extends DictionaryKeys>(\n dictionaryPromise: Record<string, () => Promise<T>>,\n key: K\n ): TranslateFunction<K>;\n <T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(\n dictionaryPromise: Record<string, () => Promise<T>>,\n key: K,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<K, Prefix>;\n};\n\n/**\n * Server counterpart of `useDictionaryDynamic`, emitted by the optimize pass\n * for dictionaries on the per-locale loader.\n */\nexport const useDictionaryDynamic = ((\n dictionaryPromise: Record<string, () => Promise<Dictionary>>,\n key: string,\n namespacePrefix?: string\n) => {\n const locale = resolveServerLocale();\n const content = useDictionaryDynamicBase(\n dictionaryPromise as never,\n key as never,\n locale as never\n );\n\n return createDictionaryTranslator(\n locale,\n content,\n namespacePrefix\n );\n}) as UseDictionaryDynamic;\n"],"mappings":";;;;;;;;;;AA6BA,MAAa,yBACX,mBACA,KACA,oBACG;CACH,MAAM,SAASA,uDAAoB;CACnC,MAAM,cAAUC,2CACd,mBACA,KACA,MACF;CAEA,WAAOC,+CACL,QACA,SACA,eACF;AACF"}
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_react_server_resolveLocale = require('./resolveLocale.cjs');
3
+
4
+ //#region src/react-server/useLocale.ts
5
+ /**
6
+ * Server counterpart of `useLocale`, resolved from the `[locale]` route segment
7
+ * forwarded through `setRequestLocale` when the app provides one.
8
+ */
9
+ const useLocale = () => require_react_server_resolveLocale.resolveServerLocale();
10
+
11
+ //#endregion
12
+ exports.useLocale = useLocale;
13
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":["resolveServerLocale"],"sources":["../../../src/react-server/useLocale.ts"],"sourcesContent":["import type { useLocale as _useLocale } from 'next-intl';\nimport { resolveServerLocale } from './resolveLocale';\n\n/**\n * Server counterpart of `useLocale`, resolved from the `[locale]` route segment\n * forwarded through `setRequestLocale` when the app provides one.\n */\nexport const useLocale: typeof _useLocale = () =>\n resolveServerLocale() as ReturnType<typeof _useLocale>;\n"],"mappings":";;;;;;;;AAOA,MAAa,kBACXA,uDAAoB"}
@@ -0,0 +1,42 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_react_server_resolveLocale = require('./resolveLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+ let next_intlayer_server = require("next-intlayer/server");
5
+
6
+ //#region src/react-server/useTranslations.ts
7
+ /** Splits `'about.counter'` into the dictionary key and its key prefix. */
8
+ const splitNamespace = (namespace) => {
9
+ const dotPosition = namespace.indexOf(".");
10
+ if (dotPosition === -1) return [namespace, void 0];
11
+ return [namespace.slice(0, dotPosition), namespace.slice(dotPosition + 1)];
12
+ };
13
+ /**
14
+ * Server counterpart of `useTranslations`.
15
+ *
16
+ * next-intl's `useTranslations` is isomorphic — the same component code runs in
17
+ * a Server or a Client Component — so the adapter has to be too. Without this
18
+ * every component calling it is forced across the client boundary, which drags
19
+ * its dictionary into a client chunk that Next shares across every locale.
20
+ *
21
+ * The optimize pass normally rewrites these calls to `useDictionary` with the
22
+ * dictionary inlined; this runtime path covers the calls it could not resolve
23
+ * statically (a dynamic namespace, or an unoptimized build).
24
+ */
25
+ const useTranslations = ((namespace) => {
26
+ const locale = require_react_server_resolveLocale.resolveServerLocale();
27
+ if (!namespace) {
28
+ const rootTranslator = (key, values) => {
29
+ const [dictionaryKey, keyPrefix] = splitNamespace(key);
30
+ const content = (0, next_intlayer_server.useIntlayer)(dictionaryKey, locale);
31
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, void 0)(keyPrefix ?? "", values);
32
+ };
33
+ return rootTranslator;
34
+ }
35
+ const [dictionaryKey, keyPrefix] = splitNamespace(namespace);
36
+ const content = (0, next_intlayer_server.useIntlayer)(dictionaryKey, locale);
37
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, keyPrefix);
38
+ });
39
+
40
+ //#endregion
41
+ exports.useTranslations = useTranslations;
42
+ //# sourceMappingURL=useTranslations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.cjs","names":["resolveServerLocale","useIntlayer","createDictionaryTranslator"],"sources":["../../../src/react-server/useTranslations.ts"],"sourcesContent":["import type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type LooseTranslateFunction,\n type TranslateFunction,\n type TranslateFunctionForNamespace,\n} from '@intlayer/use-intl';\nimport { useIntlayer } from 'next-intlayer/server';\nimport { resolveServerLocale } from './resolveLocale';\n\ntype UseTranslations = {\n <N extends DictionaryKeys>(namespace: N): TranslateFunction<N>;\n <N extends `${string}.${string}`>(\n namespace: N\n ): TranslateFunctionForNamespace<N>;\n (): LooseTranslateFunction;\n};\n\n/** Splits `'about.counter'` into the dictionary key and its key prefix. */\nconst splitNamespace = (namespace: string): [string, string | undefined] => {\n const dotPosition = namespace.indexOf('.');\n if (dotPosition === -1) return [namespace, undefined];\n return [namespace.slice(0, dotPosition), namespace.slice(dotPosition + 1)];\n};\n\n/**\n * Server counterpart of `useTranslations`.\n *\n * next-intl's `useTranslations` is isomorphic — the same component code runs in\n * a Server or a Client Component — so the adapter has to be too. Without this\n * every component calling it is forced across the client boundary, which drags\n * its dictionary into a client chunk that Next shares across every locale.\n *\n * The optimize pass normally rewrites these calls to `useDictionary` with the\n * dictionary inlined; this runtime path covers the calls it could not resolve\n * statically (a dynamic namespace, or an unoptimized build).\n */\nexport const useTranslations = ((namespace?: string) => {\n const locale = resolveServerLocale();\n\n if (!namespace) {\n // Root scope: the first segment of each message id names the dictionary,\n // so the lookup can only happen per call.\n const rootTranslator = (key: string, values?: Record<string, unknown>) => {\n const [dictionaryKey, keyPrefix] = splitNamespace(key);\n const content = useIntlayer(dictionaryKey as never, locale as never);\n const translate = createDictionaryTranslator(locale, content, undefined);\n return translate(keyPrefix ?? '', values as never);\n };\n return rootTranslator as unknown as LooseTranslateFunction;\n }\n\n const [dictionaryKey, keyPrefix] = splitNamespace(namespace);\n const content = useIntlayer(dictionaryKey as never, locale as never);\n\n return createDictionaryTranslator(locale, content, keyPrefix);\n}) as UseTranslations;\n"],"mappings":";;;;;;;AAmBA,MAAM,kBAAkB,cAAoD;CAC1E,MAAM,cAAc,UAAU,QAAQ,GAAG;CACzC,IAAI,gBAAgB,IAAI,OAAO,CAAC,WAAW,MAAS;CACpD,OAAO,CAAC,UAAU,MAAM,GAAG,WAAW,GAAG,UAAU,MAAM,cAAc,CAAC,CAAC;AAC3E;;;;;;;;;;;;;AAcA,MAAa,oBAAoB,cAAuB;CACtD,MAAM,SAASA,uDAAoB;CAEnC,IAAI,CAAC,WAAW;EAGd,MAAM,kBAAkB,KAAa,WAAqC;GACxE,MAAM,CAAC,eAAe,aAAa,eAAe,GAAG;GACrD,MAAM,cAAUC,kCAAY,eAAwB,MAAe;GAEnE,WADkBC,+CAA2B,QAAQ,SAAS,MAC/C,CAAC,CAAC,aAAa,IAAI,MAAe;EACnD;EACA,OAAO;CACT;CAEA,MAAM,CAAC,eAAe,aAAa,eAAe,SAAS;CAC3D,MAAM,cAAUD,kCAAY,eAAwB,MAAe;CAEnE,WAAOC,+CAA2B,QAAQ,SAAS,SAAS;AAC9D"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_react_useLocale = require('./useLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+
5
+ //#region src/server/react/helpers.ts
6
+ /**
7
+ * Server counterparts of use-intl's ambient hooks. They mirror the client
8
+ * versions' signatures so the same component code type-checks on both sides.
9
+ */
10
+ const useFormatter = (() => (0, _intlayer_use_intl.createFormatter)({ locale: require_server_react_useLocale.useLocale() }));
11
+ /** Current time on the server render. */
12
+ const useNow = (() => /* @__PURE__ */ new Date());
13
+ /**
14
+ * Time zone the formatters resolve against — the same value the async
15
+ * `getTimeZone()` reports, so both server surfaces agree.
16
+ */
17
+ const useTimeZone = (() => Intl.DateTimeFormat().resolvedOptions().timeZone);
18
+
19
+ //#endregion
20
+ exports.useFormatter = useFormatter;
21
+ exports.useNow = useNow;
22
+ exports.useTimeZone = useTimeZone;
23
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","names":["createFormatter","useLocale"],"sources":["../../../../src/server/react/helpers.ts"],"sourcesContent":["import { createFormatter } from '@intlayer/use-intl';\nimport { useLocale } from './useLocale';\n\n/**\n * Server counterparts of use-intl's ambient hooks. They mirror the client\n * versions' signatures so the same component code type-checks on both sides.\n */\nexport const useFormatter: typeof import('@intlayer/use-intl').useFormatter =\n (() => createFormatter({ locale: useLocale() as string })) as never;\n\n/** Current time on the server render. */\nexport const useNow: typeof import('@intlayer/use-intl').useNow = (() =>\n new Date()) as never;\n\n/**\n * Time zone the formatters resolve against — the same value the async\n * `getTimeZone()` reports, so both server surfaces agree.\n */\nexport const useTimeZone: typeof import('@intlayer/use-intl').useTimeZone =\n (() => Intl.DateTimeFormat().resolvedOptions().timeZone) as never;\n"],"mappings":";;;;;;;;;AAOA,MAAa,0BACJA,oCAAgB,EAAE,QAAQC,yCAAU,EAAY,CAAC;;AAG1D,MAAa,gCACX,IAAI,KAAK;;;;;AAMX,MAAa,qBACJ,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,61 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_routing = require('../../routing.cjs');
3
+ const require_client_NextIntlClientProvider = require('../../client/NextIntlClientProvider.cjs');
4
+ const require_server_react_useTranslations = require('./useTranslations.cjs');
5
+ const require_server_react_useLocale = require('./useLocale.cjs');
6
+ const require_server_react_helpers = require('./helpers.cjs');
7
+ const require_server_react_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
8
+ const require_server_react_useDictionary = require('./useDictionary.cjs');
9
+ let _intlayer_use_intl = require("@intlayer/use-intl");
10
+
11
+ Object.defineProperty(exports, 'IntlError', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _intlayer_use_intl.IntlError;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, 'IntlErrorCode', {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _intlayer_use_intl.IntlErrorCode;
21
+ }
22
+ });
23
+ exports.NextIntlClientProvider = require_client_NextIntlClientProvider.NextIntlClientProvider;
24
+ Object.defineProperty(exports, 'createFormatter', {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _intlayer_use_intl.createFormatter;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, 'createTranslator', {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _intlayer_use_intl.createTranslator;
34
+ }
35
+ });
36
+ exports.defineRouting = require_routing.defineRouting;
37
+ Object.defineProperty(exports, 'hasLocale', {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _intlayer_use_intl.hasLocale;
41
+ }
42
+ });
43
+ Object.defineProperty(exports, 'initializeConfig', {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _intlayer_use_intl.initializeConfig;
47
+ }
48
+ });
49
+ exports.useDictionary = require_server_react_useDictionary.useDictionary;
50
+ exports.useDictionaryDynamic = require_server_react_useDictionaryDynamic.useDictionaryDynamic;
51
+ exports.useFormatter = require_server_react_helpers.useFormatter;
52
+ exports.useLocale = require_server_react_useLocale.useLocale;
53
+ Object.defineProperty(exports, 'useMessages', {
54
+ enumerable: true,
55
+ get: function () {
56
+ return _intlayer_use_intl.useMessages;
57
+ }
58
+ });
59
+ exports.useNow = require_server_react_helpers.useNow;
60
+ exports.useTimeZone = require_server_react_helpers.useTimeZone;
61
+ exports.useTranslations = require_server_react_useTranslations.useTranslations;
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_requestLocaleCache = require('../requestLocaleCache.cjs');
3
+ let next_intlayer_server = require("next-intlayer/server");
4
+
5
+ //#region src/server/react/resolveLocale.ts
6
+ /**
7
+ * Locale for the synchronous server hooks, resolved the way `getLocale()`
8
+ * resolves it — so server-rendered output and the client provider never
9
+ * disagree about which locale the request is in.
10
+ *
11
+ * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
12
+ * route segment), which is next-intl's source of truth for URL routing.
13
+ * 2. Otherwise Intlayer's ambient locale (server context, then the request).
14
+ *
15
+ * The second rung must stay lazy. It ends in `headers()` / `cookies()`, which
16
+ * opts the route into dynamic rendering: evaluating it eagerly took this
17
+ * package's own benchmark app from 14 prerendered pages to 0.
18
+ */
19
+ const resolveServerLocale = () => {
20
+ const requestLocale = require_server_requestLocaleCache.getCachedRequestLocale();
21
+ if (requestLocale) return requestLocale;
22
+ return (0, next_intlayer_server.useLocale)().locale;
23
+ };
24
+
25
+ //#endregion
26
+ exports.resolveServerLocale = resolveServerLocale;
27
+ //# sourceMappingURL=resolveLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLocale.cjs","names":["getCachedRequestLocale","readAmbientLocale"],"sources":["../../../../src/server/react/resolveLocale.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\n// Not a React hook despite the name: `next-intlayer/server` prefixes its\n// server readers with `use` for symmetry with the client API, but they hold no\n// positional state — its own `resolveFallbackLocale` documents that this is\n// exactly what lets them run conditionally. Bound to a plain name here so the\n// call below reads as what it is.\nimport { useLocale as readAmbientLocale } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from '../requestLocaleCache';\n\n/**\n * Locale for the synchronous server hooks, resolved the way `getLocale()`\n * resolves it — so server-rendered output and the client provider never\n * disagree about which locale the request is in.\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment), which is next-intl's source of truth for URL routing.\n * 2. Otherwise Intlayer's ambient locale (server context, then the request).\n *\n * The second rung must stay lazy. It ends in `headers()` / `cookies()`, which\n * opts the route into dynamic rendering: evaluating it eagerly took this\n * package's own benchmark app from 14 prerendered pages to 0.\n */\nexport const resolveServerLocale = (): LocalesValues => {\n const requestLocale = getCachedRequestLocale();\n if (requestLocale) return requestLocale as LocalesValues;\n\n return readAmbientLocale().locale as LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,MAAa,4BAA2C;CACtD,MAAM,gBAAgBA,yDAAuB;CAC7C,IAAI,eAAe,OAAO;CAE1B,WAAOC,gCAAkB,CAAC,CAAC;AAC7B"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_react_resolveLocale = require('./resolveLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+ let next_intlayer_server = require("next-intlayer/server");
5
+
6
+ //#region src/server/react/useDictionary.ts
7
+ /**
8
+ * Server counterpart of `@intlayer/use-intl`'s `useDictionary`.
9
+ *
10
+ * The optimize pass rewrites every `useTranslations(...)` call to this helper
11
+ * with the dictionary pre-imported. Resolving it here — rather than in a client
12
+ * component — keeps the dictionary out of the client bundle entirely: the
13
+ * server renders the text and only the rendered output crosses the boundary.
14
+ */
15
+ const useDictionary = ((dictionary, namespacePrefix) => {
16
+ const locale = require_server_react_resolveLocale.resolveServerLocale();
17
+ const content = (0, next_intlayer_server.useDictionary)(dictionary, locale);
18
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, namespacePrefix);
19
+ });
20
+
21
+ //#endregion
22
+ exports.useDictionary = useDictionary;
23
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["resolveServerLocale","useDictionaryBase","createDictionaryTranslator"],"sources":["../../../../src/server/react/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type ScopedTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { useDictionary as useDictionaryBase } from 'next-intlayer/server';\nimport { resolveServerLocale } from './resolveLocale';\n\n/**\n * Overload set mirroring the client `useDictionary` exactly, so the optimize\n * pass can emit the same call shape whichever side of the boundary the\n * component ends up on.\n */\ntype UseDictionary = {\n <T extends Dictionary>(\n dictionary: T\n ): TranslateFunction<T['key'] & DictionaryKeys>;\n <T extends Dictionary, Prefix extends string>(\n dictionary: T,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>;\n};\n\n/**\n * Server counterpart of `@intlayer/use-intl`'s `useDictionary`.\n *\n * The optimize pass rewrites every `useTranslations(...)` call to this helper\n * with the dictionary pre-imported. Resolving it here — rather than in a client\n * component — keeps the dictionary out of the client bundle entirely: the\n * server renders the text and only the rendered output crosses the boundary.\n */\nexport const useDictionary = (<T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const locale = resolveServerLocale();\n const content = useDictionaryBase(dictionary, locale as never);\n\n return createDictionaryTranslator(locale, content, namespacePrefix);\n}) as UseDictionary;\n"],"mappings":";;;;;;;;;;;;;;AAiCA,MAAa,kBACX,YACA,oBACG;CACH,MAAM,SAASA,uDAAoB;CACnC,MAAM,cAAUC,oCAAkB,YAAY,MAAe;CAE7D,WAAOC,+CAA2B,QAAQ,SAAS,eAAe;AACpE"}
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_react_resolveLocale = require('./resolveLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
+ let next_intlayer_server = require("next-intlayer/server");
5
+
6
+ //#region src/server/react/useDictionaryDynamic.ts
7
+ /**
8
+ * Server counterpart of `useDictionaryDynamic`, emitted by the optimize pass
9
+ * for dictionaries on the per-locale loader.
10
+ */
11
+ const useDictionaryDynamic = ((dictionaryPromise, key, namespacePrefix) => {
12
+ const locale = require_server_react_resolveLocale.resolveServerLocale();
13
+ const content = (0, next_intlayer_server.useDictionaryDynamic)(dictionaryPromise, key, locale);
14
+ return (0, _intlayer_use_intl.createDictionaryTranslator)(locale, content, namespacePrefix);
15
+ });
16
+
17
+ //#endregion
18
+ exports.useDictionaryDynamic = useDictionaryDynamic;
19
+ //# sourceMappingURL=useDictionaryDynamic.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["resolveServerLocale","useDictionaryDynamicBase","createDictionaryTranslator"],"sources":["../../../../src/server/react/useDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { DictionaryKeys } from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type ScopedTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'next-intlayer/server';\nimport { resolveServerLocale } from './resolveLocale';\n\ntype UseDictionaryDynamic = {\n <T extends Dictionary, K extends DictionaryKeys>(\n dictionaryPromise: Record<string, () => Promise<T>>,\n key: K\n ): TranslateFunction<K>;\n <T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(\n dictionaryPromise: Record<string, () => Promise<T>>,\n key: K,\n namespacePrefix: Prefix\n ): ScopedTranslateFunction<K, Prefix>;\n};\n\n/**\n * Server counterpart of `useDictionaryDynamic`, emitted by the optimize pass\n * for dictionaries on the per-locale loader.\n */\nexport const useDictionaryDynamic = ((\n dictionaryPromise: Record<string, () => Promise<Dictionary>>,\n key: string,\n namespacePrefix?: string\n) => {\n const locale = resolveServerLocale();\n const content = useDictionaryDynamicBase(\n dictionaryPromise as never,\n key as never,\n locale as never\n );\n\n return createDictionaryTranslator(locale, content, namespacePrefix);\n}) as UseDictionaryDynamic;\n"],"mappings":";;;;;;;;;;AA0BA,MAAa,yBACX,mBACA,KACA,oBACG;CACH,MAAM,SAASA,uDAAoB;CACnC,MAAM,cAAUC,2CACd,mBACA,KACA,MACF;CAEA,WAAOC,+CAA2B,QAAQ,SAAS,eAAe;AACpE"}
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_react_resolveLocale = require('./resolveLocale.cjs');
3
+
4
+ //#region src/server/react/useLocale.ts
5
+ /**
6
+ * Server counterpart of `useLocale`, resolved from the `[locale]` route segment
7
+ * forwarded through `setRequestLocale` when the app provides one.
8
+ */
9
+ const useLocale = () => require_server_react_resolveLocale.resolveServerLocale();
10
+
11
+ //#endregion
12
+ exports.useLocale = useLocale;
13
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":["resolveServerLocale"],"sources":["../../../../src/server/react/useLocale.ts"],"sourcesContent":["import type { useLocale as _useLocale } from 'next-intl';\nimport { resolveServerLocale } from './resolveLocale';\n\n/**\n * Server counterpart of `useLocale`, resolved from the `[locale]` route segment\n * forwarded through `setRequestLocale` when the app provides one.\n */\nexport const useLocale: typeof _useLocale = () =>\n resolveServerLocale() as ReturnType<typeof _useLocale>;\n"],"mappings":";;;;;;;;AAOA,MAAa,kBACXA,uDAAoB"}