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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/cjs/client/NextIntlClientProvider.cjs +8 -4
  2. package/dist/cjs/client/NextIntlClientProvider.cjs.map +1 -1
  3. package/dist/cjs/client/index.cjs +55 -13
  4. package/dist/cjs/client/useLocale.cjs +0 -1
  5. package/dist/cjs/client/useLocale.cjs.map +1 -1
  6. package/dist/cjs/getDictionary.cjs +19 -30
  7. package/dist/cjs/getDictionary.cjs.map +1 -1
  8. package/dist/cjs/getDictionaryDynamic.cjs +8 -24
  9. package/dist/cjs/getDictionaryDynamic.cjs.map +1 -1
  10. package/dist/cjs/index.cjs +91 -15
  11. package/dist/cjs/middleware.cjs +0 -1
  12. package/dist/cjs/middleware.cjs.map +1 -1
  13. package/dist/cjs/navigation/Link.cjs.map +1 -1
  14. package/dist/cjs/navigation/createNavigation.cjs +0 -1
  15. package/dist/cjs/navigation/createNavigation.cjs.map +1 -1
  16. package/dist/cjs/navigation/hooks.cjs +0 -1
  17. package/dist/cjs/navigation/hooks.cjs.map +1 -1
  18. package/dist/cjs/navigation/localizeHref.cjs +0 -1
  19. package/dist/cjs/navigation/localizeHref.cjs.map +1 -1
  20. package/dist/cjs/plugin/index.cjs +9 -15
  21. package/dist/cjs/plugin/index.cjs.map +1 -1
  22. package/dist/cjs/routing.cjs +0 -1
  23. package/dist/cjs/routing.cjs.map +1 -1
  24. package/dist/cjs/server/getLocale.cjs +15 -2
  25. package/dist/cjs/server/getLocale.cjs.map +1 -1
  26. package/dist/cjs/server/getMessages.cjs +0 -1
  27. package/dist/cjs/server/getMessages.cjs.map +1 -1
  28. package/dist/cjs/server/getRequestConfig.cjs +27 -0
  29. package/dist/cjs/server/getRequestConfig.cjs.map +1 -0
  30. package/dist/cjs/server/getTranslations.cjs +8 -4
  31. package/dist/cjs/server/getTranslations.cjs.map +1 -1
  32. package/dist/cjs/server/helpers.cjs +4 -3
  33. package/dist/cjs/server/helpers.cjs.map +1 -1
  34. package/dist/cjs/server/index.cjs +5 -1
  35. package/dist/cjs/server/requestLocaleCache.cjs +35 -0
  36. package/dist/cjs/server/requestLocaleCache.cjs.map +1 -0
  37. package/dist/cjs/server/setLocale.cjs +0 -1
  38. package/dist/cjs/server/setLocale.cjs.map +1 -1
  39. package/dist/cjs/server/setRequestLocale.cjs +33 -0
  40. package/dist/cjs/server/setRequestLocale.cjs.map +1 -0
  41. package/dist/esm/client/NextIntlClientProvider.mjs +9 -4
  42. package/dist/esm/client/NextIntlClientProvider.mjs.map +1 -1
  43. package/dist/esm/client/index.mjs +1 -4
  44. package/dist/esm/client/useLocale.mjs.map +1 -1
  45. package/dist/esm/getDictionary.mjs +19 -29
  46. package/dist/esm/getDictionary.mjs.map +1 -1
  47. package/dist/esm/getDictionaryDynamic.mjs +8 -23
  48. package/dist/esm/getDictionaryDynamic.mjs.map +1 -1
  49. package/dist/esm/index.mjs +3 -6
  50. package/dist/esm/middleware.mjs.map +1 -1
  51. package/dist/esm/navigation/Link.mjs.map +1 -1
  52. package/dist/esm/navigation/createNavigation.mjs.map +1 -1
  53. package/dist/esm/navigation/hooks.mjs.map +1 -1
  54. package/dist/esm/navigation/localizeHref.mjs.map +1 -1
  55. package/dist/esm/plugin/index.mjs +8 -14
  56. package/dist/esm/plugin/index.mjs.map +1 -1
  57. package/dist/esm/routing.mjs.map +1 -1
  58. package/dist/esm/server/getLocale.mjs +15 -1
  59. package/dist/esm/server/getLocale.mjs.map +1 -1
  60. package/dist/esm/server/getMessages.mjs.map +1 -1
  61. package/dist/esm/server/getRequestConfig.mjs +25 -0
  62. package/dist/esm/server/getRequestConfig.mjs.map +1 -0
  63. package/dist/esm/server/getTranslations.mjs +8 -4
  64. package/dist/esm/server/getTranslations.mjs.map +1 -1
  65. package/dist/esm/server/helpers.mjs +4 -3
  66. package/dist/esm/server/helpers.mjs.map +1 -1
  67. package/dist/esm/server/index.mjs +3 -1
  68. package/dist/esm/server/requestLocaleCache.mjs +33 -0
  69. package/dist/esm/server/requestLocaleCache.mjs.map +1 -0
  70. package/dist/esm/server/setLocale.mjs.map +1 -1
  71. package/dist/esm/server/setRequestLocale.mjs +32 -0
  72. package/dist/esm/server/setRequestLocale.mjs.map +1 -0
  73. package/dist/types/client/NextIntlClientProvider.d.ts +0 -1
  74. package/dist/types/client/NextIntlClientProvider.d.ts.map +1 -1
  75. package/dist/types/client/index.d.ts +1 -4
  76. package/dist/types/client/useLocale.d.ts +0 -1
  77. package/dist/types/client/useLocale.d.ts.map +1 -1
  78. package/dist/types/getDictionary.d.ts +25 -13
  79. package/dist/types/getDictionary.d.ts.map +1 -1
  80. package/dist/types/getDictionaryDynamic.d.ts +15 -7
  81. package/dist/types/getDictionaryDynamic.d.ts.map +1 -1
  82. package/dist/types/index.d.ts +3 -6
  83. package/dist/types/middleware.d.ts +0 -1
  84. package/dist/types/middleware.d.ts.map +1 -1
  85. package/dist/types/navigation/Link.d.ts +3 -6
  86. package/dist/types/navigation/Link.d.ts.map +1 -1
  87. package/dist/types/navigation/createNavigation.d.ts +0 -1
  88. package/dist/types/navigation/createNavigation.d.ts.map +1 -1
  89. package/dist/types/navigation/hooks.d.ts +4 -6
  90. package/dist/types/navigation/hooks.d.ts.map +1 -1
  91. package/dist/types/navigation/localizeHref.d.ts.map +1 -1
  92. package/dist/types/plugin/index.d.ts +0 -1
  93. package/dist/types/plugin/index.d.ts.map +1 -1
  94. package/dist/types/routing.d.ts +0 -1
  95. package/dist/types/routing.d.ts.map +1 -1
  96. package/dist/types/server/getLocale.d.ts +9 -1
  97. package/dist/types/server/getLocale.d.ts.map +1 -1
  98. package/dist/types/server/getMessages.d.ts +0 -1
  99. package/dist/types/server/getMessages.d.ts.map +1 -1
  100. package/dist/types/server/getRequestConfig.d.ts +18 -0
  101. package/dist/types/server/getRequestConfig.d.ts.map +1 -0
  102. package/dist/types/server/getTranslations.d.ts +13 -33
  103. package/dist/types/server/getTranslations.d.ts.map +1 -1
  104. package/dist/types/server/helpers.d.ts +2 -2
  105. package/dist/types/server/helpers.d.ts.map +1 -1
  106. package/dist/types/server/index.d.ts +3 -1
  107. package/dist/types/server/requestLocaleCache.d.ts +16 -0
  108. package/dist/types/server/requestLocaleCache.d.ts.map +1 -0
  109. package/dist/types/server/setLocale.d.ts.map +1 -1
  110. package/dist/types/server/setRequestLocale.d.ts +28 -0
  111. package/dist/types/server/setRequestLocale.d.ts.map +1 -0
  112. package/package.json +14 -13
  113. package/dist/cjs/client/helpers.cjs +0 -66
  114. package/dist/cjs/client/helpers.cjs.map +0 -1
  115. package/dist/cjs/client/useTranslations.cjs +0 -39
  116. package/dist/cjs/client/useTranslations.cjs.map +0 -1
  117. package/dist/cjs/createFormatter.cjs +0 -59
  118. package/dist/cjs/createFormatter.cjs.map +0 -1
  119. package/dist/cjs/createTranslator.cjs +0 -111
  120. package/dist/cjs/createTranslator.cjs.map +0 -1
  121. package/dist/cjs/getTranslationsDictionary.cjs +0 -31
  122. package/dist/cjs/getTranslationsDictionary.cjs.map +0 -1
  123. package/dist/cjs/getTranslationsDictionaryDynamic.cjs +0 -27
  124. package/dist/cjs/getTranslationsDictionaryDynamic.cjs.map +0 -1
  125. package/dist/cjs/hasLocale.cjs +0 -25
  126. package/dist/cjs/hasLocale.cjs.map +0 -1
  127. package/dist/cjs/package.cjs +0 -122
  128. package/dist/cjs/package.cjs.map +0 -1
  129. package/dist/cjs/useDictionary.cjs +0 -45
  130. package/dist/cjs/useDictionary.cjs.map +0 -1
  131. package/dist/cjs/useDictionaryDynamic.cjs +0 -37
  132. package/dist/cjs/useDictionaryDynamic.cjs.map +0 -1
  133. package/dist/cjs/useTranslationsDictionary.cjs +0 -37
  134. package/dist/cjs/useTranslationsDictionary.cjs.map +0 -1
  135. package/dist/cjs/useTranslationsDictionaryDynamic.cjs +0 -29
  136. package/dist/cjs/useTranslationsDictionaryDynamic.cjs.map +0 -1
  137. package/dist/esm/_virtual/_rolldown/runtime.mjs +0 -8
  138. package/dist/esm/client/helpers.mjs +0 -59
  139. package/dist/esm/client/helpers.mjs.map +0 -1
  140. package/dist/esm/client/useTranslations.mjs +0 -37
  141. package/dist/esm/client/useTranslations.mjs.map +0 -1
  142. package/dist/esm/createFormatter.mjs +0 -57
  143. package/dist/esm/createFormatter.mjs.map +0 -1
  144. package/dist/esm/createTranslator.mjs +0 -108
  145. package/dist/esm/createTranslator.mjs.map +0 -1
  146. package/dist/esm/getTranslationsDictionary.mjs +0 -29
  147. package/dist/esm/getTranslationsDictionary.mjs.map +0 -1
  148. package/dist/esm/getTranslationsDictionaryDynamic.mjs +0 -25
  149. package/dist/esm/getTranslationsDictionaryDynamic.mjs.map +0 -1
  150. package/dist/esm/hasLocale.mjs +0 -23
  151. package/dist/esm/hasLocale.mjs.map +0 -1
  152. package/dist/esm/package.mjs +0 -119
  153. package/dist/esm/package.mjs.map +0 -1
  154. package/dist/esm/useDictionary.mjs +0 -43
  155. package/dist/esm/useDictionary.mjs.map +0 -1
  156. package/dist/esm/useDictionaryDynamic.mjs +0 -35
  157. package/dist/esm/useDictionaryDynamic.mjs.map +0 -1
  158. package/dist/esm/useTranslationsDictionary.mjs +0 -35
  159. package/dist/esm/useTranslationsDictionary.mjs.map +0 -1
  160. package/dist/esm/useTranslationsDictionaryDynamic.mjs +0 -27
  161. package/dist/esm/useTranslationsDictionaryDynamic.mjs.map +0 -1
  162. package/dist/types/client/helpers.d.ts +0 -45
  163. package/dist/types/client/helpers.d.ts.map +0 -1
  164. package/dist/types/client/useTranslations.d.ts +0 -74
  165. package/dist/types/client/useTranslations.d.ts.map +0 -1
  166. package/dist/types/createFormatter.d.ts +0 -15
  167. package/dist/types/createFormatter.d.ts.map +0 -1
  168. package/dist/types/createTranslator.d.ts +0 -40
  169. package/dist/types/createTranslator.d.ts.map +0 -1
  170. package/dist/types/getTranslationsDictionary.d.ts +0 -15
  171. package/dist/types/getTranslationsDictionary.d.ts.map +0 -1
  172. package/dist/types/getTranslationsDictionaryDynamic.d.ts +0 -12
  173. package/dist/types/getTranslationsDictionaryDynamic.d.ts.map +0 -1
  174. package/dist/types/hasLocale.d.ts +0 -20
  175. package/dist/types/hasLocale.d.ts.map +0 -1
  176. package/dist/types/useDictionary.d.ts +0 -22
  177. package/dist/types/useDictionary.d.ts.map +0 -1
  178. package/dist/types/useDictionaryDynamic.d.ts +0 -15
  179. package/dist/types/useDictionaryDynamic.d.ts.map +0 -1
  180. package/dist/types/useTranslationsDictionary.d.ts +0 -19
  181. package/dist/types/useTranslationsDictionary.d.ts.map +0 -1
  182. package/dist/types/useTranslationsDictionaryDynamic.d.ts +0 -12
  183. package/dist/types/useTranslationsDictionaryDynamic.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["sep","ANSIColors"],"sources":["../../../src/plugin/index.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { runOnce } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\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\nconst NEXT_INTL_SWC_CALLERS = [\n {\n callerName: 'useTranslations',\n importSources: ['next-intl', '@intlayer/next-intl'],\n namespaceArgIndex: 0,\n staticReplacement: 'useDictionary',\n dynamicReplacement: 'useDictionaryDynamic',\n },\n {\n callerName: 'getTranslations',\n importSources: ['next-intl/server', '@intlayer/next-intl/server'],\n namespaceArgIndex: 0,\n staticReplacement: 'getDictionary',\n dynamicReplacement: 'getDictionaryDynamic',\n },\n];\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":["sep","NEXT_INTL_CALLERS","ANSIColors"],"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,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
2
  let _intlayer_config_built = require("@intlayer/config/built");
4
3
 
5
4
  //#region src/routing.ts
@@ -1 +1 @@
1
- {"version":3,"file":"routing.cjs","names":["internationalization","routing"],"sources":["../../src/routing.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type Routing = {\n locales: LocalesValues[];\n defaultLocale: LocalesValues;\n localePrefix?: 'always' | 'as-needed' | 'never';\n pathnames?: Record<string, string | Record<string, string>>;\n};\n\n/**\n * Drop-in replacement for next-intl's `defineRouting()`.\n *\n * Merges the provided config with Intlayer's own routing / internationalization\n * configuration so you don't have to repeat locale lists. All fields are\n * optional — omitted values are read from the Intlayer config at runtime.\n *\n * @example\n * ```ts\n * export default defineRouting({\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport const defineRouting: (config?: Partial<Routing>) => Routing = (\n config?: Partial<Routing>\n): Routing => ({\n locales:\n config?.locales ??\n ((internationalization?.locales ?? []) as LocalesValues[]),\n defaultLocale:\n config?.defaultLocale ??\n (internationalization?.defaultLocale as LocalesValues),\n localePrefix:\n config?.localePrefix ?? (routing?.prefixDefault ? 'always' : 'as-needed'),\n ...config,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,iBACX,YACa;CACb,SACE,QAAQ,WACNA,6CAAsB,WAAW,EAAE;CACvC,eACE,QAAQ,iBACPA,6CAAsB;CACzB,cACE,QAAQ,iBAAiBC,gCAAS,gBAAgB,WAAW;CAC/D,GAAG;CACJ"}
1
+ {"version":3,"file":"routing.cjs","names":["internationalization","routing"],"sources":["../../src/routing.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport type Routing = {\n locales: LocalesValues[];\n defaultLocale: LocalesValues;\n localePrefix?: 'always' | 'as-needed' | 'never';\n pathnames?: Record<string, string | Record<string, string>>;\n};\n\n/**\n * Drop-in replacement for next-intl's `defineRouting()`.\n *\n * Merges the provided config with Intlayer's own routing / internationalization\n * configuration so you don't have to repeat locale lists. All fields are\n * optional — omitted values are read from the Intlayer config at runtime.\n *\n * @example\n * ```ts\n * export default defineRouting({\n * locales: ['en', 'fr'],\n * defaultLocale: 'en',\n * });\n * ```\n */\nexport const defineRouting: (config?: Partial<Routing>) => Routing = (\n config?: Partial<Routing>\n): Routing => ({\n locales:\n config?.locales ??\n ((internationalization?.locales ?? []) as LocalesValues[]),\n defaultLocale:\n config?.defaultLocale ??\n (internationalization?.defaultLocale as LocalesValues),\n localePrefix:\n config?.localePrefix ?? (routing?.prefixDefault ? 'always' : 'as-needed'),\n ...config,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,MAAa,iBACX,YACa;CACb,SACE,QAAQ,WACNA,6CAAsB,WAAW,CAAC;CACtC,eACE,QAAQ,iBACPA,6CAAsB;CACzB,cACE,QAAQ,iBAAiBC,gCAAS,gBAAgB,WAAW;CAC/D,GAAG;AACL"}
@@ -1,12 +1,25 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ const require_server_requestLocaleCache = require('./requestLocaleCache.cjs');
3
3
  let next_intlayer_server = require("next-intlayer/server");
4
4
 
5
5
  //#region src/server/getLocale.ts
6
6
  /**
7
7
  * Drop-in for next-intl's `getLocale()` server function.
8
+ *
9
+ * Resolution order mirrors next-intl's per-request model:
10
+ *
11
+ * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`
12
+ * route segment) — the source of truth for URL-driven routing. This is what
13
+ * keeps server-rendered content and the locale switcher in sync with the URL
14
+ * instead of a stale cookie.
15
+ * 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),
16
+ * for apps that drive the locale from storage rather than the route.
8
17
  */
9
- const getLocale = async () => await (0, next_intlayer_server.getLocale)();
18
+ const getLocale = async () => {
19
+ const requestLocale = require_server_requestLocaleCache.getCachedRequestLocale();
20
+ if (requestLocale) return requestLocale;
21
+ return await (0, next_intlayer_server.getLocale)();
22
+ };
10
23
 
11
24
  //#endregion
12
25
  exports.getLocale = getLocale;
@@ -1 +1 @@
1
- {"version":3,"file":"getLocale.cjs","names":[],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> =>\n (await getLocaleIntlayer()) as string;\n"],"mappings":";;;;;;;;AAMA,MAAa,YAA+B,YACzC,2CAAyB"}
1
+ {"version":3,"file":"getLocale.cjs","names":["getCachedRequestLocale"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import type { getLocale as _getLocale } from 'next-intl/server';\nimport { getLocale as getLocaleIntlayer } from 'next-intlayer/server';\nimport { getCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `getLocale()` server function.\n *\n * Resolution order mirrors next-intl's per-request model:\n *\n * 1. The locale forwarded through `setRequestLocale(locale)` (the `[locale]`\n * route segment) — the source of truth for URL-driven routing. This is what\n * keeps server-rendered content and the locale switcher in sync with the URL\n * instead of a stale cookie.\n * 2. Otherwise Intlayer's own resolution (cookie / header / Accept-Language),\n * for apps that drive the locale from storage rather than the route.\n */\nexport const getLocale: typeof _getLocale = async (): Promise<string> => {\n const requestLocale = getCachedRequestLocale();\n if (requestLocale) return requestLocale as string;\n\n return (await getLocaleIntlayer()) as string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,YAA+B,YAA6B;CACvE,MAAM,gBAAgBA,yDAAuB;CAC7C,IAAI,eAAe,OAAO;CAE1B,OAAQ,0CAAwB;AAClC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
2
  let _intlayer_config_built = require("@intlayer/config/built");
4
3
  let _intlayer_config_colors = require("@intlayer/config/colors");
5
4
  let _intlayer_config_logger = require("@intlayer/config/logger");
@@ -1 +1 @@
1
- {"version":3,"file":"getMessages.cjs","names":["CYAN"],"sources":["../../../src/server/getMessages.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getMessages as _getMessages } from 'next-intl/server';\n\n/**\n * Drop-in replacement for next-intl's `getMessages()` server function.\n *\n * Returns all compiled dictionary content for the current locale as a flat\n * record keyed by dictionary name. Useful when you need to pass messages\n * to a `NextIntlClientProvider`.\n *\n * @example\n * ```ts\n * const messages = await getMessages();\n * ```\n *\n * @deprecated getMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood\n */\nexport const getMessages: typeof _getMessages = async () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAmC,YAAY;AAC1D,KAAI,QAAQ,IAAI,aAAa,cAE3B,2CAD+B,EAAE,iCAAK,CAC7B,CACP,yCAAY,eAAeA,6BAAK,CAAC,iHAClC;AAGH,QAAO,EAAE"}
1
+ {"version":3,"file":"getMessages.cjs","names":["CYAN"],"sources":["../../../src/server/getMessages.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getMessages as _getMessages } from 'next-intl/server';\n\n/**\n * Drop-in replacement for next-intl's `getMessages()` server function.\n *\n * Returns all compiled dictionary content for the current locale as a flat\n * record keyed by dictionary name. Useful when you need to pass messages\n * to a `NextIntlClientProvider`.\n *\n * @example\n * ```ts\n * const messages = await getMessages();\n * ```\n *\n * @deprecated getMessages has no use case with intlayer.\n * Messages are loaded automatically under the hood\n */\nexport const getMessages: typeof _getMessages = async () => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getMessages', CYAN)} has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAmC,YAAY;CAC1D,IAAI,QAAQ,IAAI,aAAa,eAE3B,0CAD+B,EAAE,gCAAI,CAC7B,CAAC,CACP,yCAAY,eAAeA,4BAAI,EAAE,gHACnC;CAGF,OAAO,CAAC;AACV"}
@@ -0,0 +1,27 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ let _intlayer_config_built = require("@intlayer/config/built");
3
+ let _intlayer_config_colors = require("@intlayer/config/colors");
4
+ let _intlayer_config_logger = require("@intlayer/config/logger");
5
+
6
+ //#region src/server/getRequestConfig.ts
7
+ /**
8
+ * Drop-in for next-intl's `getRequestConfig`.
9
+ *
10
+ * In next-intl this registers the per-request config (locale + messages) read
11
+ * by its own plugin. With intlayer the locale is resolved from routing /
12
+ * storage and messages come from compiled dictionaries, so the returned config
13
+ * is never consumed — this is an identity passthrough kept so existing
14
+ * `i18n/request.ts` files keep resolving and type-checking.
15
+ *
16
+ * @deprecated getRequestConfig has no use case with intlayer. The locale and
17
+ * messages are resolved automatically; the file can be removed.
18
+ */
19
+ const getRequestConfig = (createRequestConfig) => {
20
+ if (process.env.NODE_ENV === "development") (0, _intlayer_config_logger.getAppLogger)({ log: _intlayer_config_built.log })(`${(0, _intlayer_config_logger.colorize)("getRequestConfig", _intlayer_config_colors.CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`);
21
+ return createRequestConfig;
22
+ };
23
+
24
+ //#endregion
25
+ exports.default = getRequestConfig;
26
+ exports.getRequestConfig = getRequestConfig;
27
+ //# sourceMappingURL=getRequestConfig.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRequestConfig.cjs","names":["CYAN"],"sources":["../../../src/server/getRequestConfig.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport type { getRequestConfig as _getRequestConfig } from 'next-intl/server';\n\n/**\n * Drop-in for next-intl's `getRequestConfig`.\n *\n * In next-intl this registers the per-request config (locale + messages) read\n * by its own plugin. With intlayer the locale is resolved from routing /\n * storage and messages come from compiled dictionaries, so the returned config\n * is never consumed — this is an identity passthrough kept so existing\n * `i18n/request.ts` files keep resolving and type-checking.\n *\n * @deprecated getRequestConfig has no use case with intlayer. The locale and\n * messages are resolved automatically; the file can be removed.\n */\nexport const getRequestConfig: typeof _getRequestConfig = (\n createRequestConfig\n) => {\n if (process.env.NODE_ENV === 'development') {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('getRequestConfig', CYAN)} has no use case with intlayer. The locale and messages are resolved automatically; the i18n/request.ts file can be removed`\n );\n }\n\n return createRequestConfig;\n};\n\nexport default getRequestConfig;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,oBACX,wBACG;CACH,IAAI,QAAQ,IAAI,aAAa,eAE3B,0CAD+B,EAAE,gCAAI,CAC7B,CAAC,CACP,yCAAY,oBAAoBA,4BAAI,EAAE,4HACxC;CAGF,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_server_getLocale = require('./getLocale.cjs');
3
- const require_createTranslator = require('../createTranslator.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
4
 
5
5
  //#region src/server/getTranslations.ts
6
6
  /**
@@ -11,8 +11,9 @@ const require_createTranslator = require('../createTranslator.cjs');
11
11
  * arguments (`{value, number}`). Rich text is available through `t.rich()`
12
12
  * and `t.markup()`.
13
13
  *
14
- * Also accepts an options object `{ namespace, locale }` to match next-intl's
15
- * full server API surface.
14
+ * Resolves the active locale from the current request (or the `locale` option)
15
+ * and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime
16
+ * that backs the client `useTranslations`.
16
17
  *
17
18
  * @example
18
19
  * ```ts
@@ -37,7 +38,10 @@ const getTranslations = (async (namespaceOrOptions) => {
37
38
  namespace = namespaceOrOptions.namespace;
38
39
  localeOverride = namespaceOrOptions.locale;
39
40
  } else namespace = namespaceOrOptions;
40
- return require_createTranslator.createTranslator(localeOverride ?? await require_server_getLocale.getLocale(), namespace);
41
+ return (0, _intlayer_use_intl.createTranslator)({
42
+ locale: localeOverride ?? await require_server_getLocale.getLocale(),
43
+ namespace
44
+ });
41
45
  });
42
46
 
43
47
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"getTranslations.cjs","names":["createTranslator","getLocale"],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { ReactNode } from 'react';\nimport {\n createTranslator,\n type MarkupChunkRenderer,\n type RichChunkRenderer,\n} from '../createTranslator';\nimport { getLocale } from './getLocale';\n\n/**\n * Options accepted by the options-object overload of {@link getTranslations}.\n */\ntype GetTranslationsOptions<N extends DictionaryKeys> = {\n /** The dictionary namespace to scope translations to. */\n namespace?: N;\n /** Override the locale instead of reading it from the current request. */\n locale?: LocalesValues;\n};\n\n/**\n * The translation function returned by {@link getTranslations}.\n *\n * Beyond the plain call signature, the function exposes:\n * - `has(key)` — returns `true` when the key exists in the namespace.\n * - `raw(key)` — returns the unprocessed message 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 message 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 getTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. An options object `{ namespace?, locale? }` → typed when namespace is\n * a known `DictionaryKeys` value.\n * 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * `string` paths, matching next-intl's scoped-namespace behaviour.\n * 4. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n */\ntype GetTranslations = {\n <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;\n <N extends DictionaryKeys>(\n options: GetTranslationsOptions<N>\n ): Promise<TranslateFunction<N>>;\n (namespace: `${string}.${string}`): Promise<LooseTranslateFunction>;\n (): Promise<LooseTranslateFunction>;\n};\n\n/**\n * Drop-in for next-intl's server `getTranslations()`.\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 * Also accepts an options object `{ namespace, locale }` to match next-intl's\n * full server API surface.\n *\n * @example\n * ```ts\n * // Bare namespace — fully typed dot-paths\n * const t = await getTranslations('about');\n * return <h1>{t('counter.label')}</h1>;\n *\n * // ICU plural\n * t('items', { count: 3 });\n *\n * // Options object with locale override\n * const t = await getTranslations({ namespace: 'about', locale: 'fr' });\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const getTranslations: GetTranslations = (async (\n namespaceOrOptions?: string | GetTranslationsOptions<DictionaryKeys>\n) => {\n let namespace: string | undefined;\n let localeOverride: LocalesValues | undefined;\n\n if (typeof namespaceOrOptions === 'object' && namespaceOrOptions !== null) {\n namespace = namespaceOrOptions.namespace;\n localeOverride = namespaceOrOptions.locale;\n } else {\n namespace = namespaceOrOptions as string | undefined;\n }\n\n const locale = localeOverride ?? (await getLocale());\n\n return createTranslator(locale as LocalesValues, namespace);\n}) as GetTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,MAAa,mBAAoC,OAC/C,uBACG;CACH,IAAI;CACJ,IAAI;AAEJ,KAAI,OAAO,uBAAuB,YAAY,uBAAuB,MAAM;AACzE,cAAY,mBAAmB;AAC/B,mBAAiB,mBAAmB;OAEpC,aAAY;AAKd,QAAOA,0CAFQ,kBAAmB,MAAMC,oCAAW,EAEF,UAAU"}
1
+ {"version":3,"file":"getTranslations.cjs","names":["getLocale"],"sources":["../../../src/server/getTranslations.ts"],"sourcesContent":["import type {\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n createTranslator,\n type LooseTranslateFunction,\n type TranslateFunction,\n type TranslateFunctionForNamespace,\n} from '@intlayer/use-intl';\nimport { getLocale } from './getLocale';\n\n/**\n * Options accepted by the options-object overload of {@link getTranslations}.\n */\ntype GetTranslationsOptions<N extends DictionaryKeys> = {\n /** The dictionary namespace to scope translations to. */\n namespace?: N;\n /** Override the locale instead of reading it from the current request. */\n locale?: LocalesValues;\n};\n\n/**\n * Overload set for {@link getTranslations}:\n *\n * 1. A bare dictionary key → fully-typed `t()` (autocompleted dot-paths).\n * 2. An options object `{ namespace?, locale? }` → typed when namespace is\n * a known `DictionaryKeys` value.\n * 3. A nested namespace `'dictionary.sub.scope'` → `t()` accepts relative\n * dot-paths under the scope, typed against the dictionary, matching\n * next-intl's scoped-namespace behaviour.\n * 4. No namespace → root scope; the first segment of each key designates\n * the dictionary (`t('about.title')`).\n *\n * The translate function shape (`t`, `t.rich`, `t.markup`, `t.raw`, `t.has`)\n * is shared with `@intlayer/use-intl`.\n */\ntype GetTranslations = {\n <N extends DictionaryKeys>(namespace: N): Promise<TranslateFunction<N>>;\n <N extends DictionaryKeys>(\n options: GetTranslationsOptions<N>\n ): Promise<TranslateFunction<N>>;\n <N extends `${string}.${string}`>(\n namespace: N\n ): Promise<TranslateFunctionForNamespace<N>>;\n (): Promise<LooseTranslateFunction>;\n};\n\n/**\n * Drop-in for next-intl's server `getTranslations()`.\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 * Resolves the active locale from the current request (or the `locale` option)\n * and delegates to `@intlayer/use-intl`'s `createTranslator`, the same runtime\n * that backs the client `useTranslations`.\n *\n * @example\n * ```ts\n * // Bare namespace — fully typed dot-paths\n * const t = await getTranslations('about');\n * return <h1>{t('counter.label')}</h1>;\n *\n * // ICU plural\n * t('items', { count: 3 });\n *\n * // Options object with locale override\n * const t = await getTranslations({ namespace: 'about', locale: 'fr' });\n *\n * // Rich text\n * t.rich('terms', { link: (chunks) => <a href=\"/terms\">{chunks}</a> });\n * ```\n */\nexport const getTranslations: GetTranslations = (async (\n namespaceOrOptions?: string | GetTranslationsOptions<DictionaryKeys>\n) => {\n let namespace: string | undefined;\n let localeOverride: LocalesValues | undefined;\n\n if (typeof namespaceOrOptions === 'object' && namespaceOrOptions !== null) {\n namespace = namespaceOrOptions.namespace;\n localeOverride = namespaceOrOptions.locale;\n } else {\n namespace = namespaceOrOptions as string | undefined;\n }\n\n const locale = localeOverride ?? (await getLocale());\n\n return createTranslator({ locale: locale as LocalesValues, namespace });\n}) as GetTranslations;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAa,mBAAoC,OAC/C,uBACG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,OAAO,uBAAuB,YAAY,uBAAuB,MAAM;EACzE,YAAY,mBAAmB;EAC/B,iBAAiB,mBAAmB;CACtC,OACE,YAAY;CAKd,gDAAwB;EAAE,QAFX,kBAAmB,MAAMA,mCAAU;EAES;CAAU,CAAC;AACxE"}
@@ -1,14 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createFormatter = require('../createFormatter.cjs');
3
2
  const require_server_getLocale = require('./getLocale.cjs');
3
+ let _intlayer_use_intl = require("@intlayer/use-intl");
4
4
 
5
5
  //#region src/server/helpers.ts
6
6
  /**
7
7
  * Drop-in for next-intl's server `getFormatter()`.
8
- * Returns locale-aware formatters backed by the native `Intl.*` APIs.
8
+ * Returns locale-aware formatters backed by the native `Intl.*` APIs,
9
+ * built by `@intlayer/use-intl`'s `createFormatter`.
9
10
  */
10
11
  const getFormatter = (async (options) => {
11
- return require_createFormatter.createFormatter(options?.locale ?? await require_server_getLocale.getLocale());
12
+ return (0, _intlayer_use_intl.createFormatter)({ locale: options?.locale ?? await require_server_getLocale.getLocale() });
12
13
  });
13
14
  /**
14
15
  * Drop-in for next-intl's server `getNow()`.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","names":["createFormatter","getLocale"],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport { createFormatter } from '../createFormatter';\nimport { getLocale } from './getLocale';\n\n/**\n * Drop-in for next-intl's server `getFormatter()`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs.\n */\nexport const getFormatter: typeof _getFormatter = (async (options?: {\n locale?: string;\n}) => {\n const locale = options?.locale ?? (await getLocale());\n return createFormatter(locale as string);\n}) as typeof _getFormatter;\n\n/**\n * Drop-in for next-intl's server `getNow()`.\n * Returns the current `Date`.\n */\nexport const getNow: typeof _getNow = (async () =>\n new Date()) as typeof _getNow;\n\n/**\n * Drop-in for next-intl's server `getTimeZone()`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const getTimeZone: typeof _getTimeZone = (async () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone) as typeof _getTimeZone;\n"],"mappings":";;;;;;;;;AAYA,MAAa,gBAAsC,OAAO,YAEpD;AAEJ,QAAOA,wCADQ,SAAS,UAAW,MAAMC,oCAAW,CACZ;;;;;;AAO1C,MAAa,UAA0B,4BACrC,IAAI,MAAM;;;;;AAMZ,MAAa,eAAoC,YAC/C,KAAK,gBAAgB,CAAC,iBAAiB,CAAC"}
1
+ {"version":3,"file":"helpers.cjs","names":["getLocale"],"sources":["../../../src/server/helpers.ts"],"sourcesContent":["import { createFormatter } from '@intlayer/use-intl';\nimport type {\n getFormatter as _getFormatter,\n getNow as _getNow,\n getTimeZone as _getTimeZone,\n} from 'next-intl/server';\nimport { getLocale } from './getLocale';\n\n/**\n * Drop-in for next-intl's server `getFormatter()`.\n * Returns locale-aware formatters backed by the native `Intl.*` APIs,\n * built by `@intlayer/use-intl`'s `createFormatter`.\n */\nexport const getFormatter: typeof _getFormatter = (async (options?: {\n locale?: string;\n}) => {\n const locale = options?.locale ?? (await getLocale());\n return createFormatter({ locale: locale as string });\n}) as typeof _getFormatter;\n\n/**\n * Drop-in for next-intl's server `getNow()`.\n * Returns the current `Date`.\n */\nexport const getNow: typeof _getNow = (async () =>\n new Date()) as typeof _getNow;\n\n/**\n * Drop-in for next-intl's server `getTimeZone()`.\n * Returns the system time zone resolved from `Intl.DateTimeFormat`.\n */\nexport const getTimeZone: typeof _getTimeZone = (async () =>\n Intl.DateTimeFormat().resolvedOptions().timeZone) as typeof _getTimeZone;\n"],"mappings":";;;;;;;;;;AAaA,MAAa,gBAAsC,OAAO,YAEpD;CAEJ,+CAAuB,EAAE,QADV,SAAS,UAAW,MAAMA,mCAAU,EACD,CAAC;AACrD;;;;;AAMA,MAAa,UAA0B,4BACrC,IAAI,KAAK;;;;;AAMX,MAAa,eAAoC,YAC/C,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC"}
@@ -3,6 +3,8 @@ const require_server_getLocale = require('./getLocale.cjs');
3
3
  const require_getDictionary = require('../getDictionary.cjs');
4
4
  const require_getDictionaryDynamic = require('../getDictionaryDynamic.cjs');
5
5
  const require_server_helpers = require('./helpers.cjs');
6
+ const require_server_getRequestConfig = require('./getRequestConfig.cjs');
7
+ const require_server_setRequestLocale = require('./setRequestLocale.cjs');
6
8
  const require_server_setLocale = require('./setLocale.cjs');
7
9
  const require_server_getTranslations = require('./getTranslations.cjs');
8
10
  const require_server_getMessages = require('./getMessages.cjs');
@@ -13,6 +15,8 @@ exports.getFormatter = require_server_helpers.getFormatter;
13
15
  exports.getLocale = require_server_getLocale.getLocale;
14
16
  exports.getMessages = require_server_getMessages.getMessages;
15
17
  exports.getNow = require_server_helpers.getNow;
18
+ exports.getRequestConfig = require_server_getRequestConfig.default;
16
19
  exports.getTimeZone = require_server_helpers.getTimeZone;
17
20
  exports.getTranslations = require_server_getTranslations.getTranslations;
18
- exports.setLocale = require_server_setLocale.setLocale;
21
+ exports.setLocale = require_server_setLocale.setLocale;
22
+ exports.setRequestLocale = require_server_setRequestLocale.setRequestLocale;
@@ -0,0 +1,35 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let react = require("react");
3
+
4
+ //#region src/server/requestLocaleCache.ts
5
+ /**
6
+ * Request-scoped holder for the locale provided through {@link setRequestLocale}.
7
+ *
8
+ * next-intl resolves the active locale per request from the `[locale]` route
9
+ * segment, which the app forwards via `setRequestLocale(locale)`. React's
10
+ * `cache()` gives a per-request singleton (the same trick next-intl uses in its
11
+ * own `RequestLocaleCache`), so the value set in the layout/page is readable by
12
+ * the other server APIs (`getLocale`, `getTranslations`, …) during the same
13
+ * render.
14
+ *
15
+ * @see https://github.com/vercel/next.js/discussions/58862
16
+ */
17
+ const getRequestLocaleHolder = (0, react.cache)(() => ({ locale: void 0 }));
18
+ /**
19
+ * Read the locale stored for the current request, or `undefined` when
20
+ * `setRequestLocale` has not been called.
21
+ */
22
+ const getCachedRequestLocale = () => getRequestLocaleHolder().locale;
23
+ /**
24
+ * Store the locale for the current request. Called by `setRequestLocale`.
25
+ *
26
+ * @param locale - The locale resolved from the `[locale]` route segment.
27
+ */
28
+ const setCachedRequestLocale = (locale) => {
29
+ getRequestLocaleHolder().locale = locale;
30
+ };
31
+
32
+ //#endregion
33
+ exports.getCachedRequestLocale = getCachedRequestLocale;
34
+ exports.setCachedRequestLocale = setCachedRequestLocale;
35
+ //# sourceMappingURL=requestLocaleCache.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestLocaleCache.cjs","names":[],"sources":["../../../src/server/requestLocaleCache.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cache } from 'react';\n\n/**\n * Request-scoped holder for the locale provided through {@link setRequestLocale}.\n *\n * next-intl resolves the active locale per request from the `[locale]` route\n * segment, which the app forwards via `setRequestLocale(locale)`. React's\n * `cache()` gives a per-request singleton (the same trick next-intl uses in its\n * own `RequestLocaleCache`), so the value set in the layout/page is readable by\n * the other server APIs (`getLocale`, `getTranslations`, …) during the same\n * render.\n *\n * @see https://github.com/vercel/next.js/discussions/58862\n */\nconst getRequestLocaleHolder = cache((): { locale?: LocalesValues } => ({\n locale: undefined,\n}));\n\n/**\n * Read the locale stored for the current request, or `undefined` when\n * `setRequestLocale` has not been called.\n */\nexport const getCachedRequestLocale = (): LocalesValues | undefined =>\n getRequestLocaleHolder().locale;\n\n/**\n * Store the locale for the current request. Called by `setRequestLocale`.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n */\nexport const setCachedRequestLocale = (locale: LocalesValues): void => {\n getRequestLocaleHolder().locale = locale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,iDAAkE,EACtE,QAAQ,OACV,EAAE;;;;;AAMF,MAAa,+BACX,uBAAuB,CAAC,CAAC;;;;;;AAO3B,MAAa,0BAA0B,WAAgC;CACrE,uBAAuB,CAAC,CAAC,SAAS;AACpC"}
@@ -1,5 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
2
  let _intlayer_core_utils = require("@intlayer/core/utils");
4
3
  let next_headers_js = require("next/headers.js");
5
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"setLocale.cjs","names":[],"sources":["../../../src/server/setLocale.ts"],"sourcesContent":["import { setLocaleInStorageServer } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cookies } from 'next/headers.js';\n\n/**\n * Drop-in replacement for next-intl's `setLocale()` server action.\n *\n * Writes the locale to whichever cookie(s) the active `routing.storage`\n * configuration specifies. When `createNextIntlPlugin` is used (the default),\n * this is `NEXT_LOCALE`; when the user has configured a custom storage in\n * `intlayer.config.ts`, that name is used instead.\n *\n * Must be called inside a Server Action.\n *\n * @example\n * ```ts\n * 'use server';\n * await setLocale('fr');\n * ```\n */\nexport const setLocale = async (locale: string): Promise<void> => {\n const cookieStore = await cookies();\n\n setLocaleInStorageServer(locale as LocalesValues, {\n setCookieStore: (name, value, attributes) => {\n cookieStore.set(name, value, {\n ...(attributes ?? {}),\n path: attributes?.path ?? '/',\n sameSite: (attributes?.sameSite as 'lax') ?? 'lax',\n httpOnly: attributes?.httpOnly ?? false,\n secure: attributes?.secure ?? process.env.NODE_ENV === 'production',\n });\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY,OAAO,WAAkC;CAChE,MAAM,cAAc,oCAAe;AAEnC,oDAAyB,QAAyB,EAChD,iBAAiB,MAAM,OAAO,eAAe;AAC3C,cAAY,IAAI,MAAM,OAAO;GAC3B,GAAI,cAAc,EAAE;GACpB,MAAM,YAAY,QAAQ;GAC1B,UAAW,YAAY,YAAsB;GAC7C,UAAU,YAAY,YAAY;GAClC,QAAQ,YAAY,UAAU,QAAQ,IAAI,aAAa;GACxD,CAAC;IAEL,CAAC"}
1
+ {"version":3,"file":"setLocale.cjs","names":[],"sources":["../../../src/server/setLocale.ts"],"sourcesContent":["import { setLocaleInStorageServer } from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { cookies } from 'next/headers.js';\n\n/**\n * Drop-in replacement for next-intl's `setLocale()` server action.\n *\n * Writes the locale to whichever cookie(s) the active `routing.storage`\n * configuration specifies. When `createNextIntlPlugin` is used (the default),\n * this is `NEXT_LOCALE`; when the user has configured a custom storage in\n * `intlayer.config.ts`, that name is used instead.\n *\n * Must be called inside a Server Action.\n *\n * @example\n * ```ts\n * 'use server';\n * await setLocale('fr');\n * ```\n */\nexport const setLocale = async (locale: string): Promise<void> => {\n const cookieStore = await cookies();\n\n setLocaleInStorageServer(locale as LocalesValues, {\n setCookieStore: (name, value, attributes) => {\n cookieStore.set(name, value, {\n ...(attributes ?? {}),\n path: attributes?.path ?? '/',\n sameSite: (attributes?.sameSite as 'lax') ?? 'lax',\n httpOnly: attributes?.httpOnly ?? false,\n secure: attributes?.secure ?? process.env.NODE_ENV === 'production',\n });\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY,OAAO,WAAkC;CAChE,MAAM,cAAc,mCAAc;CAElC,mDAAyB,QAAyB,EAChD,iBAAiB,MAAM,OAAO,eAAe;EAC3C,YAAY,IAAI,MAAM,OAAO;GAC3B,GAAI,cAAc,CAAC;GACnB,MAAM,YAAY,QAAQ;GAC1B,UAAW,YAAY,YAAsB;GAC7C,UAAU,YAAY,YAAY;GAClC,QAAQ,YAAY,UAAU,QAAQ,IAAI,aAAa;EACzD,CAAC;CACH,EACF,CAAC;AACH"}
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_server_requestLocaleCache = require('./requestLocaleCache.cjs');
3
+
4
+ //#region src/server/setRequestLocale.ts
5
+ /**
6
+ * Drop-in for next-intl's `setRequestLocale`.
7
+ *
8
+ * In next-intl this stores the locale (typically the `[locale]` route segment)
9
+ * in a request-scoped cache so the rest of the request can render in that
10
+ * locale and opt into static rendering. The compat keeps the same contract:
11
+ * the locale is stored per-request and read back by `getLocale()` (and, through
12
+ * it, `getTranslations` / `getDictionary` / metadata). This is what makes the
13
+ * per-request locale — and therefore the locale switcher — work without relying
14
+ * on a cookie.
15
+ *
16
+ * @param locale - The locale resolved from the `[locale]` route segment.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * export default async function LocaleLayout({ params }) {
21
+ * const { locale } = await params;
22
+ * setRequestLocale(locale);
23
+ * // …
24
+ * }
25
+ * ```
26
+ */
27
+ const setRequestLocale = (locale) => {
28
+ require_server_requestLocaleCache.setCachedRequestLocale(locale);
29
+ };
30
+
31
+ //#endregion
32
+ exports.setRequestLocale = setRequestLocale;
33
+ //# sourceMappingURL=setRequestLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setRequestLocale.cjs","names":[],"sources":["../../../src/server/setRequestLocale.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { setRequestLocale as _setRequestLocale } from 'next-intl/server';\nimport { setCachedRequestLocale } from './requestLocaleCache';\n\n/**\n * Drop-in for next-intl's `setRequestLocale`.\n *\n * In next-intl this stores the locale (typically the `[locale]` route segment)\n * in a request-scoped cache so the rest of the request can render in that\n * locale and opt into static rendering. The compat keeps the same contract:\n * the locale is stored per-request and read back by `getLocale()` (and, through\n * it, `getTranslations` / `getDictionary` / metadata). This is what makes the\n * per-request locale — and therefore the locale switcher — work without relying\n * on a cookie.\n *\n * @param locale - The locale resolved from the `[locale]` route segment.\n *\n * @example\n * ```ts\n * export default async function LocaleLayout({ params }) {\n * const { locale } = await params;\n * setRequestLocale(locale);\n * // …\n * }\n * ```\n */\nexport const setRequestLocale: typeof _setRequestLocale = (locale): void => {\n setCachedRequestLocale(locale as LocalesValues);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,oBAA8C,WAAiB;CAC1E,yDAAuB,MAAuB;AAChD"}
@@ -1,10 +1,12 @@
1
1
  'use client';
2
2
 
3
- import { log } from "@intlayer/config/built";
3
+ import { log, routing } from "@intlayer/config/built";
4
4
  import { IntlayerClientProvider } from "next-intlayer";
5
- import { jsx } from "react/jsx-runtime";
6
5
  import { CYAN } from "@intlayer/config/colors";
7
6
  import { colorize, getAppLogger } from "@intlayer/config/logger";
7
+ import { getLocaleFromPath } from "@intlayer/core/localization";
8
+ import { usePathname } from "next/navigation";
9
+ import { jsx } from "react/jsx-runtime";
8
10
 
9
11
  //#region src/client/NextIntlClientProvider.tsx
10
12
  /**
@@ -14,11 +16,14 @@ import { colorize, getAppLogger } from "@intlayer/config/logger";
14
16
  */
15
17
  const NextIntlClientProvider = ({ locale, children, messages: _messages, timeZone: _timeZone, now: _now, ...rest }) => {
16
18
  if (typeof _messages !== "undefined") getAppLogger({ log })(`${colorize("NextIntlClientProvider", CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`);
19
+ const pathname = usePathname();
20
+ const mode = routing?.mode ?? "prefix-no-default";
21
+ const resolvedLocale = locale ?? (mode === "prefix-all" || mode === "prefix-no-default" ? getLocaleFromPath(pathname) : void 0);
17
22
  return /* @__PURE__ */ jsx(IntlayerClientProvider, {
18
- locale,
23
+ locale: resolvedLocale,
19
24
  ...rest,
20
25
  children
21
- }, String(locale));
26
+ }, String(resolvedLocale));
22
27
  };
23
28
 
24
29
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"NextIntlClientProvider.mjs","names":[],"sources":["../../../src/client/NextIntlClientProvider.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 { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // `key={locale}` remounts the provider when the locale changes via navigation\n // (next-intl switches locale by routing to a locale-prefixed path). This\n // re-seeds the client locale context from the new `locale` prop so client\n // components re-render in the new language instead of keeping the previous one.\n return (\n <IntlayerClientProvider key={String(locale)} locale={locale} {...rest}>\n {children}\n </IntlayerClientProvider>\n );\n};\n\n/**\n *\n */\nexport type NextIntlClientProviderProps = Omit<\n ComponentProps<typeof _NextIntlClientProvider>,\n 'messages'\n> & {\n /**\n * @deprecated\n * has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason\n */\n messages?: never;\n /**\n * locale\n */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,0BAA0D,EACrE,QACA,UACA,UAAU,WACV,UAAU,WACV,KAAK,MACL,GAAG,WACC;AACJ,KAEE,OAAO,cAAc,YAGrB,CADkB,aAAa,EAAE,KAAK,CAC7B,CACP,GAAG,SAAS,0BAA0B,KAAK,CAAC,+HAC7C;AAOH,QACE,oBAAC,wBAAD;EAAqD;EAAQ,GAAI;EAC9D;EACsB,EAFI,OAAO,OAAO,CAElB"}
1
+ {"version":3,"file":"NextIntlClientProvider.mjs","names":[],"sources":["../../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport { log, routing } from '@intlayer/config/built';\nimport { CYAN } from '@intlayer/config/colors';\nimport { colorize, getAppLogger } from '@intlayer/config/logger';\nimport { getLocaleFromPath } from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { usePathname } from 'next/navigation';\nimport type { NextIntlClientProvider as _NextIntlClientProvider } from 'next-intl';\nimport { IntlayerClientProvider } from 'next-intlayer';\nimport type { ComponentProps } from 'react';\n\n/**\n * Drop-in for next-intl's `NextIntlClientProvider`.\n * `messages`, `timeZone`, and `now` are accepted for API compatibility\n * but have no effect — Intlayer uses its own compiled dictionaries.\n */\nexport const NextIntlClientProvider: typeof _NextIntlClientProvider = ({\n locale,\n children,\n messages: _messages,\n timeZone: _timeZone,\n now: _now,\n ...rest\n}) => {\n if (\n process.env.NODE_ENV === 'development' &&\n typeof _messages !== 'undefined'\n ) {\n const appLogger = getAppLogger({ log });\n appLogger(\n `${colorize('NextIntlClientProvider', CYAN)} do not pass the messages prop with intlayer. Messages are loaded automatically under the hood for bundle optimization reason`\n );\n }\n\n // next-intl drives the locale from the request: apps render\n // `<NextIntlClientProvider>` without a `locale` prop and the server resolves it\n // from the `[locale]` route segment. As a client component we cannot read the\n // server request here, so when no explicit `locale` is given we derive it from\n // the URL (the same `[locale]` segment) using Intlayer's routing config. This\n // keeps `useLocale`, `Link` and the locale switcher in sync with the URL\n // instead of falling back to the stored cookie / default locale.\n //\n // Only prefix-based routing carries the locale in the path. For `no-prefix` /\n // `search-params` the path has no locale segment, so we leave `locale`\n // undefined and let the provider resolve it from storage (cookie) — deriving\n // from the path there would wrongly clobber the cookie with the default locale.\n const pathname = usePathname();\n const mode = routing?.mode ?? 'prefix-no-default';\n const isPrefixMode = mode === 'prefix-all' || mode === 'prefix-no-default';\n const resolvedLocale =\n locale ?? (isPrefixMode ? getLocaleFromPath(pathname) : undefined);\n\n // `key={resolvedLocale}` remounts the provider when the locale changes via\n // navigation (next-intl switches locale by routing to a locale-prefixed path).\n // This re-seeds the client locale context so client components re-render in\n // the new language instead of keeping the previous one.\n return (\n <IntlayerClientProvider\n key={String(resolvedLocale)}\n locale={resolvedLocale}\n {...rest}\n >\n {children}\n </IntlayerClientProvider>\n );\n};\n\n/**\n *\n */\nexport type NextIntlClientProviderProps = Omit<\n ComponentProps<typeof _NextIntlClientProvider>,\n 'messages'\n> & {\n /**\n * @deprecated\n * has no use case with intlayer. Messages are loaded automatically under the hood for bundle optimization reason\n */\n messages?: never;\n /**\n * locale\n */\n locale: LocalesValues;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,0BAA0D,EACrE,QACA,UACA,UAAU,WACV,UAAU,WACV,KAAK,MACL,GAAG,WACC;CACJ,IAEE,OAAO,cAAc,aAGrB,AADkB,aAAa,EAAE,IAAI,CAC7B,CAAC,CACP,GAAG,SAAS,0BAA0B,IAAI,EAAE,8HAC9C;CAeF,MAAM,WAAW,YAAY;CAC7B,MAAM,OAAO,SAAS,QAAQ;CAE9B,MAAM,iBACJ,WAFmB,SAAS,gBAAgB,SAAS,sBAE3B,kBAAkB,QAAQ,IAAI;CAM1D,OACE,oBAAC,wBAAD;EAEE,QAAQ;EACR,GAAI;EAEH;CACqB,GALjB,OAAO,cAAc,CAKJ;AAE5B"}
@@ -1,8 +1,5 @@
1
- import { useDictionaryDynamic } from "../useDictionaryDynamic.mjs";
2
- import { useDictionary } from "../useDictionary.mjs";
3
- import { IntlProvider, useExtracted, useFormatter, useMessages, useNow, useTimeZone } from "./helpers.mjs";
4
1
  import { NextIntlClientProvider } from "./NextIntlClientProvider.mjs";
5
2
  import { useLocale } from "./useLocale.mjs";
6
- import { useTranslations } from "./useTranslations.mjs";
3
+ import { IntlProvider, _useExtracted as useExtracted, useDictionary, useDictionaryDynamic, useFormatter, useMessages, useNow, useTimeZone, useTranslations } from "@intlayer/use-intl";
7
4
 
8
5
  export { IntlProvider, NextIntlClientProvider, useDictionary, useDictionaryDynamic, useExtracted, useFormatter, useLocale, useMessages, useNow, useTimeZone, useTranslations };
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.mjs","names":["useLocaleIntlayer"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport type { useLocale as _useLocale } from 'next-intl';\nimport { useLocale as useLocaleIntlayer } from 'next-intlayer';\n\n/**\n * Drop-in for next-intl's `useLocale`.\n */\nexport const useLocale: typeof _useLocale = (): string => {\n const { locale } = useLocaleIntlayer();\n return locale as string;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,kBAA6C;CACxD,MAAM,EAAE,WAAWA,aAAmB;AACtC,QAAO"}
1
+ {"version":3,"file":"useLocale.mjs","names":["useLocaleIntlayer"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport type { useLocale as _useLocale } from 'next-intl';\nimport { useLocale as useLocaleIntlayer } from 'next-intlayer';\n\n/**\n * Drop-in for next-intl's `useLocale`.\n */\nexport const useLocale: typeof _useLocale = (): string => {\n const { locale } = useLocaleIntlayer();\n return locale as string;\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,kBAA6C;CACxD,MAAM,EAAE,WAAWA,YAAkB;CACrC,OAAO;AACT"}
@@ -1,42 +1,32 @@
1
1
  import { getLocale } from "./server/getLocale.mjs";
2
+ import { createDictionaryTranslator } from "@intlayer/use-intl";
2
3
  import { getDictionary as getDictionary$1 } from "next-intlayer";
3
4
 
4
5
  //#region src/getDictionary.ts
5
- const navigatePath = (objectValue, path) => {
6
- if (!path) return objectValue;
7
- const parts = path.split(".");
8
- let current = objectValue;
9
- for (const part of parts) {
10
- if (current === null || current === void 0 || typeof current !== "object") return;
11
- current = current[part];
12
- }
13
- return current;
6
+ const readRestArgument = (rest) => {
7
+ if (typeof rest === "string") return { namespacePrefix: rest };
8
+ return { localeOverride: rest?.locale };
14
9
  };
15
10
  /**
16
11
  * Dictionary-accepting variant of `getTranslations`.
17
12
  *
18
- * Used internally by the SWC optimization: instead of looking up the dictionary
19
- * at runtime by key, the SWC plugin pre-imports the dictionary JSON at build time
20
- * and passes it directly here. This enables tree-shaking of unused locale content.
13
+ * Used internally by the build-time optimization: instead of looking up the
14
+ * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary
15
+ * JSON at build time and passes it directly here. This enables tree-shaking of
16
+ * unused locale content.
21
17
  *
22
- * Runs on the server, where next-intl apps do not mount an `IntlayerServerProvider`.
23
- * The request locale therefore cannot be read from a server context and is resolved
24
- * asynchronously from the cookie/header via `getLocale()`. `getTranslations` is always
25
- * awaited, so an async resolver is a drop-in replacement.
18
+ * Runs on the server, where next-intl apps do not mount an
19
+ * `IntlayerServerProvider`. The request locale therefore cannot be read from a
20
+ * server context and is resolved asynchronously from the cookie/header via
21
+ * `getLocale()` (or the explicit `{ locale }` of the object overload).
22
+ * `getTranslations` is always awaited, so an async resolver is a drop-in
23
+ * replacement.
26
24
  */
27
- const getDictionary = async (dictionary, namespacePrefix) => {
28
- const content = getDictionary$1(dictionary, await getLocale());
29
- const resolveKey = (key) => namespacePrefix ? `${namespacePrefix}.${key}` : key;
30
- return Object.assign((lookup, params) => {
31
- const rawValue = navigatePath(content, resolveKey(String(lookup)));
32
- const str = String(rawValue ?? resolveKey(String(lookup)));
33
- if (!params) return str;
34
- return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
35
- }, {
36
- has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
37
- raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
38
- });
39
- };
25
+ const getDictionary = (async (dictionary, rest) => {
26
+ const { namespacePrefix, localeOverride } = readRestArgument(rest);
27
+ const locale = localeOverride ?? await getLocale();
28
+ return createDictionaryTranslator(locale, getDictionary$1(dictionary, locale), namespacePrefix);
29
+ });
40
30
 
41
31
  //#endregion
42
32
  export { getDictionary };
@@ -1 +1 @@
1
- {"version":3,"file":"getDictionary.mjs","names":["getDictionaryBase"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary as getDictionaryBase } from 'next-intlayer';\nimport { getLocale } from './server/getLocale';\n\nconst 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/**\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 *\n * Runs on the server, where next-intl apps do not mount an `IntlayerServerProvider`.\n * The request locale therefore cannot be read from a server context and is resolved\n * asynchronously from the cookie/header via `getLocale()`. `getTranslations` is always\n * awaited, so an async resolver is a drop-in replacement.\n */\nexport const getDictionary = async <T extends Dictionary>(\n dictionary: T,\n namespacePrefix?: string\n) => {\n const locale = (await getLocale()) as LocalesValues;\n const content = getDictionaryBase(dictionary, locale);\n\n const resolveKey = (key: string): string =>\n namespacePrefix ? `${namespacePrefix}.${key}` : key;\n\n return Object.assign(\n <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const str = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<any>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<any>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;;AAMA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,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;;;;;;;;;;;;;;AAeT,MAAa,gBAAgB,OAC3B,YACA,oBACG;CAEH,MAAM,UAAUA,gBAAkB,YAAY,MADxB,WAAW,CACoB;CAErD,MAAM,cAAc,QAClB,kBAAkB,GAAG,gBAAgB,GAAG,QAAQ;AAElD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,MAAM,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC1D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;IAEH;EACE,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
1
+ {"version":3,"file":"getDictionary.mjs","names":["getDictionaryBase"],"sources":["../../src/getDictionary.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 { getDictionary as getDictionaryBase } from 'next-intlayer';\nimport { getLocale } from './server/getLocale';\n\n/**\n * Trailing argument left by the optimize pass. `getTranslations('ns.scope')`\n * yields the key-prefix remainder as a string, while the object overload\n * `getTranslations({ locale, namespace })` keeps its options object (with the\n * namespace stripped, since the dictionary is now passed directly).\n */\ntype DictionaryTranslatorRest = string | { locale?: LocalesValues };\n\nconst readRestArgument = (\n rest: DictionaryTranslatorRest | undefined\n): { namespacePrefix?: string; localeOverride?: LocalesValues } => {\n if (typeof rest === 'string') return { namespacePrefix: rest };\n return { localeOverride: rest?.locale };\n};\n\n/**\n * Overload set for {@link getDictionary}: a string rest argument is the\n * key-prefix remainder of a nested namespace (relative dot-paths under the\n * scope); otherwise the translator is typed against the dictionary's\n * dot-paths.\n */\ntype GetDictionary = {\n <T extends Dictionary, Prefix extends string>(\n dictionary: T,\n namespacePrefix: Prefix\n ): Promise<ScopedTranslateFunction<T['key'] & DictionaryKeys, Prefix>>;\n <T extends Dictionary>(\n dictionary: T,\n options?: { locale?: LocalesValues }\n ): Promise<TranslateFunction<T['key'] & DictionaryKeys>>;\n};\n\n/**\n * Dictionary-accepting variant of `getTranslations`.\n *\n * Used internally by the build-time optimization: instead of looking up the\n * dictionary at runtime by key, the babel/swc plugin pre-imports the dictionary\n * JSON at build time and passes it directly here. This enables tree-shaking of\n * unused locale content.\n *\n * Runs on the server, where next-intl apps do not mount an\n * `IntlayerServerProvider`. The request locale therefore cannot be read from a\n * server context and is resolved asynchronously from the cookie/header via\n * `getLocale()` (or the explicit `{ locale }` of the object overload).\n * `getTranslations` is always awaited, so an async resolver is a drop-in\n * replacement.\n */\nexport const getDictionary = (async <T extends Dictionary>(\n dictionary: T,\n rest?: DictionaryTranslatorRest\n) => {\n const { namespacePrefix, localeOverride } = readRestArgument(rest);\n const locale = localeOverride ?? ((await getLocale()) as LocalesValues);\n const content = getDictionaryBase(dictionary, locale);\n\n return createDictionaryTranslator(locale, content, namespacePrefix);\n}) as GetDictionary;\n"],"mappings":";;;;;AAqBA,MAAM,oBACJ,SACiE;CACjE,IAAI,OAAO,SAAS,UAAU,OAAO,EAAE,iBAAiB,KAAK;CAC7D,OAAO,EAAE,gBAAgB,MAAM,OAAO;AACxC;;;;;;;;;;;;;;;;AAkCA,MAAa,iBAAiB,OAC5B,YACA,SACG;CACH,MAAM,EAAE,iBAAiB,mBAAmB,iBAAiB,IAAI;CACjE,MAAM,SAAS,kBAAoB,MAAM,UAAU;CAGnD,OAAO,2BAA2B,QAFlBA,gBAAkB,YAAY,MAEE,GAAG,eAAe;AACpE"}
@@ -1,32 +1,17 @@
1
+ import { getLocale as getLocale$1 } from "./server/getLocale.mjs";
2
+ import { createDictionaryTranslator } from "@intlayer/use-intl";
1
3
  import { useDictionaryDynamic } from "next-intlayer/server";
2
4
 
3
5
  //#region src/getDictionaryDynamic.ts
4
- const navigatePath = (objectValue, path) => {
5
- if (!path) return objectValue;
6
- const parts = path.split(".");
7
- let current = objectValue;
8
- for (const part of parts) {
9
- if (current === null || current === void 0 || typeof current !== "object") return;
10
- current = current[part];
11
- }
12
- return current;
13
- };
14
6
  /**
15
7
  * Dynamic dictionary-accepting variant of `getTranslations`.
8
+ *
9
+ * Counterpart to {@link getDictionary} for dictionaries imported lazily per
10
+ * locale. Used internally by the build-time optimization.
16
11
  */
17
- const getDictionaryDynamic = async (dictionaryPromise, key, namespacePrefix) => {
18
- const content = await useDictionaryDynamic(dictionaryPromise, key);
19
- const resolveKey = (lookupKey) => namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;
20
- return Object.assign((lookup, params) => {
21
- const rawValue = navigatePath(content, resolveKey(String(lookup)));
22
- const str = String(rawValue ?? resolveKey(String(lookup)));
23
- if (!params) return str;
24
- return str.replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
25
- }, {
26
- has: (lookup) => navigatePath(content, resolveKey(String(lookup))) != null,
27
- raw: (lookup) => navigatePath(content, resolveKey(String(lookup)))
28
- });
29
- };
12
+ const getDictionaryDynamic = (async (dictionaryPromise, key, namespacePrefix) => {
13
+ return createDictionaryTranslator(await getLocale$1(), await useDictionaryDynamic(dictionaryPromise, key), namespacePrefix);
14
+ });
30
15
 
31
16
  //#endregion
32
17
  export { getDictionaryDynamic };
@@ -1 +1 @@
1
- {"version":3,"file":"getDictionaryDynamic.mjs","names":["getDictionaryDynamicBase"],"sources":["../../src/getDictionaryDynamic.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 { useDictionaryDynamic as getDictionaryDynamicBase } from 'next-intlayer/server';\n\nconst 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/**\n * Dynamic dictionary-accepting variant of `getTranslations`.\n */\nexport const getDictionaryDynamic = 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 getDictionaryDynamicBase<T, any>(\n dictionaryPromise,\n key as any\n );\n\n const resolveKey = (lookupKey: string): string =>\n namespacePrefix ? `${namespacePrefix}.${lookupKey}` : lookupKey;\n\n return Object.assign(\n <P extends ValidDotPathsFor<any>>(\n lookup: P,\n params?: Record<string, unknown>\n ): string => {\n const rawValue = navigatePath(content, resolveKey(String(lookup)));\n const str = String(rawValue ?? resolveKey(String(lookup)));\n if (!params) return str;\n return str.replace(/\\{(\\w+)\\}/g, (_, k) =>\n params[k] != null ? String(params[k]) : `{${k}}`\n );\n },\n {\n has: <P extends ValidDotPathsFor<any>>(lookup: P): boolean =>\n navigatePath(content, resolveKey(String(lookup))) != null,\n raw: <P extends ValidDotPathsFor<any>>(lookup: P): unknown =>\n navigatePath(content, resolveKey(String(lookup))),\n }\n );\n};\n"],"mappings":";;;AAKA,MAAM,gBAAgB,aAAsB,SAA0B;AACpE,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;;;;;AAMT,MAAa,uBAAuB,OAIlC,mBACA,KACA,oBACG;CACH,MAAM,UAAU,MAAMA,qBACpB,mBACA,IACD;CAED,MAAM,cAAc,cAClB,kBAAkB,GAAG,gBAAgB,GAAG,cAAc;AAExD,QAAO,OAAO,QAEV,QACA,WACW;EACX,MAAM,WAAW,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EAClE,MAAM,MAAM,OAAO,YAAY,WAAW,OAAO,OAAO,CAAC,CAAC;AAC1D,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,IAAI,QAAQ,eAAe,GAAG,MACnC,OAAO,MAAM,OAAO,OAAO,OAAO,GAAG,GAAG,IAAI,EAAE,GAC/C;IAEH;EACE,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC,IAAI;EACvD,MAAuC,WACrC,aAAa,SAAS,WAAW,OAAO,OAAO,CAAC,CAAC;EACpD,CACF"}
1
+ {"version":3,"file":"getDictionaryDynamic.mjs","names":["getLocale","getDictionaryDynamicBase"],"sources":["../../src/getDictionaryDynamic.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport {\n createDictionaryTranslator,\n type ScopedTranslateFunction,\n type TranslateFunction,\n} from '@intlayer/use-intl';\nimport { useDictionaryDynamic as getDictionaryDynamicBase } from 'next-intlayer/server';\nimport { getLocale } from './server/getLocale';\n\n/**\n * Overload set for {@link getDictionaryDynamic}: without a prefix the\n * translator is typed against the dictionary's dot-paths; with a prefix the\n * keys are relative dot-paths under that scope.\n */\ntype GetDictionaryDynamic = {\n <T extends Dictionary, K extends DictionaryKeys>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K\n ): Promise<TranslateFunction<K>>;\n <T extends Dictionary, K extends DictionaryKeys, Prefix extends string>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix: Prefix\n ): Promise<ScopedTranslateFunction<K, Prefix>>;\n};\n\n/**\n * Dynamic dictionary-accepting variant of `getTranslations`.\n *\n * Counterpart to {@link getDictionary} for dictionaries imported lazily per\n * locale. Used internally by the build-time optimization.\n */\nexport const getDictionaryDynamic = (async <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n namespacePrefix?: string\n) => {\n const locale = (await getLocale()) as LocalesValues;\n const content = await getDictionaryDynamicBase<T, K>(dictionaryPromise, key);\n\n return createDictionaryTranslator(locale, content, namespacePrefix);\n}) as GetDictionaryDynamic;\n"],"mappings":";;;;;;;;;;;AAqCA,MAAa,wBAAwB,OAInC,mBACA,KACA,oBACG;CAIH,OAAO,2BAA2B,MAHZA,YAAU,GAGU,MAFpBC,qBAA+B,mBAAmB,GAAG,GAExB,eAAe;AACpE"}