next-intl 3.25.0 → 4.0.0-beta-00a79d4

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 (450) hide show
  1. package/config.d.ts +2 -1
  2. package/dist/cjs/development/plugin.cjs +167 -0
  3. package/dist/{development → esm/development}/config.js +1 -5
  4. package/dist/esm/development/index.react-client.js +3 -0
  5. package/dist/esm/development/index.react-server.js +8 -0
  6. package/dist/{development → esm/development}/middleware/getAlternateLinksHeaderValue.js +18 -25
  7. package/dist/esm/development/middleware/middleware.js +155 -0
  8. package/dist/{development → esm/development}/middleware/resolveLocale.js +13 -25
  9. package/dist/esm/development/middleware/syncCookie.js +20 -0
  10. package/dist/{development → esm/development}/middleware/utils.js +24 -54
  11. package/dist/esm/development/middleware.js +1 -0
  12. package/dist/{development → esm/development}/navigation/react-client/createNavigation.js +22 -29
  13. package/dist/esm/development/navigation/react-client/useBasePathname.js +27 -0
  14. package/dist/esm/development/navigation/react-server/createNavigation.js +22 -0
  15. package/dist/esm/development/navigation/react-server/getServerLocale.js +12 -0
  16. package/dist/{development → esm/development}/navigation/shared/BaseLink.js +31 -36
  17. package/dist/{development → esm/development}/navigation/shared/createSharedNavigationFns.js +39 -50
  18. package/dist/{development → esm/development}/navigation/shared/syncLocaleCookie.js +5 -9
  19. package/dist/{development → esm/development}/navigation/shared/utils.js +21 -35
  20. package/dist/esm/development/navigation.react-client.js +1 -0
  21. package/dist/esm/development/navigation.react-server.js +1 -0
  22. package/dist/esm/development/plugin/createMessagesDeclaration.js +61 -0
  23. package/dist/esm/development/plugin/createNextIntlPlugin.js +23 -0
  24. package/dist/esm/development/plugin/getNextConfig.js +82 -0
  25. package/dist/esm/development/plugin/utils.js +11 -0
  26. package/dist/esm/development/plugin.js +1 -0
  27. package/dist/esm/development/react-client/index.js +35 -0
  28. package/dist/esm/development/react-server/NextIntlClientProviderServer.js +31 -0
  29. package/dist/esm/development/react-server/useConfig.js +21 -0
  30. package/dist/esm/development/react-server/useFormatter.js +9 -0
  31. package/dist/esm/development/react-server/useLocale.js +8 -0
  32. package/dist/esm/development/react-server/useMessages.js +9 -0
  33. package/dist/esm/development/react-server/useNow.js +12 -0
  34. package/dist/esm/development/react-server/useTimeZone.js +8 -0
  35. package/dist/esm/development/react-server/useTranslations.js +9 -0
  36. package/dist/esm/development/routing/config.js +28 -0
  37. package/dist/esm/development/routing/defineRouting.js +5 -0
  38. package/dist/esm/development/routing.js +1 -0
  39. package/dist/{development → esm/development}/server/react-client/index.js +5 -16
  40. package/dist/{development → esm/development}/server/react-server/RequestLocale.js +10 -14
  41. package/dist/{development → esm/development}/server/react-server/RequestLocaleCache.js +3 -8
  42. package/dist/esm/development/server/react-server/createRequestConfig.js +2 -0
  43. package/dist/esm/development/server/react-server/getConfig.js +53 -0
  44. package/dist/esm/development/server/react-server/getConfigNow.js +10 -0
  45. package/dist/esm/development/server/react-server/getDefaultNow.js +9 -0
  46. package/dist/esm/development/server/react-server/getFormats.js +10 -0
  47. package/dist/esm/development/server/react-server/getFormatter.js +21 -0
  48. package/dist/esm/development/server/react-server/getLocale.js +10 -0
  49. package/dist/esm/development/server/react-server/getMessages.js +19 -0
  50. package/dist/esm/development/server/react-server/getNow.js +8 -0
  51. package/dist/{development → esm/development}/server/react-server/getRequestConfig.js +1 -5
  52. package/dist/esm/development/server/react-server/getServerFormatter.js +21 -0
  53. package/dist/esm/development/server/react-server/getServerTranslator.js +12 -0
  54. package/dist/esm/development/server/react-server/getTimeZone.js +13 -0
  55. package/dist/{development → esm/development}/server/react-server/getTranslations.js +7 -15
  56. package/dist/esm/development/server.react-client.js +1 -0
  57. package/dist/esm/development/server.react-server.js +8 -0
  58. package/dist/esm/development/shared/NextIntlClientProvider.js +18 -0
  59. package/dist/esm/development/shared/constants.js +4 -0
  60. package/dist/esm/development/shared/use.js +13 -0
  61. package/dist/{development → esm/development}/shared/utils.js +6 -50
  62. package/dist/esm/production/index.react-client.js +1 -0
  63. package/dist/esm/production/middleware/getAlternateLinksHeaderValue.js +1 -0
  64. package/dist/esm/production/middleware/middleware.js +1 -0
  65. package/dist/esm/production/middleware/resolveLocale.js +1 -0
  66. package/dist/esm/production/middleware/syncCookie.js +1 -0
  67. package/dist/esm/production/middleware/utils.js +1 -0
  68. package/dist/esm/production/navigation/react-client/createNavigation.js +1 -0
  69. package/dist/esm/production/navigation/react-client/useBasePathname.js +1 -0
  70. package/dist/esm/production/navigation/react-server/createNavigation.js +1 -0
  71. package/dist/esm/production/navigation/shared/BaseLink.js +2 -0
  72. package/dist/esm/production/navigation/shared/createSharedNavigationFns.js +1 -0
  73. package/dist/esm/production/navigation/shared/syncLocaleCookie.js +1 -0
  74. package/dist/esm/production/navigation/shared/utils.js +1 -0
  75. package/dist/esm/production/navigation.react-client.js +1 -0
  76. package/dist/esm/production/navigation.react-server.js +1 -0
  77. package/dist/esm/production/plugin/createMessagesDeclaration.js +1 -0
  78. package/dist/esm/production/plugin/createNextIntlPlugin.js +1 -0
  79. package/dist/esm/production/plugin/getNextConfig.js +1 -0
  80. package/dist/esm/production/plugin/utils.js +1 -0
  81. package/dist/esm/production/plugin.js +1 -0
  82. package/dist/esm/production/react-client/index.js +1 -0
  83. package/dist/esm/production/react-server/NextIntlClientProviderServer.js +1 -0
  84. package/dist/esm/production/react-server/useConfig.js +1 -0
  85. package/dist/esm/production/react-server/useFormatter.js +1 -0
  86. package/dist/esm/production/react-server/useLocale.js +1 -0
  87. package/dist/esm/production/react-server/useMessages.js +1 -0
  88. package/dist/esm/production/react-server/useNow.js +1 -0
  89. package/dist/esm/production/react-server/useTimeZone.js +1 -0
  90. package/dist/esm/production/react-server/useTranslations.js +1 -0
  91. package/dist/esm/production/routing/config.js +1 -0
  92. package/dist/esm/production/server/react-client/index.js +1 -0
  93. package/dist/esm/production/server/react-server/RequestLocale.js +1 -0
  94. package/dist/esm/production/server/react-server/getConfig.js +1 -0
  95. package/dist/esm/production/server/react-server/getConfigNow.js +1 -0
  96. package/dist/esm/production/server/react-server/getDefaultNow.js +1 -0
  97. package/dist/esm/production/server/react-server/getFormats.js +1 -0
  98. package/dist/esm/production/server/react-server/getFormatter.js +1 -0
  99. package/dist/esm/production/server/react-server/getLocale.js +1 -0
  100. package/dist/esm/production/server/react-server/getMessages.js +1 -0
  101. package/dist/esm/production/server/react-server/getNow.js +1 -0
  102. package/dist/esm/production/server/react-server/getServerFormatter.js +1 -0
  103. package/dist/esm/{server → production/server}/react-server/getTimeZone.js +1 -1
  104. package/dist/esm/production/server/react-server/getTranslations.js +1 -0
  105. package/dist/esm/production/server.react-client.js +1 -0
  106. package/dist/esm/production/server.react-server.js +1 -0
  107. package/dist/esm/production/shared/NextIntlClientProvider.js +2 -0
  108. package/dist/esm/production/shared/constants.js +1 -0
  109. package/dist/esm/production/shared/use.js +1 -0
  110. package/dist/esm/production/shared/utils.js +1 -0
  111. package/dist/types/{src/index.react-client.d.ts → index.react-client.d.ts} +1 -1
  112. package/dist/types/index.react-server.d.ts +1 -0
  113. package/dist/types/{src/middleware → middleware}/getAlternateLinksHeaderValue.d.ts +3 -3
  114. package/dist/types/{src/middleware → middleware}/index.d.ts +1 -1
  115. package/dist/types/middleware/middleware.d.ts +4 -0
  116. package/dist/types/{src/middleware → middleware}/resolveLocale.d.ts +5 -4
  117. package/dist/types/middleware/syncCookie.d.ts +7 -0
  118. package/dist/types/{src/middleware → middleware}/utils.d.ts +4 -3
  119. package/dist/types/middleware.d.ts +1 -0
  120. package/dist/types/{src/navigation → navigation}/react-client/createNavigation.d.ts +58 -57
  121. package/dist/types/navigation/react-client/index.d.ts +2 -0
  122. package/dist/types/{src/navigation → navigation}/react-client/useBasePathname.d.ts +1 -1
  123. package/dist/types/{src/navigation → navigation}/react-server/createNavigation.d.ts +30 -30
  124. package/dist/types/navigation/react-server/index.d.ts +2 -0
  125. package/dist/types/navigation/shared/BaseLink.d.ts +19 -0
  126. package/dist/types/navigation/shared/createSharedNavigationFns.d.ts +386 -0
  127. package/dist/types/{src/navigation → navigation}/shared/syncLocaleCookie.d.ts +3 -2
  128. package/dist/types/{src/navigation → navigation}/shared/utils.d.ts +5 -4
  129. package/dist/types/navigation.react-client.d.ts +1 -0
  130. package/dist/types/navigation.react-server.d.ts +1 -0
  131. package/dist/types/plugin/createMessagesDeclaration.d.ts +1 -0
  132. package/dist/types/plugin/createNextIntlPlugin.d.ts +3 -0
  133. package/dist/types/plugin/getNextConfig.d.ts +3 -0
  134. package/dist/types/plugin/index.d.ts +1 -0
  135. package/dist/types/plugin/types.d.ts +6 -0
  136. package/dist/types/plugin/utils.d.ts +2 -0
  137. package/dist/types/plugin.d.ts +1 -0
  138. package/dist/types/{src/react-client → react-client}/index.d.ts +1 -2
  139. package/dist/types/react-server/NextIntlClientProviderServer.d.ts +5 -0
  140. package/dist/types/react-server/index.d.ts +15 -0
  141. package/dist/types/{src/react-server → react-server}/testUtils.d.ts +1 -1
  142. package/dist/types/{src/react-server → react-server}/useConfig.d.ts +1 -1
  143. package/dist/types/react-server/useFormatter.d.ts +2 -0
  144. package/dist/types/react-server/useLocale.d.ts +2 -0
  145. package/dist/types/react-server/useMessages.d.ts +2 -0
  146. package/dist/types/react-server/useNow.d.ts +2 -0
  147. package/dist/types/react-server/useTimeZone.d.ts +2 -0
  148. package/dist/types/{src/routing → routing}/config.d.ts +2 -4
  149. package/dist/types/{src/routing → routing}/defineRouting.d.ts +2 -2
  150. package/dist/types/routing/index.d.ts +3 -0
  151. package/dist/types/routing.d.ts +1 -0
  152. package/dist/types/{src/server → server}/react-client/index.d.ts +1 -2
  153. package/dist/types/server/react-server/RequestLocaleCache.d.ts +3 -0
  154. package/dist/types/{src/server → server}/react-server/createRequestConfig.d.ts +1 -1
  155. package/dist/types/{src/server → server}/react-server/getConfig.d.ts +2 -3
  156. package/dist/types/server/react-server/getConfigNow.d.ts +4 -0
  157. package/dist/types/server/react-server/getDefaultNow.d.ts +3 -0
  158. package/dist/types/server/react-server/getFormats.d.ts +3 -0
  159. package/dist/types/{src/server → server}/react-server/getFormatter.d.ts +2 -2
  160. package/dist/types/server/react-server/getLocale.d.ts +4 -0
  161. package/dist/types/server/react-server/getMessages.d.ts +6 -0
  162. package/dist/types/server/react-server/getNow.d.ts +4 -0
  163. package/dist/types/{src/server → server}/react-server/getRequestConfig.d.ts +2 -19
  164. package/dist/types/server/react-server/getServerFormatter.d.ts +10 -0
  165. package/dist/types/server/react-server/getServerTranslator.d.ts +4 -0
  166. package/dist/types/server/react-server/getTimeZone.d.ts +4 -0
  167. package/dist/types/server/react-server/getTranslations.d.ts +8 -0
  168. package/dist/types/server/react-server/index.d.ts +11 -0
  169. package/dist/types/server.react-client.d.ts +1 -0
  170. package/dist/types/server.react-server.d.ts +1 -0
  171. package/dist/types/{src/shared → shared}/NextIntlClientProvider.d.ts +5 -4
  172. package/dist/types/shared/constants.d.ts +1 -0
  173. package/dist/types/shared/use.d.ts +3 -0
  174. package/dist/types/{src/shared → shared}/utils.d.ts +3 -9
  175. package/middleware.d.ts +2 -1
  176. package/navigation.d.ts +2 -1
  177. package/package.json +57 -26
  178. package/plugin.d.cts +3 -0
  179. package/plugin.d.ts +3 -7
  180. package/routing.d.ts +2 -1
  181. package/server.d.ts +2 -1
  182. package/dist/config.js +0 -7
  183. package/dist/development/_virtual/_rollupPluginBabelHelpers.js +0 -15
  184. package/dist/development/index.react-client.js +0 -21
  185. package/dist/development/index.react-server.js +0 -28
  186. package/dist/development/middleware/middleware.js +0 -169
  187. package/dist/development/middleware/syncCookie.js +0 -20
  188. package/dist/development/middleware.js +0 -9
  189. package/dist/development/navigation/react-client/ClientLink.js +0 -55
  190. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -156
  191. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +0 -67
  192. package/dist/development/navigation/react-client/redirects.js +0 -32
  193. package/dist/development/navigation/react-client/useBasePathname.js +0 -31
  194. package/dist/development/navigation/react-client/useBaseRouter.js +0 -72
  195. package/dist/development/navigation/react-server/ServerLink.js +0 -32
  196. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -95
  197. package/dist/development/navigation/react-server/createNavigation.js +0 -30
  198. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +0 -56
  199. package/dist/development/navigation/react-server/getServerLocale.js +0 -16
  200. package/dist/development/navigation/react-server/redirects.js +0 -24
  201. package/dist/development/navigation/shared/LegacyBaseLink.js +0 -57
  202. package/dist/development/navigation/shared/redirects.js +0 -25
  203. package/dist/development/navigation.react-client.js +0 -13
  204. package/dist/development/navigation.react-server.js +0 -13
  205. package/dist/development/plugin.js +0 -101
  206. package/dist/development/react-client/index.js +0 -38
  207. package/dist/development/react-client/useLocale.js +0 -28
  208. package/dist/development/react-server/NextIntlClientProviderServer.js +0 -33
  209. package/dist/development/react-server/getTranslator.js +0 -16
  210. package/dist/development/react-server/useConfig.js +0 -25
  211. package/dist/development/react-server/useFormatter.js +0 -18
  212. package/dist/development/react-server/useLocale.js +0 -15
  213. package/dist/development/react-server/useMessages.js +0 -16
  214. package/dist/development/react-server/useNow.js +0 -19
  215. package/dist/development/react-server/useTimeZone.js +0 -15
  216. package/dist/development/react-server/useTranslations.js +0 -17
  217. package/dist/development/routing/config.js +0 -35
  218. package/dist/development/routing/defineRouting.js +0 -9
  219. package/dist/development/routing.js +0 -9
  220. package/dist/development/server/react-server/RequestLocaleLegacy.js +0 -43
  221. package/dist/development/server/react-server/createRequestConfig.js +0 -16
  222. package/dist/development/server/react-server/getConfig.js +0 -73
  223. package/dist/development/server/react-server/getFormatter.js +0 -25
  224. package/dist/development/server/react-server/getLocale.js +0 -14
  225. package/dist/development/server/react-server/getMessages.js +0 -24
  226. package/dist/development/server/react-server/getNow.js +0 -17
  227. package/dist/development/server/react-server/getTimeZone.js +0 -17
  228. package/dist/development/server.react-client.js +0 -17
  229. package/dist/development/server.react-server.js +0 -24
  230. package/dist/development/shared/NextIntlClientProvider.js +0 -30
  231. package/dist/development/shared/constants.js +0 -12
  232. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +0 -1
  233. package/dist/esm/index.react-client.js +0 -1
  234. package/dist/esm/middleware/getAlternateLinksHeaderValue.js +0 -1
  235. package/dist/esm/middleware/middleware.js +0 -1
  236. package/dist/esm/middleware/resolveLocale.js +0 -1
  237. package/dist/esm/middleware/syncCookie.js +0 -1
  238. package/dist/esm/middleware/utils.js +0 -1
  239. package/dist/esm/navigation/react-client/ClientLink.js +0 -1
  240. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -1
  241. package/dist/esm/navigation/react-client/createNavigation.js +0 -1
  242. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +0 -1
  243. package/dist/esm/navigation/react-client/redirects.js +0 -1
  244. package/dist/esm/navigation/react-client/useBasePathname.js +0 -1
  245. package/dist/esm/navigation/react-client/useBaseRouter.js +0 -1
  246. package/dist/esm/navigation/react-server/ServerLink.js +0 -1
  247. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -1
  248. package/dist/esm/navigation/react-server/createNavigation.js +0 -1
  249. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +0 -1
  250. package/dist/esm/navigation/react-server/redirects.js +0 -1
  251. package/dist/esm/navigation/shared/BaseLink.js +0 -2
  252. package/dist/esm/navigation/shared/LegacyBaseLink.js +0 -2
  253. package/dist/esm/navigation/shared/createSharedNavigationFns.js +0 -1
  254. package/dist/esm/navigation/shared/redirects.js +0 -1
  255. package/dist/esm/navigation/shared/syncLocaleCookie.js +0 -1
  256. package/dist/esm/navigation/shared/utils.js +0 -1
  257. package/dist/esm/navigation.react-client.js +0 -1
  258. package/dist/esm/navigation.react-server.js +0 -1
  259. package/dist/esm/plugin.js +0 -1
  260. package/dist/esm/react-client/index.js +0 -1
  261. package/dist/esm/react-client/useLocale.js +0 -1
  262. package/dist/esm/react-server/NextIntlClientProviderServer.js +0 -1
  263. package/dist/esm/react-server/useConfig.js +0 -1
  264. package/dist/esm/react-server/useFormatter.js +0 -1
  265. package/dist/esm/react-server/useLocale.js +0 -1
  266. package/dist/esm/react-server/useMessages.js +0 -1
  267. package/dist/esm/react-server/useNow.js +0 -1
  268. package/dist/esm/react-server/useTimeZone.js +0 -1
  269. package/dist/esm/react-server/useTranslations.js +0 -1
  270. package/dist/esm/routing/config.js +0 -1
  271. package/dist/esm/server/react-client/index.js +0 -1
  272. package/dist/esm/server/react-server/RequestLocale.js +0 -1
  273. package/dist/esm/server/react-server/RequestLocaleLegacy.js +0 -1
  274. package/dist/esm/server/react-server/getConfig.js +0 -1
  275. package/dist/esm/server/react-server/getFormatter.js +0 -1
  276. package/dist/esm/server/react-server/getLocale.js +0 -1
  277. package/dist/esm/server/react-server/getMessages.js +0 -1
  278. package/dist/esm/server/react-server/getNow.js +0 -1
  279. package/dist/esm/server/react-server/getTranslations.js +0 -1
  280. package/dist/esm/server.react-client.js +0 -1
  281. package/dist/esm/server.react-server.js +0 -1
  282. package/dist/esm/shared/NextIntlClientProvider.js +0 -2
  283. package/dist/esm/shared/constants.js +0 -1
  284. package/dist/esm/shared/utils.js +0 -1
  285. package/dist/index.react-client.js +0 -7
  286. package/dist/index.react-server.js +0 -7
  287. package/dist/middleware.js +0 -7
  288. package/dist/navigation.react-client.js +0 -7
  289. package/dist/navigation.react-server.js +0 -7
  290. package/dist/plugin.js +0 -7
  291. package/dist/production/_virtual/_rollupPluginBabelHelpers.js +0 -1
  292. package/dist/production/config.js +0 -1
  293. package/dist/production/index.react-client.js +0 -1
  294. package/dist/production/index.react-server.js +0 -1
  295. package/dist/production/middleware/getAlternateLinksHeaderValue.js +0 -1
  296. package/dist/production/middleware/middleware.js +0 -1
  297. package/dist/production/middleware/resolveLocale.js +0 -1
  298. package/dist/production/middleware/syncCookie.js +0 -1
  299. package/dist/production/middleware/utils.js +0 -1
  300. package/dist/production/middleware.js +0 -1
  301. package/dist/production/navigation/react-client/ClientLink.js +0 -1
  302. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +0 -1
  303. package/dist/production/navigation/react-client/createNavigation.js +0 -1
  304. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +0 -1
  305. package/dist/production/navigation/react-client/redirects.js +0 -1
  306. package/dist/production/navigation/react-client/useBasePathname.js +0 -1
  307. package/dist/production/navigation/react-client/useBaseRouter.js +0 -1
  308. package/dist/production/navigation/react-server/ServerLink.js +0 -1
  309. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +0 -1
  310. package/dist/production/navigation/react-server/createNavigation.js +0 -1
  311. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +0 -1
  312. package/dist/production/navigation/react-server/getServerLocale.js +0 -1
  313. package/dist/production/navigation/react-server/redirects.js +0 -1
  314. package/dist/production/navigation/shared/BaseLink.js +0 -2
  315. package/dist/production/navigation/shared/LegacyBaseLink.js +0 -2
  316. package/dist/production/navigation/shared/createSharedNavigationFns.js +0 -1
  317. package/dist/production/navigation/shared/redirects.js +0 -1
  318. package/dist/production/navigation/shared/syncLocaleCookie.js +0 -1
  319. package/dist/production/navigation/shared/utils.js +0 -1
  320. package/dist/production/navigation.react-client.js +0 -1
  321. package/dist/production/navigation.react-server.js +0 -1
  322. package/dist/production/plugin.js +0 -1
  323. package/dist/production/react-client/index.js +0 -1
  324. package/dist/production/react-client/useLocale.js +0 -1
  325. package/dist/production/react-server/NextIntlClientProviderServer.js +0 -1
  326. package/dist/production/react-server/getTranslator.js +0 -1
  327. package/dist/production/react-server/useConfig.js +0 -1
  328. package/dist/production/react-server/useFormatter.js +0 -1
  329. package/dist/production/react-server/useLocale.js +0 -1
  330. package/dist/production/react-server/useMessages.js +0 -1
  331. package/dist/production/react-server/useNow.js +0 -1
  332. package/dist/production/react-server/useTimeZone.js +0 -1
  333. package/dist/production/react-server/useTranslations.js +0 -1
  334. package/dist/production/routing/config.js +0 -1
  335. package/dist/production/routing/defineRouting.js +0 -1
  336. package/dist/production/routing.js +0 -1
  337. package/dist/production/server/react-client/index.js +0 -1
  338. package/dist/production/server/react-server/RequestLocale.js +0 -1
  339. package/dist/production/server/react-server/RequestLocaleCache.js +0 -1
  340. package/dist/production/server/react-server/RequestLocaleLegacy.js +0 -1
  341. package/dist/production/server/react-server/createRequestConfig.js +0 -1
  342. package/dist/production/server/react-server/getConfig.js +0 -1
  343. package/dist/production/server/react-server/getFormatter.js +0 -1
  344. package/dist/production/server/react-server/getLocale.js +0 -1
  345. package/dist/production/server/react-server/getMessages.js +0 -1
  346. package/dist/production/server/react-server/getNow.js +0 -1
  347. package/dist/production/server/react-server/getRequestConfig.js +0 -1
  348. package/dist/production/server/react-server/getTimeZone.js +0 -1
  349. package/dist/production/server/react-server/getTranslations.js +0 -1
  350. package/dist/production/server.react-client.js +0 -1
  351. package/dist/production/server.react-server.js +0 -1
  352. package/dist/production/shared/NextIntlClientProvider.js +0 -2
  353. package/dist/production/shared/constants.js +0 -1
  354. package/dist/production/shared/utils.js +0 -1
  355. package/dist/routing.js +0 -7
  356. package/dist/server.react-client.js +0 -7
  357. package/dist/server.react-server.js +0 -7
  358. package/dist/types/__mocks__/react.d.ts +0 -9
  359. package/dist/types/src/index.react-server.d.ts +0 -1
  360. package/dist/types/src/middleware/getAlternateLinksHeaderValue.test.d.ts +0 -1
  361. package/dist/types/src/middleware/middleware.d.ts +0 -13
  362. package/dist/types/src/middleware/middleware.test.d.ts +0 -1
  363. package/dist/types/src/middleware/resolveLocale.test.d.ts +0 -1
  364. package/dist/types/src/middleware/syncCookie.d.ts +0 -3
  365. package/dist/types/src/middleware/utils.test.d.ts +0 -1
  366. package/dist/types/src/middleware.d.ts +0 -1
  367. package/dist/types/src/navigation/createLocalizedPathnamesNavigation.test.d.ts +0 -1
  368. package/dist/types/src/navigation/createNavigation.test.d.ts +0 -1
  369. package/dist/types/src/navigation/createSharedPathnamesNavigation.test.d.ts +0 -1
  370. package/dist/types/src/navigation/react-client/ClientLink.d.ts +0 -31
  371. package/dist/types/src/navigation/react-client/ClientLink.test.d.ts +0 -1
  372. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +0 -91
  373. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.test.d.ts +0 -1
  374. package/dist/types/src/navigation/react-client/createNavigation.test.d.ts +0 -1
  375. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +0 -66
  376. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.test.d.ts +0 -1
  377. package/dist/types/src/navigation/react-client/index.d.ts +0 -7
  378. package/dist/types/src/navigation/react-client/redirects.d.ts +0 -10
  379. package/dist/types/src/navigation/react-client/useBasePathname.test.d.ts +0 -1
  380. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +0 -33
  381. package/dist/types/src/navigation/react-client/useBaseRouter.test.d.ts +0 -1
  382. package/dist/types/src/navigation/react-server/ServerLink.d.ts +0 -9
  383. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +0 -70
  384. package/dist/types/src/navigation/react-server/createNavigation.test.d.ts +0 -1
  385. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +0 -11
  386. package/dist/types/src/navigation/react-server/index.d.ts +0 -4
  387. package/dist/types/src/navigation/react-server/redirects.d.ts +0 -10
  388. package/dist/types/src/navigation/shared/BaseLink.d.ts +0 -17
  389. package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +0 -12
  390. package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +0 -386
  391. package/dist/types/src/navigation/shared/redirects.d.ts +0 -11
  392. package/dist/types/src/navigation/shared/redirects.test.d.ts +0 -1
  393. package/dist/types/src/navigation/shared/utils.test.d.ts +0 -1
  394. package/dist/types/src/navigation.react-client.d.ts +0 -1
  395. package/dist/types/src/navigation.react-server.d.ts +0 -1
  396. package/dist/types/src/plugin.d.ts +0 -1
  397. package/dist/types/src/react-client/useFormatter.test.d.ts +0 -1
  398. package/dist/types/src/react-client/useLocale.d.ts +0 -1
  399. package/dist/types/src/react-client/useLocale.test.d.ts +0 -1
  400. package/dist/types/src/react-client/useNow.test.d.ts +0 -1
  401. package/dist/types/src/react-client/useTimeZone.test.d.ts +0 -1
  402. package/dist/types/src/react-client/useTranslations.test.d.ts +0 -1
  403. package/dist/types/src/react-server/NextIntlClientProviderServer.d.ts +0 -5
  404. package/dist/types/src/react-server/NextIntlClientProviderServer.test.d.ts +0 -1
  405. package/dist/types/src/react-server/getTranslator.d.ts +0 -51
  406. package/dist/types/src/react-server/index.d.ts +0 -15
  407. package/dist/types/src/react-server/index.test.d.ts +0 -1
  408. package/dist/types/src/react-server/useFormatter.d.ts +0 -2
  409. package/dist/types/src/react-server/useLocale.d.ts +0 -2
  410. package/dist/types/src/react-server/useMessages.d.ts +0 -2
  411. package/dist/types/src/react-server/useNow.d.ts +0 -2
  412. package/dist/types/src/react-server/useTimeZone.d.ts +0 -2
  413. package/dist/types/src/react-server/useTranslations.test.d.ts +0 -1
  414. package/dist/types/src/routing/defineRouting.test.d.ts +0 -1
  415. package/dist/types/src/routing/index.d.ts +0 -3
  416. package/dist/types/src/routing/types.test.d.ts +0 -1
  417. package/dist/types/src/routing.d.ts +0 -1
  418. package/dist/types/src/server/react-client/index.test.d.ts +0 -1
  419. package/dist/types/src/server/react-server/RequestLocaleCache.d.ts +0 -2
  420. package/dist/types/src/server/react-server/RequestLocaleLegacy.d.ts +0 -1
  421. package/dist/types/src/server/react-server/getLocale.d.ts +0 -3
  422. package/dist/types/src/server/react-server/getMessages.d.ts +0 -6
  423. package/dist/types/src/server/react-server/getNow.d.ts +0 -3
  424. package/dist/types/src/server/react-server/getTimeZone.d.ts +0 -3
  425. package/dist/types/src/server/react-server/getTranslations.d.ts +0 -92
  426. package/dist/types/src/server/react-server/index.d.ts +0 -14
  427. package/dist/types/src/server/react-server/index.test.d.ts +0 -1
  428. package/dist/types/src/server.react-client.d.ts +0 -1
  429. package/dist/types/src/server.react-server.d.ts +0 -1
  430. package/dist/types/src/shared/NextIntlClientProvider.test.d.ts +0 -1
  431. package/dist/types/src/shared/constants.d.ts +0 -3
  432. package/dist/types/src/shared/utils.test.d.ts +0 -1
  433. package/dist/types/test/setup.d.ts +0 -1
  434. /package/dist/esm/{config.js → production/config.js} +0 -0
  435. /package/dist/esm/{index.react-server.js → production/index.react-server.js} +0 -0
  436. /package/dist/esm/{middleware.js → production/middleware.js} +0 -0
  437. /package/dist/esm/{navigation → production/navigation}/react-server/getServerLocale.js +0 -0
  438. /package/dist/esm/{routing → production/routing}/defineRouting.js +0 -0
  439. /package/dist/esm/{routing.js → production/routing.js} +0 -0
  440. /package/dist/esm/{server → production/server}/react-server/RequestLocaleCache.js +0 -0
  441. /package/dist/esm/{server → production/server}/react-server/createRequestConfig.js +0 -0
  442. /package/dist/esm/{server → production/server}/react-server/getRequestConfig.js +0 -0
  443. /package/dist/esm/{react-server/getTranslator.js → production/server/react-server/getServerTranslator.js} +0 -0
  444. /package/dist/types/{src/config.d.ts → config.d.ts} +0 -0
  445. /package/dist/types/{src/navigation → navigation}/react-server/getServerLocale.d.ts +0 -0
  446. /package/dist/types/{src/navigation → navigation}/shared/StrictParams.d.ts +0 -0
  447. /package/dist/types/{src/react-server → react-server}/useTranslations.d.ts +0 -0
  448. /package/dist/types/{src/routing → routing}/types.d.ts +0 -0
  449. /package/dist/types/{src/server → server}/react-server/RequestLocale.d.ts +0 -0
  450. /package/dist/types/{src/shared → shared}/types.d.ts +0 -0
