next-intl 3.0.0-beta.1 → 3.0.0-beta.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 (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -21
  3. package/dist/_virtual/next-intl.esm.js +1 -7
  4. package/dist/_virtual/next-intl.esm.js.map +1 -1
  5. package/dist/client/NextIntlClientProvider.d.ts +4 -0
  6. package/dist/client/index.d.ts +2 -4
  7. package/dist/client/next-intl.esm.js +39 -27
  8. package/dist/client/next-intl.esm.js.map +1 -1
  9. package/dist/client/next-intl.esm2.js +14 -20
  10. package/dist/client/next-intl.esm2.js.map +1 -1
  11. package/dist/client/useClientLocale.d.ts +1 -0
  12. package/dist/client/usePathname.d.ts +9 -6
  13. package/dist/client/useRouter.d.ts +16 -0
  14. package/dist/index.d.ts +6 -43
  15. package/dist/link/Link.d.ts +27 -0
  16. package/dist/link/index.d.ts +1 -0
  17. package/dist/link/next-intl.esm.js +39 -0
  18. package/dist/link/next-intl.esm.js.map +1 -0
  19. package/dist/link/react-server/Link.d.ts +7 -0
  20. package/dist/link/react-server/index.d.ts +1 -0
  21. package/dist/middleware/NextIntlMiddlewareConfig.d.ts +46 -0
  22. package/dist/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  23. package/dist/middleware/index.d.ts +4 -0
  24. package/dist/middleware/middleware.d.ts +3 -0
  25. package/dist/middleware/resolveLocale.d.ts +6 -0
  26. package/dist/middleware/utils.d.ts +5 -0
  27. package/dist/next-intl.cjs.development.js +180 -111
  28. package/dist/next-intl.cjs.development.js.map +1 -1
  29. package/dist/next-intl.cjs.production.min.js +1 -1
  30. package/dist/next-intl.cjs.production.min.js.map +1 -1
  31. package/dist/next-intl.esm.js +4 -18
  32. package/dist/next-intl.esm.js.map +1 -1
  33. package/dist/react-client/Link.d.ts +4 -0
  34. package/dist/react-client/index.d.ts +17 -0
  35. package/dist/react-client/next-intl.esm.js +18 -13
  36. package/dist/react-client/next-intl.esm.js.map +1 -1
  37. package/dist/react-client/next-intl.esm2.js +18 -0
  38. package/dist/react-client/next-intl.esm2.js.map +1 -0
  39. package/dist/react-client/next-intl.esm3.js +15 -0
  40. package/dist/react-client/next-intl.esm3.js.map +1 -0
  41. package/dist/react-server/Link.d.ts +4 -0
  42. package/dist/react-server/index.d.ts +9 -36
  43. package/dist/react-server/useFormatter.d.ts +2 -0
  44. package/dist/react-server/useIntl.d.ts +1 -1
  45. package/dist/react-server/useLocale.d.ts +2 -1
  46. package/dist/react-server/useNow.d.ts +2 -1
  47. package/dist/react-server/useTimeZone.d.ts +2 -1
  48. package/dist/react-server/useTranslations.d.ts +2 -5
  49. package/dist/server/createRequestConfig.d.ts +2 -2
  50. package/dist/server/getConfig.d.ts +14 -6
  51. package/dist/server/getFormatter.d.ts +7 -0
  52. package/dist/server/getIntl.d.ts +2 -1
  53. package/dist/server/getNow.d.ts +1 -1
  54. package/dist/server/getRequestConfig.d.ts +8 -3
  55. package/dist/server/index.d.ts +5 -3
  56. package/dist/server/react-client/index.d.ts +8 -0
  57. package/dist/server/react-client/redirect.d.ts +1 -0
  58. package/dist/shared/BaseLink.d.ts +7 -0
  59. package/dist/shared/NextIntlClientProvider.d.ts +1 -1
  60. package/dist/shared/constants.d.ts +1 -0
  61. package/dist/shared/next-intl.esm.js +36 -29
  62. package/dist/shared/next-intl.esm.js.map +1 -1
  63. package/dist/shared/next-intl.esm2.js +49 -41
  64. package/dist/shared/next-intl.esm2.js.map +1 -1
  65. package/dist/shared/next-intl.esm3.js +44 -7
  66. package/dist/shared/next-intl.esm3.js.map +1 -1
  67. package/dist/shared/next-intl.esm4.js +3 -3
  68. package/dist/shared/next-intl.esm4.js.map +1 -1
  69. package/dist/shared/redirect.d.ts +1 -0
  70. package/dist/shared/utils.d.ts +15 -0
  71. package/dist/src/client/NextIntlClientProvider.d.ts +4 -0
  72. package/dist/src/client/NextIntlClientProvider.js +16 -0
  73. package/dist/src/client/NextIntlClientProvider.js.map +1 -0
  74. package/dist/src/client/index.d.ts +2 -4
  75. package/dist/src/client/index.js +3 -4
  76. package/dist/src/client/index.js.map +1 -1
  77. package/dist/src/client/useClientLocale.d.ts +1 -0
  78. package/dist/src/client/useClientLocale.js +16 -0
  79. package/dist/src/client/useClientLocale.js.map +1 -0
  80. package/dist/src/client/usePathname.d.ts +9 -6
  81. package/dist/src/client/usePathname.js +20 -26
  82. package/dist/src/client/usePathname.js.map +1 -1
  83. package/dist/src/client/useRouter.d.ts +16 -0
  84. package/dist/src/client/useRouter.js +35 -12
  85. package/dist/src/client/useRouter.js.map +1 -1
  86. package/dist/src/index.d.ts +6 -43
  87. package/dist/src/index.js +6 -12
  88. package/dist/src/index.js.map +1 -1
  89. package/dist/src/link/Link.d.ts +27 -0
  90. package/dist/src/link/Link.js +29 -0
  91. package/dist/src/link/Link.js.map +1 -0
  92. package/dist/src/link/index.d.ts +1 -0
  93. package/dist/src/link/index.js +2 -0
  94. package/dist/src/link/index.js.map +1 -0
  95. package/dist/src/link/react-server/Link.d.ts +7 -0
  96. package/dist/src/link/react-server/Link.js +8 -0
  97. package/dist/src/link/react-server/Link.js.map +1 -0
  98. package/dist/src/link/react-server/index.d.ts +1 -0
  99. package/dist/src/link/react-server/index.js +2 -0
  100. package/dist/src/link/react-server/index.js.map +1 -0
  101. package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +46 -0
  102. package/dist/src/middleware/NextIntlMiddlewareConfig.js.map +1 -0
  103. package/dist/src/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  104. package/dist/src/middleware/getAlternateLinksHeaderValue.js +64 -0
  105. package/dist/src/middleware/getAlternateLinksHeaderValue.js.map +1 -0
  106. package/dist/src/middleware/index.d.ts +4 -0
  107. package/dist/src/middleware/index.js +5 -0
  108. package/dist/src/middleware/index.js.map +1 -0
  109. package/dist/src/middleware/middleware.d.ts +3 -0
  110. package/dist/src/middleware/middleware.js +183 -0
  111. package/dist/src/middleware/middleware.js.map +1 -0
  112. package/dist/src/middleware/resolveLocale.d.ts +6 -0
  113. package/dist/src/middleware/resolveLocale.js +88 -0
  114. package/dist/src/middleware/resolveLocale.js.map +1 -0
  115. package/dist/src/middleware/utils.d.ts +5 -0
  116. package/dist/src/middleware/utils.js +37 -0
  117. package/dist/src/middleware/utils.js.map +1 -0
  118. package/dist/src/react-client/Link.d.ts +4 -0
  119. package/dist/src/react-client/Link.js +19 -0
  120. package/dist/src/react-client/Link.js.map +1 -0
  121. package/dist/src/react-client/index.d.ts +17 -0
  122. package/dist/src/react-client/index.js +19 -0
  123. package/dist/src/react-client/index.js.map +1 -0
  124. package/dist/src/react-server/Link.d.ts +4 -0
  125. package/dist/src/react-server/Link.js +19 -0
  126. package/dist/src/react-server/Link.js.map +1 -0
  127. package/dist/src/react-server/index.d.ts +9 -36
  128. package/dist/src/react-server/index.js +9 -5
  129. package/dist/src/react-server/index.js.map +1 -1
  130. package/dist/src/react-server/useFormatter.d.ts +2 -0
  131. package/dist/src/react-server/useFormatter.js +8 -0
  132. package/dist/src/react-server/useFormatter.js.map +1 -0
  133. package/dist/src/react-server/useHook.js +10 -6
  134. package/dist/src/react-server/useHook.js.map +1 -1
  135. package/dist/src/react-server/useIntl.d.ts +1 -1
  136. package/dist/src/react-server/useIntl.js +5 -0
  137. package/dist/src/react-server/useIntl.js.map +1 -1
  138. package/dist/src/react-server/useLocale.d.ts +2 -1
  139. package/dist/src/react-server/useLocale.js +3 -1
  140. package/dist/src/react-server/useLocale.js.map +1 -1
  141. package/dist/src/react-server/useNow.d.ts +2 -1
  142. package/dist/src/react-server/useNow.js +4 -1
  143. package/dist/src/react-server/useNow.js.map +1 -1
  144. package/dist/src/react-server/useTimeZone.d.ts +2 -1
  145. package/dist/src/react-server/useTimeZone.js +3 -1
  146. package/dist/src/react-server/useTimeZone.js.map +1 -1
  147. package/dist/src/react-server/useTranslations.d.ts +2 -5
  148. package/dist/src/react-server/useTranslations.js +5 -2
  149. package/dist/src/react-server/useTranslations.js.map +1 -1
  150. package/dist/src/server/createRequestConfig.d.ts +2 -2
  151. package/dist/src/server/createRequestConfig.js.map +1 -1
  152. package/dist/src/server/getConfig.d.ts +14 -6
  153. package/dist/src/server/getConfig.js +4 -4
  154. package/dist/src/server/getConfig.js.map +1 -1
  155. package/dist/src/server/getFormatter.d.ts +7 -0
  156. package/dist/src/server/getFormatter.js +9 -0
  157. package/dist/src/server/getFormatter.js.map +1 -0
  158. package/dist/src/server/getIntl.d.ts +2 -1
  159. package/dist/src/server/getIntl.js +6 -0
  160. package/dist/src/server/getIntl.js.map +1 -1
  161. package/dist/src/server/getLocale.js +19 -7
  162. package/dist/src/server/getLocale.js.map +1 -1
  163. package/dist/src/server/getNow.d.ts +1 -1
  164. package/dist/src/server/getRequestConfig.d.ts +8 -3
  165. package/dist/src/server/getRequestConfig.js +3 -0
  166. package/dist/src/server/getRequestConfig.js.map +1 -1
  167. package/dist/src/server/index.d.ts +5 -3
  168. package/dist/src/server/index.js +27 -4
  169. package/dist/src/server/index.js.map +1 -1
  170. package/dist/src/server/react-client/index.d.ts +8 -0
  171. package/dist/src/server/react-client/index.js +15 -0
  172. package/dist/src/server/react-client/index.js.map +1 -0
  173. package/dist/src/server/react-client/redirect.d.ts +1 -0
  174. package/dist/src/server/react-client/redirect.js +8 -0
  175. package/dist/src/server/react-client/redirect.js.map +1 -0
  176. package/dist/src/server/redirect.js +2 -4
  177. package/dist/src/server/redirect.js.map +1 -1
  178. package/dist/src/shared/BaseLink.d.ts +7 -0
  179. package/dist/src/shared/BaseLink.js +34 -0
  180. package/dist/src/shared/BaseLink.js.map +1 -0
  181. package/dist/src/shared/NextIntlClientProvider.d.ts +1 -1
  182. package/dist/src/shared/NextIntlClientProvider.js +0 -1
  183. package/dist/src/shared/NextIntlClientProvider.js.map +1 -1
  184. package/dist/src/shared/constants.d.ts +1 -0
  185. package/dist/src/shared/constants.js +2 -0
  186. package/dist/src/shared/constants.js.map +1 -1
  187. package/dist/src/shared/redirect.d.ts +1 -0
  188. package/dist/src/shared/redirect.js +7 -0
  189. package/dist/src/shared/redirect.js.map +1 -0
  190. package/dist/src/shared/utils.d.ts +15 -0
  191. package/dist/src/shared/utils.js +53 -0
  192. package/dist/src/shared/utils.js.map +1 -0
  193. package/link.d.ts +1 -0
  194. package/package.json +33 -25
  195. package/plugin.d.ts +1 -1
  196. package/plugin.js +8 -2
  197. package/src/client/NextIntlClientProvider.tsx +18 -0
  198. package/src/client/index.tsx +3 -4
  199. package/src/client/useClientLocale.tsx +17 -0
  200. package/src/client/usePathname.tsx +22 -31
  201. package/src/client/useRouter.tsx +30 -9
  202. package/src/index.tsx +6 -16
  203. package/src/link/Link.tsx +34 -0
  204. package/src/link/index.tsx +1 -0
  205. package/src/link/react-server/Link.tsx +12 -0
  206. package/src/link/react-server/index.tsx +1 -0
  207. package/src/middleware/NextIntlMiddlewareConfig.tsx +63 -0
  208. package/src/middleware/getAlternateLinksHeaderValue.tsx +90 -0
  209. package/src/middleware/index.tsx +5 -0
  210. package/src/middleware/middleware.tsx +253 -0
  211. package/src/middleware/resolveLocale.tsx +151 -0
  212. package/src/middleware/utils.tsx +61 -0
  213. package/src/react-client/Link.tsx +24 -0
  214. package/src/react-client/index.tsx +23 -0
  215. package/src/react-server/Link.tsx +24 -0
  216. package/src/react-server/index.tsx +10 -6
  217. package/src/react-server/useFormatter.tsx +10 -0
  218. package/src/react-server/useHook.tsx +10 -6
  219. package/src/react-server/useIntl.tsx +9 -0
  220. package/src/react-server/useLocale.tsx +5 -1
  221. package/src/react-server/useNow.tsx +10 -1
  222. package/src/react-server/useTimeZone.tsx +5 -1
  223. package/src/react-server/useTranslations.tsx +9 -2
  224. package/src/server/createRequestConfig.tsx +2 -2
  225. package/src/server/getConfig.tsx +2 -2
  226. package/src/server/getFormatter.tsx +10 -0
  227. package/src/server/getIntl.tsx +10 -0
  228. package/src/server/getLocale.tsx +21 -7
  229. package/src/server/getRequestConfig.tsx +9 -4
  230. package/src/server/index.tsx +31 -6
  231. package/src/server/react-client/index.tsx +16 -0
  232. package/src/server/react-client/redirect.tsx +8 -0
  233. package/src/server/redirect.tsx +2 -5
  234. package/src/shared/BaseLink.tsx +52 -0
  235. package/src/shared/NextIntlClientProvider.tsx +0 -2
  236. package/src/shared/constants.tsx +3 -0
  237. package/src/shared/redirect.tsx +7 -0
  238. package/src/shared/utils.tsx +91 -0
  239. package/CHANGELOG.md +0 -510
  240. package/client.js +0 -1
  241. package/dist/client/getCookieLocale.d.ts +0 -1
  242. package/dist/client/hasPathnamePrefixed.d.ts +0 -1
  243. package/dist/client/localizeHref.d.ts +0 -4
  244. package/dist/client/next-intl.esm3.js +0 -7
  245. package/dist/client/next-intl.esm3.js.map +0 -1
  246. package/dist/client/next-intl.esm4.js +0 -23
  247. package/dist/client/next-intl.esm4.js.map +0 -1
  248. package/dist/middleware.d.ts +0 -3
  249. package/dist/server/NextIntlConfig.d.ts +0 -6
  250. package/dist/server/NextIntlMiddlewareConfig.d.ts +0 -11
  251. package/dist/server/resolveLocale.d.ts +0 -9
  252. package/dist/shared/Link.d.ts +0 -7
  253. package/dist/shared/LocalizedLink.d.ts +0 -7
  254. package/dist/shared/localizePathname.d.ts +0 -1
  255. package/dist/src/client/getCookieLocale.d.ts +0 -1
  256. package/dist/src/client/getCookieLocale.js +0 -16
  257. package/dist/src/client/getCookieLocale.js.map +0 -1
  258. package/dist/src/client/hasPathnamePrefixed.d.ts +0 -1
  259. package/dist/src/client/hasPathnamePrefixed.js +0 -6
  260. package/dist/src/client/hasPathnamePrefixed.js.map +0 -1
  261. package/dist/src/client/localizeHref.d.ts +0 -4
  262. package/dist/src/client/localizeHref.js +0 -28
  263. package/dist/src/client/localizeHref.js.map +0 -1
  264. package/dist/src/middleware.d.ts +0 -3
  265. package/dist/src/middleware.js +0 -74
  266. package/dist/src/middleware.js.map +0 -1
  267. package/dist/src/server/NextIntlConfig.d.ts +0 -6
  268. package/dist/src/server/NextIntlConfig.js +0 -2
  269. package/dist/src/server/NextIntlConfig.js.map +0 -1
  270. package/dist/src/server/NextIntlMiddlewareConfig.d.ts +0 -11
  271. package/dist/src/server/NextIntlMiddlewareConfig.js.map +0 -1
  272. package/dist/src/server/resolveLocale.d.ts +0 -9
  273. package/dist/src/server/resolveLocale.js +0 -63
  274. package/dist/src/server/resolveLocale.js.map +0 -1
  275. package/dist/src/shared/Link.d.ts +0 -7
  276. package/dist/src/shared/Link.js +0 -18
  277. package/dist/src/shared/Link.js.map +0 -1
  278. package/dist/src/shared/LocalizedLink.d.ts +0 -7
  279. package/dist/src/shared/LocalizedLink.js +0 -18
  280. package/dist/src/shared/LocalizedLink.js.map +0 -1
  281. package/dist/src/shared/localizePathname.d.ts +0 -1
  282. package/dist/src/shared/localizePathname.js +0 -8
  283. package/dist/src/shared/localizePathname.js.map +0 -1
  284. package/server.js +0 -1
  285. package/src/client/getCookieLocale.tsx +0 -19
  286. package/src/client/hasPathnamePrefixed.tsx +0 -7
  287. package/src/client/localizeHref.tsx +0 -37
  288. package/src/middleware.tsx +0 -93
  289. package/src/server/NextIntlConfig.tsx +0 -16
  290. package/src/server/NextIntlMiddlewareConfig.tsx +0 -12
  291. package/src/server/resolveLocale.tsx +0 -86
  292. package/src/shared/Link.tsx +0 -26
  293. package/src/shared/LocalizedLink.tsx +0 -26
  294. package/src/shared/localizePathname.tsx +0 -9
  295. /package/dist/src/{server → middleware}/NextIntlMiddlewareConfig.js +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Jan Amann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,47 +1,54 @@
1
1
  <h1 align="center">
2
2
  <br>
3
3
  <br>
4
- <img width="400" src="media/logo.svg" alt="next-intl">
4
+ <a href="https://next-intl-docs.vercel.app/">
5
+ <img width="400" src="media/logo.svg" alt="next-intl">
6
+ </a>
5
7
  <br>
6
8
  <br>
7
9
  <br>
8
10
  </h1>
9
11
 
10
- > A minimal, but complete solution for internationalization in Next.js apps.
12
+ > Internationalization (i18n) for Next.js that gets out of your way.
11
13
 
12
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)
13
15
 
