next-intl 2.22.1 → 2.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +1 -3
  2. package/config.d.ts +3 -0
  3. package/dist/config.js +7 -0
  4. package/dist/development/_virtual/_rollupPluginBabelHelpers.js +20 -0
  5. package/dist/development/config.js +9 -0
  6. package/dist/development/index.js +21 -0
  7. package/dist/development/index.react-server.js +28 -0
  8. package/dist/development/middleware/getAlternateLinksHeaderValue.js +81 -0
  9. package/dist/development/middleware/middleware.js +146 -0
  10. package/dist/development/middleware/resolveLocale.js +110 -0
  11. package/dist/development/middleware/utils.js +150 -0
  12. package/dist/development/middleware.js +9 -0
  13. package/dist/development/navigation/BaseLink.js +52 -0
  14. package/dist/development/navigation/baseRedirect.js +22 -0
  15. package/dist/development/navigation/createLocalizedPathnamesNavigation.js +135 -0
  16. package/dist/development/navigation/createSharedPathnamesNavigation.js +19 -0
  17. package/dist/development/navigation/react-server/BaseLink.js +25 -0
  18. package/dist/development/navigation/react-server/baseRedirect.js +16 -0
  19. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +77 -0
  20. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +22 -0
  21. package/dist/development/navigation/useBasePathname.js +37 -0
  22. package/dist/development/navigation/useBaseRouter.js +76 -0
  23. package/dist/development/navigation/utils.js +108 -0
  24. package/dist/development/navigation.js +11 -0
  25. package/dist/development/navigation.react-server.js +11 -0
  26. package/dist/development/plugin.js +48 -0
  27. package/dist/development/react-client/index.js +38 -0
  28. package/dist/development/react-client/useLocale.js +24 -0
  29. package/dist/development/react-server/NextIntlClientProvider.js +33 -0
  30. package/dist/development/react-server/getBaseTranslator.js +21 -0
  31. package/dist/development/react-server/useFormatter.js +19 -0
  32. package/dist/development/react-server/useHook.js +21 -0
  33. package/dist/development/react-server/useLocale.js +14 -0
  34. package/dist/development/react-server/useMessages.js +19 -0
  35. package/dist/development/react-server/useNow.js +23 -0
  36. package/dist/development/react-server/useTimeZone.js +19 -0
  37. package/dist/development/react-server/useTranslations.js +19 -0
  38. package/dist/development/server/RequestLocale.js +43 -0
  39. package/dist/development/server/createRequestConfig.js +17 -0
  40. package/dist/development/server/getConfig.js +43 -0
  41. package/dist/development/server/getFormatter.js +26 -0
  42. package/dist/development/server/getLocale.js +11 -0
  43. package/dist/development/server/getMessages.js +21 -0
  44. package/dist/development/server/getNow.js +18 -0
  45. package/dist/development/server/getRequestConfig.js +12 -0
  46. package/dist/development/server/getTimeZone.js +18 -0
  47. package/dist/development/server/getTranslations.js +31 -0
  48. package/dist/development/server/resolveLocaleArg.js +15 -0
  49. package/dist/development/server.js +23 -0
  50. package/dist/development/shared/BaseLinkWithLocale.js +58 -0
  51. package/dist/development/shared/NextIntlClientProvider.js +30 -0
  52. package/dist/development/shared/constants.js +17 -0
  53. package/dist/development/shared/redirectWithLocale.js +16 -0
  54. package/dist/development/shared/utils.js +87 -0
  55. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +1 -0
  56. package/dist/esm/config.js +1 -0
  57. package/dist/esm/index.js +1 -0
  58. package/dist/esm/index.react-server.js +1 -0
  59. package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -0
  60. package/dist/esm/middleware/middleware.js +1 -0
  61. package/dist/esm/middleware/resolveLocale.js +1 -0
  62. package/dist/esm/middleware/utils.js +1 -0
  63. package/dist/esm/middleware.js +1 -0
  64. package/dist/esm/navigation/BaseLink.js +1 -0
  65. package/dist/esm/navigation/baseRedirect.js +1 -0
  66. package/dist/esm/navigation/createLocalizedPathnamesNavigation.js +1 -0
  67. package/dist/esm/navigation/createSharedPathnamesNavigation.js +1 -0
  68. package/dist/esm/navigation/react-server/BaseLink.js +1 -0
  69. package/dist/esm/navigation/react-server/baseRedirect.js +1 -0
  70. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
  71. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -0
  72. package/dist/esm/navigation/useBasePathname.js +2 -0
  73. package/dist/esm/navigation/useBaseRouter.js +1 -0
  74. package/dist/esm/navigation/utils.js +1 -0
  75. package/dist/esm/navigation.js +1 -0
  76. package/dist/esm/navigation.react-server.js +1 -0
  77. package/dist/esm/plugin.js +1 -0
  78. package/dist/esm/react-client/index.js +1 -0
  79. package/dist/esm/react-client/useLocale.js +1 -0
  80. package/dist/esm/react-server/NextIntlClientProvider.js +1 -0
  81. package/dist/esm/react-server/getBaseTranslator.js +1 -0
  82. package/dist/esm/react-server/useFormatter.js +1 -0
  83. package/dist/esm/react-server/useHook.js +1 -0
  84. package/dist/esm/react-server/useLocale.js +1 -0
  85. package/dist/esm/react-server/useMessages.js +1 -0
  86. package/dist/esm/react-server/useNow.js +1 -0
  87. package/dist/esm/react-server/useTimeZone.js +1 -0
  88. package/dist/esm/react-server/useTranslations.js +1 -0
  89. package/dist/esm/server/RequestLocale.js +1 -0
  90. package/dist/esm/server/createRequestConfig.js +1 -0
  91. package/dist/esm/server/getConfig.js +1 -0
  92. package/dist/esm/server/getFormatter.js +1 -0
  93. package/dist/esm/server/getLocale.js +1 -0
  94. package/dist/esm/server/getMessages.js +1 -0
  95. package/dist/esm/server/getNow.js +1 -0
  96. package/dist/esm/server/getRequestConfig.js +1 -0
  97. package/dist/esm/server/getTimeZone.js +1 -0
  98. package/dist/esm/server/getTranslations.js +1 -0
  99. package/dist/esm/server/resolveLocaleArg.js +1 -0
  100. package/dist/esm/server.js +1 -0
  101. package/dist/esm/shared/BaseLinkWithLocale.js +2 -0
  102. package/dist/esm/shared/NextIntlClientProvider.js +2 -0
  103. package/dist/esm/shared/constants.js +1 -0
  104. package/dist/esm/shared/redirectWithLocale.js +1 -0
  105. package/dist/esm/shared/utils.js +1 -0
  106. package/dist/index.js +3 -4
  107. package/dist/index.react-server.js +7 -0
  108. package/dist/middleware.js +7 -0
  109. package/dist/navigation.js +7 -0
  110. package/dist/navigation.react-server.js +7 -0
  111. package/dist/plugin.js +7 -0
  112. package/dist/production/_virtual/_rollupPluginBabelHelpers.js +1 -0
  113. package/dist/production/config.js +1 -0
  114. package/dist/production/index.js +1 -0
  115. package/dist/production/index.react-server.js +1 -0
  116. package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -0
  117. package/dist/production/middleware/middleware.js +1 -0
  118. package/dist/production/middleware/resolveLocale.js +1 -0
  119. package/dist/production/middleware/utils.js +1 -0
  120. package/dist/production/middleware.js +1 -0
  121. package/dist/production/navigation/BaseLink.js +1 -0
  122. package/dist/production/navigation/baseRedirect.js +1 -0
  123. package/dist/production/navigation/createLocalizedPathnamesNavigation.js +1 -0
  124. package/dist/production/navigation/createSharedPathnamesNavigation.js +1 -0
  125. package/dist/production/navigation/react-server/BaseLink.js +1 -0
  126. package/dist/production/navigation/react-server/baseRedirect.js +1 -0
  127. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
  128. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -0
  129. package/dist/production/navigation/useBasePathname.js +2 -0
  130. package/dist/production/navigation/useBaseRouter.js +1 -0
  131. package/dist/production/navigation/utils.js +1 -0
  132. package/dist/production/navigation.js +1 -0
  133. package/dist/production/navigation.react-server.js +1 -0
  134. package/dist/production/plugin.js +1 -0
  135. package/dist/production/react-client/index.js +1 -0
  136. package/dist/production/react-client/useLocale.js +1 -0
  137. package/dist/production/react-server/NextIntlClientProvider.js +1 -0
  138. package/dist/production/react-server/getBaseTranslator.js +1 -0
  139. package/dist/production/react-server/useFormatter.js +1 -0
  140. package/dist/production/react-server/useHook.js +1 -0
  141. package/dist/production/react-server/useLocale.js +1 -0
  142. package/dist/production/react-server/useMessages.js +1 -0
  143. package/dist/production/react-server/useNow.js +1 -0
  144. package/dist/production/react-server/useTimeZone.js +1 -0
  145. package/dist/production/react-server/useTranslations.js +1 -0
  146. package/dist/production/server/RequestLocale.js +1 -0
  147. package/dist/production/server/createRequestConfig.js +1 -0
  148. package/dist/production/server/getConfig.js +1 -0
  149. package/dist/production/server/getFormatter.js +1 -0
  150. package/dist/production/server/getLocale.js +1 -0
  151. package/dist/production/server/getMessages.js +1 -0
  152. package/dist/production/server/getNow.js +1 -0
  153. package/dist/production/server/getRequestConfig.js +1 -0
  154. package/dist/production/server/getTimeZone.js +1 -0
  155. package/dist/production/server/getTranslations.js +1 -0
  156. package/dist/production/server/resolveLocaleArg.js +1 -0
  157. package/dist/production/server.js +1 -0
  158. package/dist/production/shared/BaseLinkWithLocale.js +2 -0
  159. package/dist/production/shared/NextIntlClientProvider.js +2 -0
  160. package/dist/production/shared/constants.js +1 -0
  161. package/dist/production/shared/redirectWithLocale.js +1 -0
  162. package/dist/production/shared/utils.js +1 -0
  163. package/dist/server.js +7 -0
  164. package/dist/types/src/config.d.ts +1 -0
  165. package/dist/types/src/index.react-server.d.ts +1 -0
  166. package/dist/{src → types/src}/middleware/NextIntlMiddlewareConfig.d.ts +14 -10
  167. package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +12 -0
  168. package/dist/types/src/middleware/middleware.d.ts +4 -0
  169. package/dist/types/src/middleware/resolveLocale.d.ts +7 -0
  170. package/dist/types/src/middleware/utils.d.ts +17 -0
  171. package/dist/types/src/middleware.d.ts +1 -0
  172. package/dist/types/src/navigation/BaseLink.d.ts +63 -0
  173. package/dist/types/src/navigation/StrictParams.d.ts +8 -0
  174. package/dist/types/src/navigation/baseRedirect.d.ts +3 -0
  175. package/dist/types/src/navigation/createLocalizedPathnamesNavigation.d.ts +78 -0
  176. package/dist/types/src/navigation/createSharedPathnamesNavigation.d.ts +13 -0
  177. package/dist/types/src/navigation/index.d.ts +3 -0
  178. package/dist/types/src/navigation/react-server/BaseLink.d.ts +8 -0
  179. package/dist/types/src/navigation/react-server/baseRedirect.d.ts +3 -0
  180. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +60 -0
  181. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +44 -0
  182. package/dist/types/src/navigation/react-server/index.d.ts +3 -0
  183. package/dist/{src/client/usePathname.d.ts → types/src/navigation/useBasePathname.d.ts} +1 -1
  184. package/dist/{client/useRouter.d.ts → types/src/navigation/useBaseRouter.d.ts} +32 -31
  185. package/dist/types/src/navigation/utils.d.ts +51 -0
  186. package/dist/types/src/navigation.d.ts +1 -0
  187. package/dist/types/src/navigation.react-server.d.ts +1 -0
  188. package/dist/types/src/plugin.d.ts +1 -0
  189. package/dist/{react-client → types/src/react-client}/index.d.ts +15 -12
  190. package/dist/types/src/react-client/useLocale.d.ts +1 -0
  191. package/dist/types/src/react-server/NextIntlClientProvider.d.ts +5 -0
  192. package/dist/types/src/react-server/getBaseTranslator.d.ts +42 -0
  193. package/dist/types/src/react-server/index.d.ts +15 -0
  194. package/dist/types/src/react-server/useFormatter.d.ts +2 -0
  195. package/dist/types/src/react-server/useHook.d.ts +1 -0
  196. package/dist/types/src/react-server/useLocale.d.ts +2 -0
  197. package/dist/types/src/react-server/useMessages.d.ts +2 -0
  198. package/dist/types/src/react-server/useNow.d.ts +2 -0
  199. package/dist/types/src/react-server/useTimeZone.d.ts +2 -0
  200. package/dist/types/src/react-server/useTranslations.d.ts +2 -0
  201. package/dist/types/src/server/RequestLocale.d.ts +2 -0
  202. package/dist/types/src/server/createRequestConfig.d.ts +4 -0
  203. package/dist/types/src/server/getConfig.d.ts +23 -0
  204. package/dist/types/src/server/getFormatter.d.ts +14 -0
  205. package/dist/types/src/server/getLocale.d.ts +1 -0
  206. package/dist/types/src/server/getMessages.d.ts +3 -0
  207. package/dist/types/src/server/getNow.d.ts +3 -0
  208. package/dist/types/src/server/getRequestConfig.d.ts +10 -0
  209. package/dist/types/src/server/getTimeZone.d.ts +3 -0
  210. package/dist/types/src/server/getTranslations.d.ts +83 -0
  211. package/dist/types/src/server/index.d.ts +11 -0
  212. package/dist/types/src/server/resolveLocaleArg.d.ts +3 -0
  213. package/dist/types/src/server.d.ts +1 -0
  214. package/dist/types/src/shared/NextIntlClientProvider.d.ts +8 -0
  215. package/dist/{shared → types/src/shared}/constants.d.ts +3 -2
  216. package/dist/types/src/shared/redirectWithLocale.d.ts +3 -0
  217. package/dist/types/src/shared/types.d.ts +6 -0
  218. package/dist/{src → types/src}/shared/utils.d.ts +6 -0
  219. package/dist/types/test/middleware/getAlternateLinksHeaderValue.test.d.ts +1 -0
  220. package/dist/types/test/middleware/middleware.test.d.ts +1 -0
  221. package/dist/types/test/middleware/utils.test.d.ts +1 -0
  222. package/dist/types/test/navigation/BaseLink.test.d.ts +1 -0
  223. package/dist/types/test/navigation/createLocalizedPathnamesNavigation.test.d.ts +1 -0
  224. package/dist/types/test/navigation/createSharedPathnamesNavigation.test.d.ts +1 -0
  225. package/dist/types/test/navigation/useBasePathname.test.d.ts +1 -0
  226. package/dist/types/test/navigation/useBaseRouter.test.d.ts +1 -0
  227. package/dist/types/test/navigation/utils.test.d.ts +1 -0
  228. package/dist/types/test/react-client/useFormatter.test.d.ts +1 -0
  229. package/dist/types/test/react-client/useLocale.test.d.ts +1 -0
  230. package/dist/types/test/react-client/useNow.test.d.ts +1 -0
  231. package/dist/types/test/react-client/useTimeZone.test.d.ts +1 -0
  232. package/dist/types/test/react-client/useTranslations.test.d.ts +1 -0
  233. package/dist/types/test/server/index.test.d.ts +1 -0
  234. package/dist/types/test/setup.d.ts +1 -0
  235. package/dist/types/test/shared/NextIntlClientProvider.test.d.ts +1 -0
  236. package/dist/types/test/shared/utils.test.d.ts +1 -0
  237. package/middleware.d.ts +1 -1
  238. package/navigation.d.ts +1 -0
  239. package/package.json +44 -33
  240. package/plugin.d.ts +6 -0
  241. package/server.d.ts +1 -1
  242. package/client.d.ts +0 -1
  243. package/dist/_virtual/next-intl.esm.js +0 -29
  244. package/dist/_virtual/next-intl.esm.js.map +0 -1
  245. package/dist/client/NextIntlClientProvider.d.ts +0 -4
  246. package/dist/client/index.d.ts +0 -6
  247. package/dist/client/useClientLocale.d.ts +0 -1
  248. package/dist/client/usePathname.d.ts +0 -14
  249. package/dist/index.d.ts +0 -8
  250. package/dist/link/Link.d.ts +0 -27
  251. package/dist/link/index.d.ts +0 -1
  252. package/dist/link/react-server/Link.d.ts +0 -1
  253. package/dist/link/react-server/index.d.ts +0 -1
  254. package/dist/middleware/NextIntlMiddlewareConfig.d.ts +0 -28
  255. package/dist/middleware/getAlternateLinksHeaderValue.d.ts +0 -6
  256. package/dist/middleware/index.d.ts +0 -4
  257. package/dist/middleware/middleware.d.ts +0 -3
  258. package/dist/middleware/resolveLocale.d.ts +0 -6
  259. package/dist/middleware/utils.d.ts +0 -5
  260. package/dist/next-intl.cjs.development.js +0 -82
  261. package/dist/next-intl.cjs.development.js.map +0 -1
  262. package/dist/next-intl.cjs.production.min.js +0 -2
  263. package/dist/next-intl.cjs.production.min.js.map +0 -1
  264. package/dist/next-intl.esm.js +0 -3
  265. package/dist/next-intl.esm.js.map +0 -1
  266. package/dist/react-server/index.d.ts +0 -17
  267. package/dist/server/index.d.ts +0 -6
  268. package/dist/shared/BaseLink.d.ts +0 -7
  269. package/dist/shared/NextIntlClientProvider.d.ts +0 -9
  270. package/dist/shared/next-intl.esm.js +0 -41
  271. package/dist/shared/next-intl.esm.js.map +0 -1
  272. package/dist/shared/utils.d.ts +0 -15
  273. package/dist/src/client/NextIntlClientProvider.d.ts +0 -4
  274. package/dist/src/client/NextIntlClientProvider.js +0 -16
  275. package/dist/src/client/NextIntlClientProvider.js.map +0 -1
  276. package/dist/src/client/index.d.ts +0 -6
  277. package/dist/src/client/index.js +0 -8
  278. package/dist/src/client/index.js.map +0 -1
  279. package/dist/src/client/useClientLocale.d.ts +0 -1
  280. package/dist/src/client/useClientLocale.js +0 -18
  281. package/dist/src/client/useClientLocale.js.map +0 -1
  282. package/dist/src/client/usePathname.js +0 -34
  283. package/dist/src/client/usePathname.js.map +0 -1
  284. package/dist/src/client/useRouter.d.ts +0 -31
  285. package/dist/src/client/useRouter.js +0 -61
  286. package/dist/src/client/useRouter.js.map +0 -1
  287. package/dist/src/index.js +0 -9
  288. package/dist/src/index.js.map +0 -1
  289. package/dist/src/link/Link.d.ts +0 -27
  290. package/dist/src/link/Link.js +0 -29
  291. package/dist/src/link/Link.js.map +0 -1
  292. package/dist/src/link/index.d.ts +0 -1
  293. package/dist/src/link/index.js +0 -2
  294. package/dist/src/link/index.js.map +0 -1
  295. package/dist/src/link/react-server/Link.d.ts +0 -1
  296. package/dist/src/link/react-server/Link.js +0 -6
  297. package/dist/src/link/react-server/Link.js.map +0 -1
  298. package/dist/src/link/react-server/index.d.ts +0 -1
  299. package/dist/src/link/react-server/index.js +0 -2
  300. package/dist/src/link/react-server/index.js.map +0 -1
  301. package/dist/src/middleware/NextIntlMiddlewareConfig.js +0 -2
  302. package/dist/src/middleware/NextIntlMiddlewareConfig.js.map +0 -1
  303. package/dist/src/middleware/getAlternateLinksHeaderValue.d.ts +0 -6
  304. package/dist/src/middleware/getAlternateLinksHeaderValue.js +0 -71
  305. package/dist/src/middleware/getAlternateLinksHeaderValue.js.map +0 -1
  306. package/dist/src/middleware/index.js +0 -5
  307. package/dist/src/middleware/index.js.map +0 -1
  308. package/dist/src/middleware/middleware.d.ts +0 -3
  309. package/dist/src/middleware/middleware.js +0 -149
  310. package/dist/src/middleware/middleware.js.map +0 -1
  311. package/dist/src/middleware/resolveLocale.d.ts +0 -6
  312. package/dist/src/middleware/resolveLocale.js +0 -88
  313. package/dist/src/middleware/resolveLocale.js.map +0 -1
  314. package/dist/src/middleware/utils.d.ts +0 -5
  315. package/dist/src/middleware/utils.js +0 -37
  316. package/dist/src/middleware/utils.js.map +0 -1
  317. package/dist/src/react-client/index.d.ts +0 -12
  318. package/dist/src/react-client/index.js +0 -14
  319. package/dist/src/react-client/index.js.map +0 -1
  320. package/dist/src/react-server/index.d.ts +0 -17
  321. package/dist/src/react-server/index.js +0 -25
  322. package/dist/src/react-server/index.js.map +0 -1
  323. package/dist/src/server/index.d.ts +0 -6
  324. package/dist/src/server/index.js +0 -30
  325. package/dist/src/server/index.js.map +0 -1
  326. package/dist/src/shared/BaseLink.js +0 -38
  327. package/dist/src/shared/BaseLink.js.map +0 -1
  328. package/dist/src/shared/NextIntlClientProvider.d.ts +0 -9
  329. package/dist/src/shared/NextIntlClientProvider.js +0 -33
  330. package/dist/src/shared/NextIntlClientProvider.js.map +0 -1
  331. package/dist/src/shared/constants.d.ts +0 -2
  332. package/dist/src/shared/constants.js +0 -6
  333. package/dist/src/shared/constants.js.map +0 -1
  334. package/dist/src/shared/utils.js +0 -53
  335. package/dist/src/shared/utils.js.map +0 -1
  336. package/link.d.ts +0 -3
  337. package/src/client/NextIntlClientProvider.tsx +0 -18
  338. package/src/client/index.tsx +0 -9
  339. package/src/client/useClientLocale.tsx +0 -20
  340. package/src/client/usePathname.tsx +0 -40
  341. package/src/client/useRouter.tsx +0 -92
  342. package/src/index.tsx +0 -9
  343. package/src/link/Link.tsx +0 -34
  344. package/src/link/index.tsx +0 -1
  345. package/src/link/react-server/Link.tsx +0 -6
  346. package/src/link/react-server/index.tsx +0 -1
  347. package/src/middleware/NextIntlMiddlewareConfig.tsx +0 -42
  348. package/src/middleware/getAlternateLinksHeaderValue.tsx +0 -97
  349. package/src/middleware/index.tsx +0 -5
  350. package/src/middleware/middleware.tsx +0 -206
  351. package/src/middleware/resolveLocale.tsx +0 -151
  352. package/src/middleware/utils.tsx +0 -61
  353. package/src/react-client/index.tsx +0 -15
  354. package/src/react-server/index.tsx +0 -29
  355. package/src/server/index.tsx +0 -34
  356. package/src/shared/BaseLink.tsx +0 -57
  357. package/src/shared/NextIntlClientProvider.tsx +0 -54
  358. package/src/shared/constants.tsx +0 -6
  359. package/src/shared/utils.tsx +0 -91
  360. /package/dist/{src → types/src}/index.d.ts +0 -0
  361. /package/dist/{src → types/src}/middleware/index.d.ts +0 -0
  362. /package/dist/{src/shared/BaseLink.d.ts → types/src/shared/BaseLinkWithLocale.d.ts} +0 -0