package/config.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import config from './dist/types/src/config';
1
+ // Needed for projects with `moduleResolution: 'node'`
2
+ import config from './dist/types/config';
2
3
 
3
4
  export = config;
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var chokidar = require('chokidar');
6
+
7
+ function formatMessage(message) {
8
+ return `\n[next-intl] ${message}\n`;
9
+ }
10
+ function throwError(message) {
11
+ throw new Error(formatMessage(message));
12
+ }
13
+ function warn(message) {
14
+ console.warn(formatMessage(message));
15
+ }
16
+
17
+ function runOnce(fn) {
18
+ if (process.env._NEXT_INTL_COMPILE_MESSAGES === '1') {
19
+ return;
20
+ }
21
+ process.env._NEXT_INTL_COMPILE_MESSAGES = '1';
22
+ fn();
23
+ }
24
+ function createMessagesDeclaration(messagesPath) {
25
+ const fullPath = path.resolve(messagesPath);
26
+ if (!fs.existsSync(fullPath)) {
27
+ throwError(`\`createMessagesDeclaration\` points to a non-existent file: ${fullPath}`);
28
+ }
29
+ if (!fullPath.endsWith('.json')) {
30
+ throwError(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${fullPath}`);
31
+ }
32
+ const isDev = process.argv.includes('dev');
33
+ const isBuild = process.argv.includes('build');
34
+ if (!isDev && !isBuild) {
35
+ return;
36
+ }
37
+
38
+ // Next.js can call the Next.js config multiple
39
+ // times - ensure we only run once.
40
+ runOnce(() => {
41
+ compileDeclaration(messagesPath);
42
+ if (isDev) {
43
+ startWatching(messagesPath);
44
+ }
45
+ });
46
+ }
47
+ function startWatching(messagesPath) {
48
+ const watcher = chokidar.watch(messagesPath);
49
+ watcher.on('change', () => {
50
+ compileDeclaration(messagesPath, true);
51
+ });
52
+ process.on('exit', () => {
53
+ void watcher.close();
54
+ });
55
+ }
56
+ function compileDeclaration(messagesPath, async = false) {
57
+ const declarationPath = messagesPath.replace(/\.json$/, '.d.json.ts');
58
+ function createDeclaration(content) {
59
+ return `// This file is auto-generated by next-intl, do not edit directly.
60
+ // See: https://next-intl-docs.vercel.app/docs/workflows/typescript#messages-arguments
61
+
62
+ declare const messages: ${content.trim()};
63
+ export default messages;`;
64
+ }
65
+ if (async) {
66
+ return fs.promises.readFile(messagesPath, 'utf-8').then(content => fs.promises.writeFile(declarationPath, createDeclaration(content)));
67
+ }
68
+ const content = fs.readFileSync(messagesPath, 'utf-8');
69
+ fs.writeFileSync(declarationPath, createDeclaration(content));
70
+ }
71
+
72
+ function withExtensions(localPath) {
73
+ return [`${localPath}.ts`, `${localPath}.tsx`, `${localPath}.js`, `${localPath}.jsx`];
74
+ }
75
+ function resolveI18nPath(providedPath, cwd) {
76
+ function resolvePath(pathname) {
77
+ const parts = [];
78
+ if (cwd) parts.push(cwd);
79
+ parts.push(pathname);
80
+ return path.resolve(...parts);
81
+ }
82
+ function pathExists(pathname) {
83
+ return fs.existsSync(resolvePath(pathname));
84
+ }
85
+ if (providedPath) {
86
+ if (!pathExists(providedPath)) {
87
+ throwError(`Could not find i18n config at ${providedPath}, please provide a valid path.`);
88
+ }
89
+ return providedPath;
90
+ } else {
91
+ for (const candidate of [...withExtensions('./i18n/request'), ...withExtensions('./src/i18n/request')]) {
92
+ if (pathExists(candidate)) {
93
+ return candidate;
94
+ }
95
+ }
96
+ throwError(`Could not locate request configuration module.\n\nThis path is supported by default: ./(src/)i18n/request.{js,jsx,ts,tsx}\n\nAlternatively, you can specify a custom location in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(
97
+
98
+ Alternatively, you can specify a custom location in your Next.js config:
99
+
100
+ const withNextIntl = createNextIntlPlugin(
101
+ './path/to/i18n/request.tsx'
102
+ );`);
103
+ }
104
+ }
105
+ function getNextConfig(pluginConfig, nextConfig) {
106
+ const useTurbo = process.env.TURBOPACK != null;
107
+ const nextIntlConfig = {};
108
+
109
+ // Assign alias for `next-intl/config`
110
+ if (useTurbo) {
111
+ if (pluginConfig.requestConfig?.startsWith('/')) {
112
+ throwError("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: " + pluginConfig.requestConfig);
113
+ }
114
+
115
+ // `NextConfig['turbo']` is stable in Next.js 15. In case the
116
+ // experimental feature is removed in the future, we should
117
+ // replace this accordingly in a future major version.
118
+ nextIntlConfig.experimental = {
119
+ ...nextConfig?.experimental,
120
+ turbo: {
121
+ ...nextConfig?.experimental?.turbo,
122
+ resolveAlias: {
123
+ ...nextConfig?.experimental?.turbo?.resolveAlias,
124
+ // Turbo aliases don't work with absolute
125
+ // paths (see error handling above)
126
+ 'next-intl/config': resolveI18nPath(pluginConfig.requestConfig)
127
+ }
128
+ }
129
+ };
130
+ } else {
131
+ nextIntlConfig.webpack = function webpack(...[config, options]) {
132
+ // Webpack requires absolute paths
133
+ config.resolve.alias['next-intl/config'] = path.resolve(config.context, resolveI18nPath(pluginConfig.requestConfig, config.context));
134
+ if (typeof nextConfig?.webpack === 'function') {
135
+ return nextConfig.webpack(config, options);
136
+ }
137
+ return config;
138
+ };
139
+ }
140
+
141
+ // Forward config
142
+ nextIntlConfig.env = {
143
+ ...nextConfig?.env,
144
+ _next_intl_trailing_slash: nextConfig?.trailingSlash ? 'true' : undefined
145
+ };
146
+ return Object.assign({}, nextConfig, nextIntlConfig);
147
+ }
148
+
149
+ function initPlugin(pluginConfig, nextConfig) {
150
+ if (nextConfig?.i18n != null) {
151
+ warn("\n[next-intl] An `i18n` property was found in your Next.js config. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the Pages Router, you can refer to this example: https://next-intl-docs.vercel.app/examples#app-router-migration\n");
152
+ }
153
+ if (pluginConfig.experimental?.createMessagesDeclaration) {
154
+ createMessagesDeclaration(pluginConfig.experimental.createMessagesDeclaration);
155
+ }
156
+ return getNextConfig(pluginConfig, nextConfig);
157
+ }
158
+ function createNextIntlPlugin(i18nPathOrConfig = {}) {
159
+ const config = typeof i18nPathOrConfig === 'string' ? {
160
+ requestConfig: i18nPathOrConfig
161
+ } : i18nPathOrConfig;
162
+ return function withNextIntl(nextConfig) {
163
+ return initPlugin(config, nextConfig);
164
+ };
165
+ }
166
+
167
+ module.exports = createNextIntlPlugin;
@@ -1,9 +1,5 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
1
  function getConfig() {
6
2
  throw new Error("Couldn't find next-intl config file. Please follow the instructions at https://next-intl-docs.vercel.app/docs/getting-started/app-router");
7
3
  }
8
4
 
9
- exports.default = getConfig;
5
+ export { getConfig as default };
@@ -0,0 +1,3 @@
1
+ export { useFormatter, useTranslations } from './react-client/index.js';
2
+ export { default as NextIntlClientProvider } from './shared/NextIntlClientProvider.js';
3
+ export * from 'use-intl';
@@ -0,0 +1,8 @@
1
+ export { default as useLocale } from './react-server/useLocale.js';
2
+ export { default as useTranslations } from './react-server/useTranslations.js';
3
+ export { default as useFormatter } from './react-server/useFormatter.js';
4
+ export { default as useNow } from './react-server/useNow.js';
5
+ export { default as useTimeZone } from './react-server/useTimeZone.js';
6
+ export { default as useMessages } from './react-server/useMessages.js';
7
+ export { default as NextIntlClientProvider } from './react-server/NextIntlClientProviderServer.js';
8
+ export * from 'use-intl/core';
@@ -1,46 +1,39 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utils$1 = require('../shared/utils.js');
6
- var utils = require('./utils.js');
1
+ import { normalizeTrailingSlash } from '../shared/utils.js';
2
+ import { getHost, getNormalizedPathname, getLocalePrefixes, isLocaleSupportedOnDomain, applyBasePath, formatTemplatePathname } from './utils.js';
7
3
 
8
4
  /**
9
5
  * See https://developers.google.com/search/docs/specialty/international/localized-versions
10
6
  */
11
- function getAlternateLinksHeaderValue(_ref) {
12
- var _request$headers$get;
13
- let {
14
- localizedPathnames,
15
- request,
16
- resolvedLocale,
17
- routing
18
- } = _ref;
7
+ function getAlternateLinksHeaderValue({
8
+ localizedPathnames,
9
+ request,
10
+ resolvedLocale,
11
+ routing
12
+ }) {
19
13
  const normalizedUrl = request.nextUrl.clone();
20
- const host = utils.getHost(request.headers);
14
+ const host = getHost(request.headers);
21
15
  if (host) {
22
16
  normalizedUrl.port = '';
23
17
  normalizedUrl.host = host;
24
18
  }
25
- normalizedUrl.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : normalizedUrl.protocol;
26
- normalizedUrl.pathname = utils.getNormalizedPathname(normalizedUrl.pathname, routing.locales, routing.localePrefix);
19
+ normalizedUrl.protocol = request.headers.get('x-forwarded-proto') ?? normalizedUrl.protocol;
20
+ normalizedUrl.pathname = getNormalizedPathname(normalizedUrl.pathname, routing.locales, routing.localePrefix);
27
21
  function getAlternateEntry(url, locale) {
28
- url.pathname = utils$1.normalizeTrailingSlash(url.pathname);
22
+ url.pathname = normalizeTrailingSlash(url.pathname);
29
23
  if (request.nextUrl.basePath) {
30
24
  url = new URL(url);
31
- url.pathname = utils.applyBasePath(url.pathname, request.nextUrl.basePath);
25
+ url.pathname = applyBasePath(url.pathname, request.nextUrl.basePath);
32
26
  }
33
- return "<".concat(url.toString(), ">; rel=\"alternate\"; hreflang=\"").concat(locale, "\"");
27
+ return `<${url.toString()}>; rel="alternate"; hreflang="${locale}"`;
34
28
  }
35
29
  function getLocalizedPathname(pathname, locale) {
36
30
  if (localizedPathnames && typeof localizedPathnames === 'object') {
37
- return utils.formatTemplatePathname(pathname, localizedPathnames[resolvedLocale], localizedPathnames[locale]);
31
+ return formatTemplatePathname(pathname, localizedPathnames[resolvedLocale], localizedPathnames[locale]);
38
32
  } else {
39
33
  return pathname;
40
34
  }
41
35
  }
42
- const links = utils.getLocalePrefixes(routing.locales, routing.localePrefix, false).flatMap(_ref2 => {
43
- let [locale, prefix] = _ref2;
36
+ const links = getLocalePrefixes(routing.locales, routing.localePrefix, false).flatMap(([locale, prefix]) => {
44
37
  function prefixPathname(pathname) {
45
38
  if (pathname === '/') {
46
39
  return prefix;
@@ -50,7 +43,7 @@ function getAlternateLinksHeaderValue(_ref) {
50
43
  }
51
44
  let url;
52
45
  if (routing.domains) {
53
- const domainConfigs = routing.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur));
46
+ const domainConfigs = routing.domains.filter(cur => isLocaleSupportedOnDomain(locale, cur));
54
47
  return domainConfigs.map(domainConfig => {
55
48
  url = new URL(normalizedUrl);
56
49
  url.port = '';
@@ -90,4 +83,4 @@ function getAlternateLinksHeaderValue(_ref) {
90
83
  return links.join(', ');
91
84
  }
92
85
 
93
- exports.default = getAlternateLinksHeaderValue;
86
+ export { getAlternateLinksHeaderValue as default };
@@ -0,0 +1,155 @@
1
+ import { NextResponse } from 'next/server.js';
2
+ import { receiveRoutingConfig } from '../routing/config.js';
3
+ import { HEADER_LOCALE_NAME } from '../shared/constants.js';
4
+ import { matchesPathname, normalizeTrailingSlash, getLocalePrefix } from '../shared/utils.js';
5
+ import getAlternateLinksHeaderValue from './getAlternateLinksHeaderValue.js';
6
+ import resolveLocale from './resolveLocale.js';
7
+ import syncCookie from './syncCookie.js';
8
+ import { sanitizePathname, isLocaleSupportedOnDomain, getNormalizedPathname, getPathnameMatch, getInternalTemplate, formatTemplatePathname, formatPathname, getBestMatchingDomain, applyBasePath, getLocaleAsPrefix } from './utils.js';
9
+
10
+ function createMiddleware(routing) {
11
+ const resolvedRouting = receiveRoutingConfig(routing);
12
+ return function middleware(request) {
13
+ let unsafeExternalPathname;
14
+ try {
15
+ // Resolve potential foreign symbols (e.g. /ja/%E7%B4%84 → /ja/約))
16
+ unsafeExternalPathname = decodeURI(request.nextUrl.pathname);
17
+ } catch {
18
+ // In case an invalid pathname is encountered, forward
19
+ // it to Next.js which in turn responds with a 400
20
+ return NextResponse.next();
21
+ }
22
+
23
+ // Sanitize malicious URIs to prevent open redirect attacks due to
24
+ // decodeURI doesn't escape encoded backslashes ('%5C' & '%5c')
25
+ const externalPathname = sanitizePathname(unsafeExternalPathname);
26
+ const {
27
+ domain,
28
+ locale
29
+ } = resolveLocale(resolvedRouting, request.headers, request.cookies, externalPathname);
30
+ const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === resolvedRouting.defaultLocale;
31
+ const domainsConfig = resolvedRouting.domains?.filter(curDomain => isLocaleSupportedOnDomain(locale, curDomain)) || [];
32
+ const hasUnknownHost = resolvedRouting.domains != null && !domain;
33
+ function rewrite(url) {
34
+ const urlObj = new URL(url, request.url);
35
+ if (request.nextUrl.basePath) {
36
+ urlObj.pathname = applyBasePath(urlObj.pathname, request.nextUrl.basePath);
37
+ }
38
+ const headers = new Headers(request.headers);
39
+ headers.set(HEADER_LOCALE_NAME, locale);
40
+ return NextResponse.rewrite(urlObj, {
41
+ request: {
42
+ headers
43
+ }
44
+ });
45
+ }
46
+ function redirect(url, redirectDomain) {
47
+ const urlObj = new URL(url, request.url);
48
+ urlObj.pathname = normalizeTrailingSlash(urlObj.pathname);
49
+ if (domainsConfig.length > 0 && !redirectDomain && domain) {
50
+ const bestMatchingDomain = getBestMatchingDomain(domain, locale, domainsConfig);
51
+ if (bestMatchingDomain) {
52
+ redirectDomain = bestMatchingDomain.domain;
53
+ if (bestMatchingDomain.defaultLocale === locale && resolvedRouting.localePrefix.mode === 'as-needed') {
54
+ urlObj.pathname = getNormalizedPathname(urlObj.pathname, resolvedRouting.locales, resolvedRouting.localePrefix);
55
+ }
56
+ }
57
+ }
58
+ if (redirectDomain) {
59
+ urlObj.host = redirectDomain;
60
+ if (request.headers.get('x-forwarded-host')) {
61
+ urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
62
+ urlObj.port = request.headers.get('x-forwarded-port') ?? '';
63
+ }
64
+ }
65
+ if (request.nextUrl.basePath) {
66
+ urlObj.pathname = applyBasePath(urlObj.pathname, request.nextUrl.basePath);
67
+ }
68
+ return NextResponse.redirect(urlObj.toString());
69
+ }
70
+ const unprefixedExternalPathname = getNormalizedPathname(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
71
+ const pathnameMatch = getPathnameMatch(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
72
+ const hasLocalePrefix = pathnameMatch != null;
73
+ const isUnprefixedRouting = resolvedRouting.localePrefix.mode === 'never' || hasMatchedDefaultLocale && resolvedRouting.localePrefix.mode === 'as-needed';
74
+ let response;
75
+ let internalTemplateName;
76
+ let unprefixedInternalPathname = unprefixedExternalPathname;
77
+ const pathnames = resolvedRouting.pathnames;
78
+ if (pathnames) {
79
+ let resolvedTemplateLocale;
80
+ [resolvedTemplateLocale, internalTemplateName] = getInternalTemplate(pathnames, unprefixedExternalPathname, locale);
81
+ if (internalTemplateName) {
82
+ const pathnameConfig = pathnames[internalTemplateName];
83
+ const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[locale];
84
+ if (matchesPathname(localeTemplate, unprefixedExternalPathname)) {
85
+ unprefixedInternalPathname = formatTemplatePathname(unprefixedExternalPathname, localeTemplate, internalTemplateName);
86
+ } else {
87
+ let sourceTemplate;
88
+ if (resolvedTemplateLocale) {
89
+ // A localized pathname from another locale has matched
90
+ sourceTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[resolvedTemplateLocale];
91
+ } else {
92
+ // An internal pathname has matched that
93
+ // doesn't have a localized pathname
94
+ sourceTemplate = internalTemplateName;
95
+ }
96
+ const localePrefix = isUnprefixedRouting ? undefined : getLocalePrefix(locale, resolvedRouting.localePrefix);
97
+ const template = formatTemplatePathname(unprefixedExternalPathname, sourceTemplate, localeTemplate);
98
+ response = redirect(formatPathname(template, localePrefix, request.nextUrl.search));
99
+ }
100
+ }
101
+ }
102
+ if (!response) {
103
+ if (unprefixedInternalPathname === '/' && !hasLocalePrefix) {
104
+ if (isUnprefixedRouting) {
105
+ response = rewrite(formatPathname(unprefixedInternalPathname, getLocaleAsPrefix(locale), request.nextUrl.search));
106
+ } else {
107
+ response = redirect(formatPathname(unprefixedExternalPathname, getLocalePrefix(locale, resolvedRouting.localePrefix), request.nextUrl.search));
108
+ }
109
+ } else {
110
+ const internalHref = formatPathname(unprefixedInternalPathname, getLocaleAsPrefix(locale), request.nextUrl.search);
111
+ if (hasLocalePrefix) {
112
+ const externalHref = formatPathname(unprefixedExternalPathname, pathnameMatch.prefix, request.nextUrl.search);
113
+ if (resolvedRouting.localePrefix.mode === 'never') {
114
+ response = redirect(formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
115
+ } else if (pathnameMatch.exact) {
116
+ if (hasMatchedDefaultLocale && isUnprefixedRouting) {
117
+ response = redirect(formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
118
+ } else {
119
+ if (resolvedRouting.domains) {
120
+ const pathDomain = getBestMatchingDomain(domain, pathnameMatch.locale, domainsConfig);
121
+ if (domain?.domain !== pathDomain?.domain && !hasUnknownHost) {
122
+ response = redirect(externalHref, pathDomain?.domain);
123
+ } else {
124
+ response = rewrite(internalHref);
125
+ }
126
+ } else {
127
+ response = rewrite(internalHref);
128
+ }
129
+ }
130
+ } else {
131
+ response = redirect(externalHref);
132
+ }
133
+ } else {
134
+ if (isUnprefixedRouting) {
135
+ response = rewrite(internalHref);
136
+ } else {
137
+ response = redirect(formatPathname(unprefixedExternalPathname, getLocalePrefix(locale, resolvedRouting.localePrefix), request.nextUrl.search));
138
+ }
139
+ }
140
+ }
141
+ }
142
+ syncCookie(request, response, locale, resolvedRouting, domain);
143
+ if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
144
+ response.headers.set('Link', getAlternateLinksHeaderValue({
145
+ routing: resolvedRouting,
146
+ localizedPathnames: internalTemplateName != null && pathnames ? pathnames[internalTemplateName] : undefined,
147
+ request,
148
+ resolvedLocale: locale
149
+ }));
150
+ }
151
+ return response;
152
+ };
153
+ }
154
+
155
+ export { createMiddleware as default };
@@ -1,17 +1,9 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var intlLocalematcher = require('@formatjs/intl-localematcher');
6
- var Negotiator = require('negotiator');
7
- var utils = require('./utils.js');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var Negotiator__default = /*#__PURE__*/_interopDefault(Negotiator);
1
+ import { match } from '@formatjs/intl-localematcher';
2
+ import Negotiator from 'negotiator';
3
+ import { getPathnameMatch, isLocaleSupportedOnDomain, getHost } from './utils.js';
12
4
 
13
5
  function findDomainFromHost(requestHeaders, domains) {
14
- const host = utils.getHost(requestHeaders);
6
+ const host = getHost(requestHeaders);
15
7
  if (host) {
16
8
  return domains.find(cur => cur.domain === host);
17
9
  }
@@ -23,23 +15,22 @@ function orderLocales(locales) {
23
15
  }
24
16
  function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
25
17
  let locale;
26
- const languages = new Negotiator__default.default({
18
+ const languages = new Negotiator({
27
19
  headers: {
28
20
  'accept-language': requestHeaders.get('accept-language') || undefined
29
21
  }
30
22
  }).languages();
31
23
  try {
32
24
  const orderedLocales = orderLocales(locales);
33
- locale = intlLocalematcher.match(languages, orderedLocales, defaultLocale);
34
- } catch (_unused) {
25
+ locale = match(languages, orderedLocales, defaultLocale);
26
+ } catch {
35
27
  // Invalid language
36
28
  }
37
29
  return locale;
38
30
  }
39
31
  function getLocaleFromCookie(routing, requestCookies) {
40
32
  if (routing.localeCookie && requestCookies.has(routing.localeCookie.name)) {
41
- var _requestCookies$get;
42
- const value = (_requestCookies$get = requestCookies.get(routing.localeCookie.name)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
33
+ const value = requestCookies.get(routing.localeCookie.name)?.value;
43
34
  if (value && routing.locales.includes(value)) {
44
35
  return value;
45
36
  }
@@ -50,8 +41,7 @@ function resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathna
50
41
 
51
42
  // Prio 1: Use route prefix
52
43
  if (pathname) {
53
- var _getPathnameMatch;
54
- locale = (_getPathnameMatch = utils.getPathnameMatch(pathname, routing.locales, routing.localePrefix)) === null || _getPathnameMatch === void 0 ? void 0 : _getPathnameMatch.locale;
44
+ locale = getPathnameMatch(pathname, routing.locales, routing.localePrefix)?.locale;
55
45
  }
56
46
 
57
47
  // Prio 2: Use existing cookie
@@ -82,10 +72,9 @@ function resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathna
82
72
 
83
73
  // Prio 1: Use route prefix
84
74
  if (pathname) {
85
- var _getPathnameMatch2;
86
- const prefixLocale = (_getPathnameMatch2 = utils.getPathnameMatch(pathname, routing.locales, routing.localePrefix)) === null || _getPathnameMatch2 === void 0 ? void 0 : _getPathnameMatch2.locale;
75
+ const prefixLocale = getPathnameMatch(pathname, routing.locales, routing.localePrefix)?.locale;
87
76
  if (prefixLocale) {
88
- if (utils.isLocaleSupportedOnDomain(prefixLocale, domain)) {
77
+ if (isLocaleSupportedOnDomain(prefixLocale, domain)) {
89
78
  locale = prefixLocale;
90
79
  } else {
91
80
  // Causes a redirect to a domain that supports the locale
@@ -101,7 +90,7 @@ function resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathna
101
90
  if (!locale && routing.localeDetection) {
102
91
  const cookieLocale = getLocaleFromCookie(routing, requestCookies);
103
92
  if (cookieLocale) {
104
- if (utils.isLocaleSupportedOnDomain(cookieLocale, domain)) {
93
+ if (isLocaleSupportedOnDomain(cookieLocale, domain)) {
105
94
  locale = cookieLocale;
106
95
  }
107
96
  }
@@ -134,5 +123,4 @@ function resolveLocale(routing, requestHeaders, requestCookies, pathname) {
134
123
  }
135
124
  }
136
125
 
137
- exports.default = resolveLocale;
138
- exports.getAcceptLanguageLocale = getAcceptLanguageLocale;
126
+ export { resolveLocale as default, getAcceptLanguageLocale };
@@ -0,0 +1,20 @@
1
+ import { getAcceptLanguageLocale } from './resolveLocale.js';
2
+
3
+ function syncCookie(request, response, locale, routing, domain) {
4
+ if (!routing.localeCookie) return;
5
+ const {
6
+ name,
7
+ ...rest
8
+ } = routing.localeCookie;
9
+ const acceptLanguageLocale = getAcceptLanguageLocale(request.headers, domain?.locales || routing.locales, routing.defaultLocale);
10
+ const hasLocaleCookie = request.cookies.has(name);
11
+ const hasOutdatedCookie = hasLocaleCookie && request.cookies.get(name)?.value !== locale;
12
+ if (hasLocaleCookie ? hasOutdatedCookie : acceptLanguageLocale !== locale) {
13
+ response.cookies.set(name, locale, {
14
+ path: request.nextUrl.basePath || undefined,
15
+ ...rest
16
+ });
17
+ }
18
+ }
19
+
20
+ export { syncCookie as default };