14
16
  <hr />
15
17
 
16
- **🚀 New ✨**: `next-intl` is adding support for **Next.js 13** and the `app` directory. A preview version with support for React Server Components is [now available](https://next-intl-docs.vercel.app/docs/next-13) for early adopters.
18
+ 📣 [Support for Next.js 13 and the App Router has arrived ](https://next-intl-docs.vercel.app/docs/next-13)
17
19
 
18
20
  <hr />
19
21
 
20
22
  ## Features
21
23
 
22
- This library complements the [internationalized routing](https://nextjs.org/docs/advanced-features/i18n-routing) capabilities of Next.js by managing translations and providing them to components.
24
+ Internationalization is an essential part of the user experience. next-intl gives you everything you need to get language subtleties right and has always got your back whenever you need to fine-tune a translation.
23
25
 
24
- - 🌟 **Proven ICU syntax**: This covers interpolation, plurals, ordinal pluralization, label selection based on enums and rich text. I18n is an essential part of the user experience, therefore this library doesn't compromise on flexibility and never leaves you behind when you need to fine tune a translation.
25
- - 📅 **Built-in date, time and number formatting**: You can use global formats for a consistent look & feel of your app and integrate them with translations.
26
- - 💡 **Hooks-only API**: This ensures that you can use the same API for `children` as well as for attributes which expect strings.
27
- - **Type-safe**: If you're using TypeScript, you'll benefit from autocompletion for available message keys and compile-time errors for typos.
28
- - ⚔️ **Battle-tested building blocks**: This library is a minimal wrapper around built-in browser APIs and supplemental lower-level APIs from Format.JS.
29
- - 🚀 **Fast**: By integrating with both static as well as server side rendering you always get the best possible performance from your app.
26
+ - 🌟 **ICU message syntax**: Localize your messages with interpolation, plurals, ordinal pluralization, enum-based label selection, and rich text.
27
+ - 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
28
+ - **Type-safe**: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
29
+ - 💡 **Hooks-only API**: Learn a single API that can be used across your code base to turn translations into plain strings or rich text.
30
+ - 🚀 **Fast**: Get the best performance from your app by supporting internationalization on both static and dynamic pages.
31
+ - ⚔️ **Standards-based**: Use the best parts of built-in JavaScript APIs and supplemental lower-level APIs from Format.JS.
30
32
 
31
33
  ## What does it look like?
32
34
 
33
35
  This library is based on the premise that messages can be grouped by namespaces (typically a component name).
34
36
 
35
37
  ```jsx
36
- // LatestFollower.js
37
- function LatestFollower({user}) {
38
- const t = useTranslations('LatestFollower');
39
-
38
+ // UserDetails.tsx
39
+ import {useTranslations, useFormatter} from 'next-intl';
40
+
41
+ function UserDetails({user}) {
42
+ const t = useTranslations('UserDetails');
43
+ const format = useFormatter();
44
+
40
45
  return (
41
- <>
42
- <Text>{t('latestFollower', {username: user.name})}</Text>
43
- <IconButton aria-label={t('followBack')} icon={<FollowIcon />} />
44
- </>
46
+ <section>
47
+ <h2>{t('title')}</h2>
48
+ <p>{t('followers', {count: user.followers.length})}</p>
49
+ <p>{t('lastSeen', {time: format.relativeTime(user.lastSeen)})</p>
50
+ <Image alt={t('portrait', {username: user.name})} src={user.portrait} />
51
+ </section>
45
52
  );
46
53
  }
47
54
  ```
@@ -49,11 +56,24 @@ function LatestFollower({user}) {
49
56
  ```js
50
57
  // en.json
51
58
  {
52
- "LatestFollower": {
53
- "latestFollower": "{username} started following you",
54
- "followBack": "Follow back"
59
+ "UserDetails": {
60
+ "title": "User details",
61
+ "followers": "{count, plural, ↵
62
+ =0 {No followers yet} ↵
63
+ =1 {One follower} ↵
64
+ other {# followers} ↵
65
+ }",
66
+ "lastSeen": "Last seen {time}",
67
+ "portrait": "Portrait of {username}"
55
68
  }
56
69
  }
57
70
  ```
58
71
 
59
72
  ### [→ Read the docs](https://next-intl-docs.vercel.app/)
73
+
74
+ <div align="center">
75
+ <a href="https://next-intl-docs.vercel.app/redirect?href=https://crowdin.com" target="_blank">
76
+ <img width="350" src="media/partner.svg" alt="Crowdin logo">
77
+ </a>
78
+ <br>
79
+ </div>
@@ -1,33 +1,27 @@
1
1
  function _extends() {
2
- _extends = Object.assign || function (target) {
2
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3
3
  for (var i = 1; i < arguments.length; i++) {
4
4
  var source = arguments[i];
5
-
6
5
  for (var key in source) {
7
6
  if (Object.prototype.hasOwnProperty.call(source, key)) {
8
7
  target[key] = source[key];
9
8
  }
10
9
  }
11
10
  }
12
-
13
11
  return target;
14
12
  };
15
-
16
13
  return _extends.apply(this, arguments);
17
14
  }
18
-
19
15
  function _objectWithoutPropertiesLoose(source, excluded) {
20
16
  if (source == null) return {};
21
17
  var target = {};
22
18
  var sourceKeys = Object.keys(source);
23
19
  var key, i;
24
-
25
20
  for (i = 0; i < sourceKeys.length; i++) {
26
21
  key = sourceKeys[i];
27
22
  if (excluded.indexOf(key) >= 0) continue;
28
23
  target[key] = source[key];
29
24
  }
30
-
31
25
  return target;
32
26
  }
33
27
 
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ import { ComponentProps } from 'react';
2
+ import NextIntlClientProvider_ from '../shared/NextIntlClientProvider';
3
+ /** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */
4
+ export default function NextIntlClientProvider(props: ComponentProps<typeof NextIntlClientProvider_>): JSX.Element;
@@ -1,7 +1,6 @@
1
1
  /**
2
- * Client-only APIs.
2
+ * Client-only APIs available via `next-intl/client`.
3
3
  */
4
- import NextIntlClientProvider_ from '../shared/NextIntlClientProvider';
5
4
  import usePathname from './usePathname';
6
5
  import useRouter from './useRouter';
7
6
  export { default as useRouter } from './useRouter';
@@ -10,5 +9,4 @@ export { default as usePathname } from './usePathname';
10
9
  export declare const useUnlocalizedPathname: typeof usePathname;
11
10
  /** @deprecated Is called `useRouter` now. */
12
11
  export declare const useLocalizedRouter: typeof useRouter;
13
- /** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */
14
- export declare const NextIntlClientProvider: typeof NextIntlClientProvider_;
12
+ export { default as NextIntlClientProvider } from './NextIntlClientProvider';
@@ -1,33 +1,45 @@
1
1
  import { extends as _extends } from '../_virtual/next-intl.esm.js';
2
- import localizePathname from '../shared/next-intl.esm3.js';
3
- import getCookieLocale from './next-intl.esm4.js';
4
- import hasPathnamePrefixed from './next-intl.esm3.js';
2
+ import { useRouter as useRouter$1 } from 'next/navigation';
3
+ import { useMemo } from 'react';
4
+ import { localizeHref } from '../shared/next-intl.esm2.js';
5
+ import useClientLocale from './next-intl.esm2.js';
5
6
 
6
- function localizeHref(href, locale) {
7
- var cookieLocale = getCookieLocale();
8
- if (!locale) locale = cookieLocale;
9
- var pathname = window.location.pathname;
10
- var isSwitchingLocale = locale !== cookieLocale;
11
- var isPathnamePrefixed = hasPathnamePrefixed(locale, pathname);
12
-
13
- if (isPathnamePrefixed || isSwitchingLocale) {
14
- var prefixedHref;
15
-
16
- if (typeof href === 'string') {
17
- prefixedHref = localizePathname(locale, href);
18
- } else {
19
- prefixedHref = _extends({}, href);
20
-
21
- if (href.pathname) {
22
- prefixedHref.pathname = localizePathname(locale, href.pathname);
23
- }
7
+ /**
8
+ * Returns a wrapped instance of `useRouter` from `next/navigation` that
9
+ * will automatically localize the `href` parameters it receives.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * 'use client';
14
+ *
15
+ * import {useRouter} from 'next-intl/client';
16
+ *
17
+ * const router = useRouter();
18
+ *
19
+ * // When the user is on `/en`, the router will navigate to `/en/about`
20
+ * router.push('/about');
21
+ * ```
22
+ */
23
+ function useRouter() {
24
+ var router = useRouter$1();
25
+ var locale = useClientLocale();
26
+ return useMemo(function () {
27
+ function localize(href) {
28
+ return localizeHref(href, locale, locale, window.location.pathname);
24
29
  }
25
-
26
- return prefixedHref;
27
- } else {
28
- return href;
29
- }
30
+ return _extends({}, router, {
31
+ push: function push(href) {
32
+ return router.push(localize(href));
33
+ },
34
+ replace: function replace(href) {
35
+ return router.replace(localize(href));
36
+ },
37
+ prefetch: function prefetch(href) {
38
+ return router.prefetch(localize(href));
39
+ }
40
+ });
41
+ }, [locale, router]);
30
42
  }
31
43
 
32
- export { localizeHref as default };
44
+ export { useRouter as default };
33
45
  //# sourceMappingURL=next-intl.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm.js","sources":["../../src/client/localizeHref.tsx"],"sourcesContent":["import {UrlObject} from 'url';\nimport localizePathname from '../shared/localizePathname';\nimport getCookieLocale from './getCookieLocale';\nimport hasPathnamePrefixed from './hasPathnamePrefixed';\n\nexport default function localizeHref(href: string, locale?: string): string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale?: string\n): UrlObject | string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale?: string\n) {\n const cookieLocale = getCookieLocale();\n if (!locale) locale = cookieLocale;\n\n const {pathname} = window.location;\n const isSwitchingLocale = locale !== cookieLocale;\n const isPathnamePrefixed = hasPathnamePrefixed(locale, pathname);\n\n if (isPathnamePrefixed || isSwitchingLocale) {\n let prefixedHref;\n if (typeof href === 'string') {\n prefixedHref = localizePathname(locale, href);\n } else {\n prefixedHref = {...href};\n if (href.pathname) {\n prefixedHref.pathname = localizePathname(locale, href.pathname);\n }\n }\n\n return prefixedHref;\n } else {\n return href;\n }\n}\n"],"names":["localizeHref","href","locale","cookieLocale","getCookieLocale","pathname","window","location","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","prefixedHref","localizePathname"],"mappings":";;;;;AAUc,SAAUA,YAAV,CACZC,IADY,EAEZC,MAFY,EAEG;AAEf,EAAMC,IAAAA,YAAY,GAAGC,eAAe,EAApC,CAAA;AACA,EAAA,IAAI,CAACF,MAAL,EAAaA,MAAM,GAAGC,YAAT,CAAA;AAEb,EAAA,IAAOE,QAAP,GAAmBC,MAAM,CAACC,QAA1B,CAAOF,QAAP,CAAA;AACA,EAAA,IAAMG,iBAAiB,GAAGN,MAAM,KAAKC,YAArC,CAAA;AACA,EAAA,IAAMM,kBAAkB,GAAGC,mBAAmB,CAACR,MAAD,EAASG,QAAT,CAA9C,CAAA;;AAEA,EAAII,IAAAA,kBAAkB,IAAID,iBAA1B,EAA6C;AAC3C,IAAA,IAAIG,YAAJ,CAAA;;AACA,IAAA,IAAI,OAAOV,IAAP,KAAgB,QAApB,EAA8B;AAC5BU,MAAAA,YAAY,GAAGC,gBAAgB,CAACV,MAAD,EAASD,IAAT,CAA/B,CAAA;AACD,KAFD,MAEO;AACLU,MAAAA,YAAY,GAAOV,QAAAA,CAAAA,EAAAA,EAAAA,IAAP,CAAZ,CAAA;;AACA,MAAIA,IAAAA,IAAI,CAACI,QAAT,EAAmB;AACjBM,QAAAA,YAAY,CAACN,QAAb,GAAwBO,gBAAgB,CAACV,MAAD,EAASD,IAAI,CAACI,QAAd,CAAxC,CAAA;AACD,OAAA;AACF,KAAA;;AAED,IAAA,OAAOM,YAAP,CAAA;AACD,GAZD,MAYO;AACL,IAAA,OAAOV,IAAP,CAAA;AACD,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"next-intl.esm.js","sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n"],"names":["useRouter","router","useNextRouter","locale","useClientLocale","useMemo","localize","href","localizeHref","window","location","pathname","_extends","push","replace","prefetch"],"mappings":";;;;;;AAKA;;;;;;;;;;;;;;;AAeG;AACW,SAAUA,SAASA,GAAA;AAC/B,EAAA,IAAMC,MAAM,GAAGC,WAAa,EAAE,CAAA;AAC9B,EAAA,IAAMC,MAAM,GAAGC,eAAe,EAAE,CAAA;EAEhC,OAAOC,OAAO,CAAC,YAAK;IAClB,SAASC,QAAQA,CAACC,IAAY,EAAA;AAC5B,MAAA,OAAOC,YAAY,CAACD,IAAI,EAAEJ,MAAM,EAAEA,MAAM,EAAEM,MAAM,CAACC,QAAQ,CAACC,QAAQ,CAAC,CAAA;AACrE,KAAA;IAEA,OAAAC,QAAA,KACKX,MAAM,EAAA;MACTY,IAAI,EAAA,SAAAA,IAACN,CAAAA,IAAY,EAAA;QACf,OAAON,MAAM,CAACY,IAAI,CAACP,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;OACnC;MACDO,OAAO,EAAA,SAAAA,OAACP,CAAAA,IAAY,EAAA;QAClB,OAAON,MAAM,CAACa,OAAO,CAACR,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;OACtC;MACDQ,QAAQ,EAAA,SAAAA,QAACR,CAAAA,IAAY,EAAA;QACnB,OAAON,MAAM,CAACc,QAAQ,CAACT,QAAQ,CAACC,IAAI,CAAC,CAAC,CAAA;AACxC,OAAA;AAAC,KAAA,CAAA,CAAA;AAEL,GAAC,EAAE,CAACJ,MAAM,EAAEF,MAAM,CAAC,CAAC,CAAA;AACtB;;;;"}
@@ -1,24 +1,18 @@
1
- import { extends as _extends } from '../_virtual/next-intl.esm.js';
2
- import { useRouter as useRouter$1 } from 'next/navigation';
3
- import { useMemo } from 'react';
4
- import localizeHref from './next-intl.esm.js';
1
+ import { useParams } from 'next/navigation';
2
+ import { useLocale } from 'use-intl';
3
+ import { LOCALE_SEGMENT_NAME } from '../shared/next-intl.esm4.js';
5
4
 
6
- function useRouter() {
7
- var router = useRouter$1();
8
- return useMemo(function () {
9
- return _extends({}, router, {
10
- push: function push(href) {
11
- return router.push(localizeHref(href));
12
- },
13
- replace: function replace(href) {
14
- return router.replace(localizeHref(href));
15
- },
16
- prefetch: function prefetch(href) {
17
- return router.prefetch(localizeHref(href));
18
- }
19
- });
20
- }, [router]);
5
+ function useClientLocale() {
6
+ var locale;
7
+ var params = useParams();
8
+ if (params[LOCALE_SEGMENT_NAME]) {
9
+ locale = params[LOCALE_SEGMENT_NAME];
10
+ } else {
11
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine
12
+ locale = useLocale();
13
+ }
14
+ return locale;
21
15
  }
22
16
 
23
- export { useRouter as default };
17
+ export { useClientLocale as default };
24
18
  //# sourceMappingURL=next-intl.esm2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm2.js","sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport localizeHref from './localizeHref';\n\nexport default function useRouter() {\n const router = useNextRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(href));\n },\n replace(href: string) {\n return router.replace(localizeHref(href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(href));\n }\n }),\n [router]\n );\n}\n"],"names":["useRouter","router","useNextRouter","useMemo","push","href","localizeHref","replace","prefetch"],"mappings":";;;;;AAIc,SAAUA,SAAV,GAAmB;AAC/B,EAAMC,IAAAA,MAAM,GAAGC,WAAa,EAA5B,CAAA;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OAAA,QAAA,CAAA,EAAA,EACKF,MADL,EAAA;AAEEG,MAAAA,IAFF,EAEOC,SAAAA,IAAAA,CAAAA,IAFP,EAEmB;AACf,QAAOJ,OAAAA,MAAM,CAACG,IAAP,CAAYE,YAAY,CAACD,IAAD,CAAxB,CAAP,CAAA;AACD,OAJH;AAKEE,MAAAA,OALF,EAKUF,SAAAA,OAAAA,CAAAA,IALV,EAKsB;AAClB,QAAOJ,OAAAA,MAAM,CAACM,OAAP,CAAeD,YAAY,CAACD,IAAD,CAA3B,CAAP,CAAA;AACD,OAPH;AAQEG,MAAAA,QARF,EAQWH,SAAAA,QAAAA,CAAAA,IARX,EAQuB;AACnB,QAAOJ,OAAAA,MAAM,CAACO,QAAP,CAAgBF,YAAY,CAACD,IAAD,CAA5B,CAAP,CAAA;AACD,OAAA;AAVH,KAAA,CAAA,CAAA;AAAA,GADY,EAaZ,CAACJ,MAAD,CAbY,CAAd,CAAA;AAeD;;;;"}
1
+ {"version":3,"file":"next-intl.esm2.js","sources":["../../src/client/useClientLocale.tsx"],"sourcesContent":["import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n"],"names":["useClientLocale","locale","params","useParams","LOCALE_SEGMENT_NAME","useLocale"],"mappings":";;;;AAIc,SAAUA,eAAeA,GAAA;AACrC,EAAA,IAAIC,MAAM,CAAA;AAEV,EAAA,IAAMC,MAAM,GAAGC,SAAS,EAAE,CAAA;AAC1B,EAAA,IAAID,MAAM,CAACE,mBAAmB,CAAC,EAAE;AAC/BH,IAAAA,MAAM,GAAGC,MAAM,CAACE,mBAAmB,CAAC,CAAA;AACrC,GAAA,MAAM;AACL;IACAH,MAAM,GAAGI,SAAS,EAAE,CAAA;AACrB,GAAA;AAED,EAAA,OAAOJ,MAAM,CAAA;AACf;;;;"}
@@ -0,0 +1 @@
1
+ export default function useClientLocale(): string;
@@ -1,11 +1,14 @@
1
- export declare function unlocalizePathname(pathname: string): string;
2
1
  /**
3
2
  * Returns the pathname without a potential locale prefix.
4
3
  *
5
- * Note that on the server side `null` is returned, only on
6
- * the client side the correct pathname will be returned.
4
+ * @example
5
+ * ```tsx
6
+ * 'use client';
7
7
  *
8
- * This can be helpful e.g. to implement navigation links,
9
- * where the active link is highlighted.
8
+ * import {usePathname} from 'next-intl/client';
9
+ *
10
+ * // When the user is on `/en`, this will be `/`
11
+ * const pathname = usePathname();
12
+ * ```
10
13
  */
11
- export default function usePathname(): string | null;
14
+ export default function usePathname(): string;
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Returns a wrapped instance of `useRouter` from `next/navigation` that
3
+ * will automatically localize the `href` parameters it receives.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * 'use client';
8
+ *
9
+ * import {useRouter} from 'next-intl/client';
10
+ *
11
+ * const router = useRouter();
12
+ *
13
+ * // When the user is on `/en`, the router will navigate to `/en/about`
14
+ * router.push('/about');
15
+ * ```
16
+ */
1
17
  export default function useRouter(): {
2
18
  push(href: string): void;
3
19
  replace(href: string): void;
package/dist/index.d.ts CHANGED
@@ -1,45 +1,8 @@
1
1
  /**
2
- * This is the main entry file when non-'react-server' environments import
3
- * from 'next-intl'. Make sure this mirrors the API from 'react-server'.
2
+ * This is the default entry file when consumers import from
3
+ * 'next-intl'. We use the client APIs in this case.
4
+ *
5
+ * Note that the `react-server` environment (i.e. RSC) imports
6
+ * from `./react-server` instead.
4
7
  */
5
- /// <reference types="react" />
6
- /// <reference types="node" />
7
- import NextIntlClientProvider from './shared/NextIntlClientProvider';
8
- export * from 'use-intl';
9
- export { default as useLocalizedRouter } from './react-client/useLocalizedRouter';
10
- export { default as Link } from './shared/Link';
11
- export { default as NextIntlClientProvider } from './shared/NextIntlClientProvider';
12
- /** @deprecated Is called `NextIntlClientProvider` now. */
13
- export declare const NextIntlProvider: typeof NextIntlClientProvider;
14
- /** @deprecated Is called `Link` now. */
15
- export declare const LocalizedLink: import("react").ForwardRefExoticComponent<Pick<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
16
- href: string | import("url").UrlObject;
17
- as?: (string | import("url").UrlObject) | undefined;
18
- replace?: boolean | undefined;
19
- scroll?: boolean | undefined;
20
- shallow?: boolean | undefined;
21
- passHref?: boolean | undefined;
22
- prefetch?: boolean | undefined;
23
- locale?: string | false | undefined;
24
- legacyBehavior?: boolean | undefined;
25
- onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
26
- onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
27
- onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
28
- }> & {
29
- href: string | import("url").UrlObject;
30
- as?: (string | import("url").UrlObject) | undefined;
31
- replace?: boolean | undefined;
32
- scroll?: boolean | undefined;
33
- shallow?: boolean | undefined;
34
- passHref?: boolean | undefined;
35
- prefetch?: boolean | undefined;
36
- locale?: string | false | undefined;
37
- legacyBehavior?: boolean | undefined;
38
- onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
39
- onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
40
- onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
41
- } & {
42
- children?: import("react").ReactNode;
43
- } & import("react").RefAttributes<HTMLAnchorElement>, "locale"> & {
44
- locale?: string | undefined;
45
- }, "href" | "as" | "replace" | "scroll" | "shallow" | "passHref" | "prefetch" | "locale" | "legacyBehavior" | "onMouseEnter" | "onTouchStart" | "onClick" | "download" | "hrefLang" | "media" | "ping" | "rel" | "target" | "type" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & import("react").RefAttributes<HTMLAnchorElement>>;
8
+ export * from './react-client';
@@ -0,0 +1,27 @@
1
+ import React, { ComponentProps } from 'react';
2
+ import BaseLink from '../shared/BaseLink';
3
+ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
4
+ locale?: string;
5
+ };
6
+ /**
7
+ * Wraps `next/link` and prefixes the `href` with the current locale if
8
+ * necessary.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import {Link} from 'next-intl';
13
+ *
14
+ * // When the user is on `/en`, the link will point to `/en/about`
15
+ * <Link href="/about">About</Link>
16
+ *
17
+ * // You can override the `locale` to switch to another language
18
+ * <Link href="/" locale="de">Switch to German</Link>
19
+ * ```
20
+ *
21
+ * Note that when a `locale` prop is passed to switch the locale, the `prefetch`
22
+ * prop is not supported. This is because Next.js would prefetch the page and
23
+ * the `set-cookie` response header would cause the locale cookie on the current
24
+ * page to be overwritten before the user even decides to change the locale.
25
+ */
26
+ declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
27
+ export default _default;
@@ -0,0 +1 @@
1
+ export { default } from './Link';
@@ -0,0 +1,39 @@
1
+ import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
2
+ import React, { forwardRef } from 'react';
3
+ import useClientLocale from '../client/next-intl.esm2.js';
4
+ import BaseLink from '../shared/next-intl.esm3.js';
5
+
6
+ var _excluded = ["locale"];
7
+ function Link(_ref, ref) {
8
+ var locale = _ref.locale,
9
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
10
+ var defaultLocale = useClientLocale();
11
+ return React.createElement(BaseLink, _extends({
12
+ ref: ref,
13
+ locale: locale || defaultLocale
14
+ }, rest));
15
+ }
16
+ /**
17
+ * Wraps `next/link` and prefixes the `href` with the current locale if
18
+ * necessary.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import {Link} from 'next-intl';
23
+ *
24
+ * // When the user is on `/en`, the link will point to `/en/about`
25
+ * <Link href="/about">About</Link>
26
+ *
27
+ * // You can override the `locale` to switch to another language
28
+ * <Link href="/" locale="de">Switch to German</Link>
29
+ * ```
30
+ *
31
+ * Note that when a `locale` prop is passed to switch the locale, the `prefetch`
32
+ * prop is not supported. This is because Next.js would prefetch the page and
33
+ * the `set-cookie` response header would cause the locale cookie on the current
34
+ * page to be overwritten before the user even decides to change the locale.
35
+ */
36
+ var Link$1 = /*#__PURE__*/forwardRef(Link);
37
+
38
+ export { Link$1 as default };
39
+ //# sourceMappingURL=next-intl.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-intl.esm.js","sources":["../../src/link/Link.tsx"],"sourcesContent":["import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n"],"names":["Link","_ref","ref","locale","rest","_objectWithoutPropertiesLoose","_excluded","defaultLocale","useClientLocale","React","createElement","BaseLink","_extends","forwardRef"],"mappings":";;;;;;AAQA,SAASA,IAAIA,CAAAC,IAAA,EAA2BC,GAAiB,EAAA;AAAA,EAAA,IAA1CC,MAAM,GAAAF,IAAA,CAANE,MAAM;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAJ,IAAA,EAAAK,SAAA,CAAA,CAAA;AAC5B,EAAA,IAAMC,aAAa,GAAGC,eAAe,EAAE,CAAA;AACvC,EAAA,OAAOC,KAAC,CAAAC,aAAA,CAAAC,QAAQ,EAAAC,QAAA,CAAA;AAACV,IAAAA,GAAG,EAAEA,GAAG;IAAEC,MAAM,EAAEA,MAAM,IAAII,aAAAA;GAAmBH,EAAAA,IAAI,EAAI,CAAA;AAC1E,CAAA;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;AACH,aAAeS,aAAAA,UAAU,CAACb,IAAI,CAAC;;;;"}
@@ -0,0 +1,7 @@
1
+ import { ComponentProps } from 'react';
2
+ import BaseLink from '../../shared/BaseLink';
3
+ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
4
+ locale?: string;
5
+ };
6
+ export default function Link({ locale, ...rest }: Props): JSX.Element;
7
+ export {};
@@ -0,0 +1 @@
1
+ export { default } from './Link';
@@ -0,0 +1,46 @@
1
+ type RoutingConfigPrefix = {
2
+ type: 'prefix';
3
+ /** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
4
+ */
5
+ prefix?: 'as-needed' | 'always';
6
+ };
7
+ type RoutingConfigDomain = {
8
+ type: 'domain';
9
+ /** Provide a list of mappings between domains and locales. Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
10
+ domains: Array<{
11
+ domain: string;
12
+ locale: string;
13
+ }>;
14
+ };
15
+ type LocalePrefix = 'as-needed' | 'always';
16
+ type RoutingBaseConfig = {
17
+ /** A list of all locales that are supported. */
18
+ locales: Array<string>;
19
+ defaultLocale: string;
20
+ /** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
21
+ */
22
+ localePrefix?: LocalePrefix;
23
+ };
24
+ export type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> & {
25
+ /** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
26
+ domain: string;
27
+ locales?: RoutingBaseConfig['locales'];
28
+ /** @deprecated Use `defaultLocale` instead. */
29
+ locale?: string;
30
+ };
31
+ type MiddlewareConfig = RoutingBaseConfig & {
32
+ /** Can be used to change the locale handling per domain. */
33
+ domains?: Array<DomainConfig>;
34
+ /** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
35
+ localeDetection?: boolean;
36
+ /** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
37
+ alternateLinks?: boolean;
38
+ /** @deprecated Deprecated in favor of `localePrefix` and `domains`. */
39
+ routing?: RoutingConfigPrefix | RoutingConfigDomain;
40
+ };
41
+ export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
42
+ alternateLinks: boolean;
43
+ localePrefix: LocalePrefix;
44
+ localeDetection: boolean;
45
+ };
46
+ export default MiddlewareConfig;
@@ -0,0 +1,6 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
3
+ /**
4
+ * See https://developers.google.com/search/docs/specialty/international/localized-versions
5
+ */
6
+ export default function getAlternateLinksHeaderValue(config: MiddlewareConfigWithDefaults, request: NextRequest): string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The middleware, available as `next-intl/middleware`.
3
+ */
4
+ export { default } from './middleware';
@@ -0,0 +1,3 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import MiddlewareConfig from './NextIntlMiddlewareConfig';
3
+ export default function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
@@ -0,0 +1,6 @@
1
+ import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
+ import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
3
+ export default function resolveLocale(config: MiddlewareConfigWithDefaults, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
4
+ locale: string;
5
+ domain?: DomainConfig;
6
+ };
@@ -0,0 +1,5 @@
1
+ import { DomainConfig } from './NextIntlMiddlewareConfig';
2
+ export declare function getLocaleFromPathname(pathname: string): string;
3
+ export declare function getHost(requestHeaders: Headers): string | undefined;
4
+ export declare function isLocaleSupportedOnDomain(locale: string, domain: DomainConfig): boolean;
5
+ export declare function getBestMatchingDomain(curHostDomain: DomainConfig | undefined, locale: string, domainConfigs: Array<DomainConfig>): DomainConfig | undefined;