package/README.md CHANGED
@@ -11,8 +11,6 @@
11
11
 
12
12
  > Internationalization (i18n) for Next.js that gets out of your way.
13
13
 
14
- ![Gzipped size](https://badgen.net/bundlephobia/minzip/next-intl) ![Tree shaking supported](https://badgen.net/bundlephobia/tree-shaking/next-intl) [<img src="https://img.shields.io/npm/dw/next-intl.svg" />](https://www.npmjs.com/package/next-intl)
15
-
16
14
  <hr />
17
15
 
18
16
  📣 [Support for Next.js 13 and the App Router has arrived →](https://next-intl-docs.vercel.app/docs/next-13)
@@ -51,7 +49,7 @@ export default function UserProfile({user}) {
51
49
  }
52
50
  ```
53
51
 
54
- ```json
52
+ ```js
55
53
  // en.json
56
54
  {
57
55
  "UserProfile": {
package/config.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import config from './dist/types/src/config';
2
+
3
+ export = config;
package/dist/config.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./production/config.js');
5
+ } else {
6
+ module.exports = require('./development/config.js');
7
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _extends() {
6
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
7
+ for (var i = 1; i < arguments.length; i++) {
8
+ var source = arguments[i];
9
+ for (var key in source) {
10
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
11
+ target[key] = source[key];
12
+ }
13
+ }
14
+ }
15
+ return target;
16
+ };
17
+ return _extends.apply(this, arguments);
18
+ }
19
+
20
+ exports.extends = _extends;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function getConfig() {
6
+ 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-server-components");
7
+ }
8
+
9
+ exports.default = getConfig;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var index = require('./react-client/index.js');
6
+ var useLocale = require('./react-client/useLocale.js');
7
+ var NextIntlClientProvider = require('./shared/NextIntlClientProvider.js');
8
+ var useIntl = require('use-intl');
9
+
10
+
11
+
12
+ exports.useFormatter = index.useFormatter;
13
+ exports.useTranslations = index.useTranslations;
14
+ exports.useLocale = useLocale.default;
15
+ exports.NextIntlClientProvider = NextIntlClientProvider.default;
16
+ Object.keys(useIntl).forEach(function (k) {
17
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
18
+ enumerable: true,
19
+ get: function () { return useIntl[k]; }
20
+ });
21
+ });
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useLocale = require('./react-server/useLocale.js');
6
+ var useTranslations = require('./react-server/useTranslations.js');
7
+ var useFormatter = require('./react-server/useFormatter.js');
8
+ var useNow = require('./react-server/useNow.js');
9
+ var useTimeZone = require('./react-server/useTimeZone.js');
10
+ var useMessages = require('./react-server/useMessages.js');
11
+ var NextIntlClientProvider = require('./react-server/NextIntlClientProvider.js');
12
+ var core = require('use-intl/core');
13
+
14
+
15
+
16
+ exports.useLocale = useLocale.default;
17
+ exports.useTranslations = useTranslations.default;
18
+ exports.useFormatter = useFormatter.default;
19
+ exports.useNow = useNow.default;
20
+ exports.useTimeZone = useTimeZone.default;
21
+ exports.useMessages = useMessages.default;
22
+ exports.NextIntlClientProvider = NextIntlClientProvider.default;
23
+ Object.keys(core).forEach(function (k) {
24
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
25
+ enumerable: true,
26
+ get: function () { return core[k]; }
27
+ });
28
+ });
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('./utils.js');
6
+
7
+ function getAlternateEntry(url, locale) {
8
+ return "<".concat(url, ">; rel=\"alternate\"; hreflang=\"").concat(locale, "\"");
9
+ }
10
+
11
+ /**
12
+ * See https://developers.google.com/search/docs/specialty/international/localized-versions
13
+ */
14
+ function getAlternateLinksHeaderValue(_ref) {
15
+ var _request$headers$get;
16
+ let {
17
+ config,
18
+ localizedPathnames,
19
+ request,
20
+ resolvedLocale
21
+ } = _ref;
22
+ const normalizedUrl = request.nextUrl.clone();
23
+ const host = utils.getHost(request.headers);
24
+ if (host) {
25
+ normalizedUrl.port = '';
26
+ normalizedUrl.host = host;
27
+ }
28
+ normalizedUrl.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : normalizedUrl.protocol;
29
+ normalizedUrl.pathname = utils.getNormalizedPathname(normalizedUrl.pathname, config.locales);
30
+ function getLocalizedPathname(pathname, locale) {
31
+ if (localizedPathnames && typeof localizedPathnames === 'object') {
32
+ return utils.formatTemplatePathname(pathname, localizedPathnames[resolvedLocale], localizedPathnames[locale]);
33
+ } else {
34
+ return pathname;
35
+ }
36
+ }
37
+ const links = config.locales.flatMap(locale => {
38
+ function prefixPathname(pathname) {
39
+ if (pathname === '/') {
40
+ return "/".concat(locale);
41
+ } else {
42
+ return "/".concat(locale).concat(pathname);
43
+ }
44
+ }
45
+ let url;
46
+ if (config.domains) {
47
+ const domainConfigs = config.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur)) || [];
48
+ return domainConfigs.map(domainConfig => {
49
+ url = new URL(normalizedUrl);
50
+ url.port = '';
51
+ url.host = domainConfig.domain;
52
+ url.pathname = getLocalizedPathname(url.pathname, locale);
53
+ if (locale !== domainConfig.defaultLocale || config.localePrefix === 'always') {
54
+ url.pathname = prefixPathname(url.pathname);
55
+ }
56
+ return getAlternateEntry(url.toString(), locale);
57
+ });
58
+ } else {
59
+ let pathname;
60
+ if (localizedPathnames && typeof localizedPathnames === 'object') {
61
+ pathname = getLocalizedPathname(normalizedUrl.pathname, locale);
62
+ } else {
63
+ pathname = normalizedUrl.pathname;
64
+ }
65
+ if (locale !== config.defaultLocale || config.localePrefix === 'always') {
66
+ pathname = prefixPathname(pathname);
67
+ }
68
+ url = new URL(pathname, normalizedUrl);
69
+ }
70
+ return getAlternateEntry(url.toString(), locale);
71
+ });
72
+
73
+ // Add x-default entry
74
+ if (!config.domains) {
75
+ const url = new URL(getLocalizedPathname(normalizedUrl.pathname, config.defaultLocale), normalizedUrl);
76
+ links.push(getAlternateEntry(url.toString(), 'x-default'));
77
+ }
78
+ return links.join(', ');
79
+ }
80
+
81
+ exports.default = getAlternateLinksHeaderValue;
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var server = require('next/server');
6
+ var constants = require('../shared/constants.js');
7
+ var utils$1 = require('../shared/utils.js');
8
+ var getAlternateLinksHeaderValue = require('./getAlternateLinksHeaderValue.js');
9
+ var resolveLocale = require('./resolveLocale.js');
10
+ var utils = require('./utils.js');
11
+
12
+ const ROOT_URL = '/';
13
+ function receiveConfig(config) {
14
+ var _config$alternateLink, _config$localePrefix, _config$localeDetecti;
15
+ const result = {
16
+ ...config,
17
+ alternateLinks: (_config$alternateLink = config.alternateLinks) !== null && _config$alternateLink !== void 0 ? _config$alternateLink : true,
18
+ localePrefix: (_config$localePrefix = config.localePrefix) !== null && _config$localePrefix !== void 0 ? _config$localePrefix : 'always',
19
+ localeDetection: (_config$localeDetecti = config.localeDetection) !== null && _config$localeDetecti !== void 0 ? _config$localeDetecti : true
20
+ };
21
+ return result;
22
+ }
23
+ function createMiddleware(config) {
24
+ const configWithDefaults = receiveConfig(config);
25
+ return function middleware(request) {
26
+ var _request$cookies$get, _configWithDefaults$d;
27
+ const {
28
+ domain,
29
+ locale
30
+ } = resolveLocale.default(configWithDefaults, request.headers, request.cookies, request.nextUrl.pathname);
31
+ const hasOutdatedCookie = ((_request$cookies$get = request.cookies.get(constants.COOKIE_LOCALE_NAME)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
32
+ const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === configWithDefaults.defaultLocale;
33
+ const domainConfigs = ((_configWithDefaults$d = configWithDefaults.domains) === null || _configWithDefaults$d === void 0 ? void 0 : _configWithDefaults$d.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
34
+ const hasUnknownHost = configWithDefaults.domains != null && !domain;
35
+ function getResponseInit() {
36
+ const headers = new Headers(request.headers);
37
+ headers.set(constants.HEADER_LOCALE_NAME, locale);
38
+ return {
39
+ request: {
40
+ headers
41
+ }
42
+ };
43
+ }
44
+ function rewrite(url) {
45
+ return server.NextResponse.rewrite(new URL(url, request.url), getResponseInit());
46
+ }
47
+ function redirect(url, host) {
48
+ const urlObj = new URL(url, request.url);
49
+ if (domainConfigs.length > 0) {
50
+ if (!host) {
51
+ const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainConfigs);
52
+ if (bestMatchingDomain) {
53
+ host = bestMatchingDomain.domain;
54
+ if (bestMatchingDomain.defaultLocale === locale && configWithDefaults.localePrefix === 'as-needed') {
55
+ urlObj.pathname = urlObj.pathname.replace("/".concat(locale), '');
56
+ }
57
+ }
58
+ }
59
+ }
60
+ if (host) {
61
+ urlObj.host = host;
62
+ }
63
+ return server.NextResponse.redirect(urlObj.toString());
64
+ }
65
+ const normalizedPathname = utils.getNormalizedPathname(request.nextUrl.pathname, configWithDefaults.locales);
66
+ const pathLocale = utils.getKnownLocaleFromPathname(request.nextUrl.pathname, configWithDefaults.locales);
67
+ const hasLocalePrefix = pathLocale != null;
68
+ let response;
69
+ let internalTemplateName;
70
+ let pathname = request.nextUrl.pathname;
71
+ if (configWithDefaults.pathnames) {
72
+ let resolvedTemplateLocale;
73
+ [resolvedTemplateLocale = locale, internalTemplateName] = utils.getInternalTemplate(configWithDefaults.pathnames, normalizedPathname);
74
+ if (internalTemplateName) {
75
+ const pathnameConfig = configWithDefaults.pathnames[internalTemplateName];
76
+ const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[locale];
77
+ if (utils$1.matchesPathname(localeTemplate, normalizedPathname)) {
78
+ pathname = utils.formatTemplatePathname(normalizedPathname, localeTemplate, internalTemplateName, pathLocale);
79
+ } else {
80
+ const isDefaultLocale = configWithDefaults.defaultLocale === locale || (domain === null || domain === void 0 ? void 0 : domain.defaultLocale) === locale;
81
+ response = redirect(utils.getPathWithSearch(utils.formatTemplatePathname(normalizedPathname, typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[resolvedTemplateLocale], localeTemplate, pathLocale || !isDefaultLocale ? locale : undefined), request.nextUrl.search));
82
+ }
83
+ }
84
+ }
85
+ if (!response) {
86
+ if (pathname === ROOT_URL) {
87
+ const pathWithSearch = utils.getPathWithSearch("/".concat(locale), request.nextUrl.search);
88
+ if (configWithDefaults.localePrefix === 'never' || hasMatchedDefaultLocale && configWithDefaults.localePrefix === 'as-needed') {
89
+ response = rewrite(pathWithSearch);
90
+ } else {
91
+ response = redirect(pathWithSearch);
92
+ }
93
+ } else {
94
+ const pathWithSearch = utils.getPathWithSearch(pathname, request.nextUrl.search);
95
+ if (hasLocalePrefix) {
96
+ const basePath = utils.getBasePath(pathWithSearch, pathLocale);
97
+ if (configWithDefaults.localePrefix === 'never') {
98
+ response = redirect(basePath);
99
+ } else if (pathLocale === locale) {
100
+ if (hasMatchedDefaultLocale && configWithDefaults.localePrefix === 'as-needed') {
101
+ response = redirect(basePath);
102
+ } else {
103
+ if (configWithDefaults.domains) {
104
+ const pathDomain = utils.getBestMatchingDomain(domain, pathLocale, domainConfigs);
105
+ if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
106
+ response = redirect(basePath, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
107
+ } else {
108
+ response = rewrite(pathWithSearch);
109
+ }
110
+ } else {
111
+ response = rewrite(pathWithSearch);
112
+ }
113
+ }
114
+ } else {
115
+ response = redirect("/".concat(locale).concat(basePath));
116
+ }
117
+ } else {
118
+ if (configWithDefaults.localePrefix === 'never' || hasMatchedDefaultLocale && (configWithDefaults.localePrefix === 'as-needed' || configWithDefaults.domains)) {
119
+ response = rewrite("/".concat(locale).concat(pathWithSearch));
120
+ } else {
121
+ response = redirect("/".concat(locale).concat(pathWithSearch));
122
+ }
123
+ }
124
+ }
125
+ }
126
+ if (hasOutdatedCookie) {
127
+ response.cookies.set(constants.COOKIE_LOCALE_NAME, locale, {
128
+ sameSite: 'strict',
129
+ maxAge: 31536000 // 1 year
130
+ });
131
+ }
132
+
133
+ if (configWithDefaults.localePrefix !== 'never' && configWithDefaults.alternateLinks && configWithDefaults.locales.length > 1) {
134
+ var _configWithDefaults$p;
135
+ response.headers.set('Link', getAlternateLinksHeaderValue.default({
136
+ config: configWithDefaults,
137
+ localizedPathnames: internalTemplateName != null ? (_configWithDefaults$p = configWithDefaults.pathnames) === null || _configWithDefaults$p === void 0 ? void 0 : _configWithDefaults$p[internalTemplateName] : undefined,
138
+ request,
139
+ resolvedLocale: locale
140
+ }));
141
+ }
142
+ return response;
143
+ };
144
+ }
145
+
146
+ exports.default = createMiddleware;
@@ -0,0 +1,110 @@
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 constants = require('../shared/constants.js');
8
+ var utils = require('./utils.js');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var Negotiator__default = /*#__PURE__*/_interopDefault(Negotiator);
13
+
14
+ function findDomainFromHost(requestHeaders, domains) {
15
+ var _host;
16
+ let host = utils.getHost(requestHeaders);
17
+
18
+ // Remove port (easier for local development)
19
+ host = (_host = host) === null || _host === void 0 ? void 0 : _host.replace(/:\d+$/, '');
20
+ if (host && domains) {
21
+ return domains.find(cur => cur.domain === host);
22
+ }
23
+ return undefined;
24
+ }
25
+ function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
26
+ let locale;
27
+ const languages = new Negotiator__default.default({
28
+ headers: {
29
+ 'accept-language': requestHeaders.get('accept-language') || undefined
30
+ }
31
+ }).languages();
32
+ try {
33
+ locale = intlLocalematcher.match(languages, locales, defaultLocale);
34
+ } catch (e) {
35
+ // Invalid language
36
+ }
37
+ return locale;
38
+ }
39
+ function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname) {
40
+ let {
41
+ defaultLocale,
42
+ localeDetection,
43
+ locales
44
+ } = _ref;
45
+ let locale;
46
+
47
+ // Prio 1: Use route prefix
48
+ if (pathname) {
49
+ const pathLocale = utils.getLocaleFromPathname(pathname);
50
+ if (locales.includes(pathLocale)) {
51
+ locale = pathLocale;
52
+ }
53
+ }
54
+
55
+ // Prio 2: Use existing cookie
56
+ if (!locale && localeDetection && requestCookies) {
57
+ if (requestCookies.has(constants.COOKIE_LOCALE_NAME)) {
58
+ var _requestCookies$get;
59
+ const value = (_requestCookies$get = requestCookies.get(constants.COOKIE_LOCALE_NAME)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
60
+ if (value && locales.includes(value)) {
61
+ locale = value;
62
+ }
63
+ }
64
+ }
65
+
66
+ // Prio 3: Use the `accept-language` header
67
+ if (!locale && localeDetection && requestHeaders) {
68
+ locale = getAcceptLanguageLocale(requestHeaders, locales, defaultLocale);
69
+ }
70
+
71
+ // Prio 4: Use default locale
72
+ if (!locale) {
73
+ locale = defaultLocale;
74
+ }
75
+ return locale;
76
+ }
77
+ function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathname) {
78
+ const {
79
+ domains
80
+ } = config;
81
+ const localeFromPrefixStrategy = resolveLocaleFromPrefix(config, requestHeaders, requestCookies, pathname);
82
+
83
+ // Prio 1: Use a domain
84
+ if (domains) {
85
+ const domain = findDomainFromHost(requestHeaders, domains);
86
+ const hasLocalePrefix = pathname && pathname.startsWith("/".concat(localeFromPrefixStrategy));
87
+ if (domain) {
88
+ return {
89
+ locale: utils.isLocaleSupportedOnDomain(localeFromPrefixStrategy, domain) || hasLocalePrefix ? localeFromPrefixStrategy : domain.defaultLocale,
90
+ domain
91
+ };
92
+ }
93
+ }
94
+
95
+ // Prio 2: Use prefix strategy
96
+ return {
97
+ locale: localeFromPrefixStrategy
98
+ };
99
+ }
100
+ function resolveLocale(config, requestHeaders, requestCookies, pathname) {
101
+ if (config.domains) {
102
+ return resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathname);
103
+ } else {
104
+ return {
105
+ locale: resolveLocaleFromPrefix(config, requestHeaders, requestCookies, pathname)
106
+ };
107
+ }
108
+ }
109
+
110
+ exports.default = resolveLocale;
@@ -0,0 +1,150 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var utils = require('../shared/utils.js');
6
+
7
+ function getLocaleFromPathname(pathname) {
8
+ return pathname.split('/')[1];
9
+ }
10
+ function getInternalTemplate(pathnames, pathname) {
11
+ for (const [internalPathname, localizedPathnamesOrPathname] of Object.entries(pathnames)) {
12
+ if (typeof localizedPathnamesOrPathname === 'string') {
13
+ const localizedPathname = localizedPathnamesOrPathname;
14
+ if (utils.matchesPathname(localizedPathname, pathname)) {
15
+ return [undefined, internalPathname];
16
+ }
17
+ } else {
18
+ for (const [locale, localizedPathname] of Object.entries(localizedPathnamesOrPathname)) {
19
+ if (utils.matchesPathname(localizedPathname, pathname)) {
20
+ return [locale, internalPathname];
21
+ }
22
+ }
23
+ }
24
+ }
25
+ return [undefined, undefined];
26
+ }
27
+ function formatTemplatePathname(sourcePathname, sourceTemplate, targetTemplate, localePrefix) {
28
+ const params = getRouteParams(sourceTemplate, sourcePathname);
29
+ let targetPathname = '';
30
+ if (localePrefix) {
31
+ targetPathname = "/".concat(localePrefix);
32
+ }
33
+ targetPathname += formatPathname(targetTemplate, params);
34
+ if (targetPathname.endsWith('/')) {
35
+ targetPathname = targetPathname.slice(0, -1);
36
+ }
37
+ return targetPathname;
38
+ }
39
+
40
+ /**
41
+ * Removes potential locales from the pathname.
42
+ */
43
+ function getNormalizedPathname(pathname, locales) {
44
+ // Add trailing slash for consistent handling
45
+ // both for the root as well as nested paths
46
+ if (!pathname.endsWith('/')) {
47
+ pathname += '/';
48
+ }
49
+ const match = pathname.match("^/(".concat(locales.join('|'), ")(.*)"));
50
+ let result = match ? match[2] : pathname;
51
+
52
+ // Remove trailing slash
53
+ if (result.endsWith('/') && result !== '/') {
54
+ result = result.slice(0, -1);
55
+ }
56
+ return result;
57
+ }
58
+ function getKnownLocaleFromPathname(pathname, locales) {
59
+ const pathLocaleCandidate = getLocaleFromPathname(pathname);
60
+ const pathLocale = locales.includes(pathLocaleCandidate) ? pathLocaleCandidate : undefined;
61
+ return pathLocale;
62
+ }
63
+ function getBasePath(pathname, pathLocale) {
64
+ let result = pathname.replace("/".concat(pathLocale), '');
65
+ if (!result.startsWith('/')) {
66
+ result = "/".concat(result);
67
+ }
68
+ return result;
69
+ }
70
+ function getRouteParams(template, pathname) {
71
+ const regex = utils.templateToRegex(template);
72
+ const match = regex.exec(pathname);
73
+ if (!match) return undefined;
74
+ const params = {};
75
+ for (let i = 1; i < match.length; i++) {
76
+ var _template$match;
77
+ const key = (_template$match = template.match(/\[([^\]]+)\]/g)) === null || _template$match === void 0 ? void 0 : _template$match[i - 1].replace(/[[\]]/g, '');
78
+ if (key) params[key] = match[i];
79
+ }
80
+ return params;
81
+ }
82
+ function formatPathname(template, params) {
83
+ if (!params) return template;
84
+
85
+ // Simplify syntax for optional catchall ('[[...slug]]') so
86
+ // we can replace the value with simple interpolation
87
+ template = template.replaceAll('[[', '[').replaceAll(']]', ']');
88
+ let result = template;
89
+ Object.entries(params).forEach(_ref => {
90
+ let [key, value] = _ref;
91
+ result = result.replace("[".concat(key, "]"), value);
92
+ });
93
+ return result;
94
+ }
95
+ function getPathWithSearch(pathname, search) {
96
+ let pathWithSearch = pathname;
97
+ if (search) {
98
+ pathWithSearch += search;
99
+ }
100
+ return pathWithSearch;
101
+ }
102
+ function getHost(requestHeaders) {
103
+ var _ref2, _requestHeaders$get;
104
+ return (_ref2 = (_requestHeaders$get = requestHeaders.get('x-forwarded-host')) !== null && _requestHeaders$get !== void 0 ? _requestHeaders$get : requestHeaders.get('host')) !== null && _ref2 !== void 0 ? _ref2 : undefined;
105
+ }
106
+ function isLocaleSupportedOnDomain(locale, domain) {
107
+ return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
108
+ }
109
+ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
110
+ let domainConfig;
111
+
112
+ // Prio 1: Stay on current domain
113
+ if (curHostDomain && isLocaleSupportedOnDomain(locale, curHostDomain)) {
114
+ domainConfig = curHostDomain;
115
+ }
116
+
117
+ // Prio 2: Use alternative domain with matching default locale
118
+ if (!domainConfig) {
119
+ domainConfig = domainConfigs.find(cur => cur.defaultLocale === locale);
120
+ }
121
+
122
+ // Prio 3: Use alternative domain with restricted matching locale
123
+ if (!domainConfig) {
124
+ domainConfig = domainConfigs.find(cur => cur.locales != null && cur.locales.includes(locale));
125
+ }
126
+
127
+ // Prio 4: Stay on the current domain if it supports all locales
128
+ if (!domainConfig && (curHostDomain === null || curHostDomain === void 0 ? void 0 : curHostDomain.locales) == null) {
129
+ domainConfig = curHostDomain;
130
+ }
131
+
132
+ // Prio 5: Use alternative domain that supports all locales
133
+ if (!domainConfig) {
134
+ domainConfig = domainConfigs.find(cur => !cur.locales);
135
+ }
136
+ return domainConfig;
137
+ }
138
+
139
+ exports.formatPathname = formatPathname;
140
+ exports.formatTemplatePathname = formatTemplatePathname;
141
+ exports.getBasePath = getBasePath;
142
+ exports.getBestMatchingDomain = getBestMatchingDomain;
143
+ exports.getHost = getHost;
144
+ exports.getInternalTemplate = getInternalTemplate;
145
+ exports.getKnownLocaleFromPathname = getKnownLocaleFromPathname;
146
+ exports.getLocaleFromPathname = getLocaleFromPathname;
147
+ exports.getNormalizedPathname = getNormalizedPathname;
148
+ exports.getPathWithSearch = getPathWithSearch;
149
+ exports.getRouteParams = getRouteParams;
150
+ exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var middleware = require('./middleware/middleware.js');
6
+
7
+
8
+
9
+ exports.default = middleware.default;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
+ var React = require('react');
7
+ var useLocale = require('../react-client/useLocale.js');
8
+ var BaseLinkWithLocale = require('../shared/BaseLinkWithLocale.js');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
+
14
+ function BaseLink(_ref, ref) {
15
+ let {
16
+ locale,
17
+ ...rest
18
+ } = _ref;
19
+ const defaultLocale = useLocale.default();
20
+ const linkLocale = locale || defaultLocale;
21
+ return /*#__PURE__*/React__default.default.createElement(BaseLinkWithLocale.default, _rollupPluginBabelHelpers.extends({
22
+ ref: ref,
23
+ hrefLang: linkLocale,
24
+ locale: linkLocale
25
+ }, rest));
26
+ }
27
+
28
+ /**
29
+ * Wraps `next/link` and prefixes the `href` with the current locale if
30
+ * necessary.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * import {Link} from 'next-intl';
35
+ *
36
+ * // When the user is on `/en`, the link will point to `/en/about`
37
+ * <Link href="/about">About</Link>
38
+ *
39
+ * // You can override the `locale` to switch to another language
40
+ * <Link href="/" locale="de">Switch to German</Link>
41
+ * ```
42
+ *
43
+ * Note that when a `locale` prop is passed to switch the locale, the `prefetch`
44
+ * prop is not supported. This is because Next.js would prefetch the page and
45
+ * the `set-cookie` response header would cause the locale cookie on the current
46
+ * page to be overwritten before the user even decides to change the locale.
47
+ */
48
+ const BaseLinkWithRef = /*#__PURE__*/React.forwardRef(BaseLink);
49
+ BaseLinkWithRef.displayName = 'Link';
50
+ var BaseLink$1 = BaseLinkWithRef;
51
+
52
+ exports.default = BaseLink$1;