next-intl 3.0.0-alpha.1 → 3.0.0-beta.2

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 (306) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -20
  3. package/config.js +3 -0
  4. package/dist/_virtual/next-intl.esm.js +29 -0
  5. package/dist/_virtual/next-intl.esm.js.map +1 -0
  6. package/dist/client/NextIntlClientProvider.d.ts +3 -6
  7. package/dist/client/index.d.ts +11 -0
  8. package/dist/client/next-intl.esm.js +45 -0
  9. package/dist/client/next-intl.esm.js.map +1 -0
  10. package/dist/client/next-intl.esm2.js +18 -0
  11. package/dist/client/next-intl.esm2.js.map +1 -0
  12. package/dist/client/useClientLocale.d.ts +1 -0
  13. package/dist/client/usePathname.d.ts +14 -0
  14. package/dist/client/useRouter.d.ts +24 -0
  15. package/dist/index.d.ts +8 -1
  16. package/dist/link/Link.d.ts +27 -0
  17. package/dist/link/index.d.ts +1 -0
  18. package/dist/link/next-intl.esm.js +39 -0
  19. package/dist/link/next-intl.esm.js.map +1 -0
  20. package/dist/link/react-server/Link.d.ts +7 -0
  21. package/dist/link/react-server/index.d.ts +1 -0
  22. package/dist/middleware/NextIntlMiddlewareConfig.d.ts +46 -0
  23. package/dist/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  24. package/dist/middleware/index.d.ts +4 -0
  25. package/dist/middleware/middleware.d.ts +3 -0
  26. package/dist/middleware/resolveLocale.d.ts +6 -0
  27. package/dist/middleware/utils.d.ts +5 -0
  28. package/dist/next-intl.cjs.development.js +288 -4
  29. package/dist/next-intl.cjs.development.js.map +1 -1
  30. package/dist/next-intl.cjs.production.min.js +1 -1
  31. package/dist/next-intl.cjs.production.min.js.map +1 -1
  32. package/dist/next-intl.esm.js +4 -0
  33. package/dist/next-intl.esm.js.map +1 -1
  34. package/dist/react-client/Link.d.ts +4 -0
  35. package/dist/react-client/index.d.ts +17 -0
  36. package/dist/react-client/next-intl.esm.js +21 -0
  37. package/dist/react-client/next-intl.esm.js.map +1 -0
  38. package/dist/react-client/next-intl.esm2.js +18 -0
  39. package/dist/react-client/next-intl.esm2.js.map +1 -0
  40. package/dist/react-client/next-intl.esm3.js +15 -0
  41. package/dist/react-client/next-intl.esm3.js.map +1 -0
  42. package/dist/react-client/useLocalizedRouter.d.ts +8 -0
  43. package/dist/react-server/Link.d.ts +4 -0
  44. package/dist/react-server/index.d.ts +13 -0
  45. package/dist/react-server/useFormatter.d.ts +2 -0
  46. package/dist/react-server/useHook.d.ts +1 -0
  47. package/dist/react-server/useIntl.d.ts +1 -1
  48. package/dist/react-server/useLocale.d.ts +2 -2
  49. package/dist/react-server/useNow.d.ts +2 -1
  50. package/dist/react-server/useTimeZone.d.ts +2 -1
  51. package/dist/react-server/useTranslations.d.ts +2 -2
  52. package/dist/server/createRequestConfig.d.ts +4 -0
  53. package/dist/server/getConfig.d.ts +23 -0
  54. package/dist/server/getFormatter.d.ts +7 -0
  55. package/dist/server/getIntl.d.ts +7 -0
  56. package/dist/server/getLocale.d.ts +2 -0
  57. package/dist/server/getNow.d.ts +2 -0
  58. package/dist/server/getRequestConfig.d.ts +10 -0
  59. package/dist/server/getTimeZone.d.ts +2 -0
  60. package/dist/server/getTranslations.d.ts +38 -0
  61. package/dist/server/index.d.ts +14 -2
  62. package/dist/server/react-client/index.d.ts +8 -0
  63. package/dist/server/react-client/redirect.d.ts +1 -0
  64. package/dist/server/redirect.d.ts +1 -0
  65. package/dist/shared/BaseLink.d.ts +7 -0
  66. package/dist/shared/NextIntlClientProvider.d.ts +9 -0
  67. package/dist/shared/constants.d.ts +3 -0
  68. package/dist/shared/next-intl.esm.js +41 -0
  69. package/dist/shared/next-intl.esm.js.map +1 -0
  70. package/dist/shared/next-intl.esm2.js +55 -0
  71. package/dist/shared/next-intl.esm2.js.map +1 -0
  72. package/dist/shared/next-intl.esm3.js +49 -0
  73. package/dist/shared/next-intl.esm3.js.map +1 -0
  74. package/dist/shared/next-intl.esm4.js +6 -0
  75. package/dist/shared/next-intl.esm4.js.map +1 -0
  76. package/dist/shared/redirect.d.ts +1 -0
  77. package/dist/shared/utils.d.ts +15 -0
  78. package/dist/src/client/NextIntlClientProvider.d.ts +3 -6
  79. package/dist/src/client/NextIntlClientProvider.js +12 -23
  80. package/dist/src/client/NextIntlClientProvider.js.map +1 -1
  81. package/dist/src/client/index.d.ts +11 -0
  82. package/dist/src/client/index.js +12 -0
  83. package/dist/src/client/index.js.map +1 -1
  84. package/dist/src/client/useClientLocale.d.ts +1 -0
  85. package/dist/src/client/useClientLocale.js +16 -0
  86. package/dist/src/client/useClientLocale.js.map +1 -0
  87. package/dist/src/client/usePathname.d.ts +14 -0
  88. package/dist/src/client/usePathname.js +30 -0
  89. package/dist/src/client/usePathname.js.map +1 -0
  90. package/dist/src/client/useRouter.d.ts +24 -0
  91. package/dist/src/client/useRouter.js +42 -0
  92. package/dist/src/client/useRouter.js.map +1 -0
  93. package/dist/src/index.d.ts +8 -1
  94. package/dist/src/index.js +8 -1
  95. package/dist/src/index.js.map +1 -1
  96. package/dist/src/link/Link.d.ts +27 -0
  97. package/dist/src/link/Link.js +29 -0
  98. package/dist/src/link/Link.js.map +1 -0
  99. package/dist/src/link/index.d.ts +1 -0
  100. package/dist/src/link/index.js +2 -0
  101. package/dist/src/link/index.js.map +1 -0
  102. package/dist/src/link/react-server/Link.d.ts +7 -0
  103. package/dist/src/link/react-server/Link.js +8 -0
  104. package/dist/src/link/react-server/Link.js.map +1 -0
  105. package/dist/src/link/react-server/index.d.ts +1 -0
  106. package/dist/src/link/react-server/index.js +2 -0
  107. package/dist/src/link/react-server/index.js.map +1 -0
  108. package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +46 -0
  109. package/dist/src/middleware/NextIntlMiddlewareConfig.js +2 -0
  110. package/dist/src/middleware/NextIntlMiddlewareConfig.js.map +1 -0
  111. package/dist/src/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  112. package/dist/src/middleware/getAlternateLinksHeaderValue.js +64 -0
  113. package/dist/src/middleware/getAlternateLinksHeaderValue.js.map +1 -0
  114. package/dist/src/middleware/index.d.ts +4 -0
  115. package/dist/src/middleware/index.js +5 -0
  116. package/dist/src/middleware/index.js.map +1 -0
  117. package/dist/src/middleware/middleware.d.ts +3 -0
  118. package/dist/src/middleware/middleware.js +183 -0
  119. package/dist/src/middleware/middleware.js.map +1 -0
  120. package/dist/src/middleware/resolveLocale.d.ts +6 -0
  121. package/dist/src/middleware/resolveLocale.js +88 -0
  122. package/dist/src/middleware/resolveLocale.js.map +1 -0
  123. package/dist/src/middleware/utils.d.ts +5 -0
  124. package/dist/src/middleware/utils.js +37 -0
  125. package/dist/src/middleware/utils.js.map +1 -0
  126. package/dist/src/react-client/Link.d.ts +4 -0
  127. package/dist/src/react-client/Link.js +19 -0
  128. package/dist/src/react-client/Link.js.map +1 -0
  129. package/dist/src/react-client/index.d.ts +17 -0
  130. package/dist/src/react-client/index.js +19 -0
  131. package/dist/src/react-client/index.js.map +1 -0
  132. package/dist/src/react-client/useLocalizedRouter.d.ts +8 -0
  133. package/dist/src/react-client/useLocalizedRouter.js +12 -0
  134. package/dist/src/react-client/useLocalizedRouter.js.map +1 -0
  135. package/dist/src/react-server/Link.d.ts +4 -0
  136. package/dist/src/react-server/Link.js +19 -0
  137. package/dist/src/react-server/Link.js.map +1 -0
  138. package/dist/src/react-server/index.d.ts +13 -0
  139. package/dist/src/react-server/index.js +14 -2
  140. package/dist/src/react-server/index.js.map +1 -1
  141. package/dist/src/react-server/useFormatter.d.ts +2 -0
  142. package/dist/src/react-server/useFormatter.js +8 -0
  143. package/dist/src/react-server/useFormatter.js.map +1 -0
  144. package/dist/src/react-server/useHook.d.ts +1 -0
  145. package/dist/src/react-server/useHook.js +28 -0
  146. package/dist/src/react-server/useHook.js.map +1 -0
  147. package/dist/src/react-server/useIntl.d.ts +1 -1
  148. package/dist/src/react-server/useIntl.js +8 -2
  149. package/dist/src/react-server/useIntl.js.map +1 -1
  150. package/dist/src/react-server/useLocale.d.ts +2 -2
  151. package/dist/src/react-server/useLocale.js +5 -4
  152. package/dist/src/react-server/useLocale.js.map +1 -1
  153. package/dist/src/react-server/useNow.d.ts +2 -1
  154. package/dist/src/react-server/useNow.js +7 -3
  155. package/dist/src/react-server/useNow.js.map +1 -1
  156. package/dist/src/react-server/useTimeZone.d.ts +2 -1
  157. package/dist/src/react-server/useTimeZone.js +6 -3
  158. package/dist/src/react-server/useTimeZone.js.map +1 -1
  159. package/dist/src/react-server/useTranslations.d.ts +2 -2
  160. package/dist/src/react-server/useTranslations.js +7 -9
  161. package/dist/src/react-server/useTranslations.js.map +1 -1
  162. package/dist/src/server/createRequestConfig.d.ts +4 -0
  163. package/dist/src/server/createRequestConfig.js +5 -0
  164. package/dist/src/server/createRequestConfig.js.map +1 -0
  165. package/dist/src/server/getConfig.d.ts +23 -0
  166. package/dist/src/server/getConfig.js +23 -0
  167. package/dist/src/server/getConfig.js.map +1 -0
  168. package/dist/src/server/getFormatter.d.ts +7 -0
  169. package/dist/src/server/getFormatter.js +9 -0
  170. package/dist/src/server/getFormatter.js.map +1 -0
  171. package/dist/src/server/getIntl.d.ts +7 -0
  172. package/dist/src/server/getIntl.js +15 -0
  173. package/dist/src/server/getIntl.js.map +1 -0
  174. package/dist/src/server/getLocale.d.ts +2 -0
  175. package/dist/src/server/getLocale.js +33 -0
  176. package/dist/src/server/getLocale.js.map +1 -0
  177. package/dist/src/server/getNow.d.ts +2 -0
  178. package/dist/src/server/getNow.js +8 -0
  179. package/dist/src/server/getNow.js.map +1 -0
  180. package/dist/src/server/getRequestConfig.d.ts +10 -0
  181. package/dist/src/server/getRequestConfig.js +7 -0
  182. package/dist/src/server/getRequestConfig.js.map +1 -0
  183. package/dist/src/server/getTimeZone.d.ts +2 -0
  184. package/dist/src/server/getTimeZone.js +8 -0
  185. package/dist/src/server/getTimeZone.js.map +1 -0
  186. package/dist/src/server/getTranslations.d.ts +38 -0
  187. package/dist/src/server/getTranslations.js +23 -0
  188. package/dist/src/server/getTranslations.js.map +1 -0
  189. package/dist/src/server/index.d.ts +14 -2
  190. package/dist/src/server/index.js +37 -2
  191. package/dist/src/server/index.js.map +1 -1
  192. package/dist/src/server/react-client/index.d.ts +8 -0
  193. package/dist/src/server/react-client/index.js +15 -0
  194. package/dist/src/server/react-client/index.js.map +1 -0
  195. package/dist/src/server/react-client/redirect.d.ts +1 -0
  196. package/dist/src/server/react-client/redirect.js +8 -0
  197. package/dist/src/server/react-client/redirect.js.map +1 -0
  198. package/dist/src/server/redirect.d.ts +1 -0
  199. package/dist/src/server/redirect.js +7 -0
  200. package/dist/src/server/redirect.js.map +1 -0
  201. package/dist/src/shared/BaseLink.d.ts +7 -0
  202. package/dist/src/shared/BaseLink.js +34 -0
  203. package/dist/src/shared/BaseLink.js.map +1 -0
  204. package/dist/src/shared/NextIntlClientProvider.d.ts +9 -0
  205. package/dist/src/shared/NextIntlClientProvider.js +33 -0
  206. package/dist/src/shared/NextIntlClientProvider.js.map +1 -0
  207. package/dist/src/shared/constants.d.ts +3 -0
  208. package/dist/src/shared/constants.js +8 -0
  209. package/dist/src/shared/constants.js.map +1 -0
  210. package/dist/src/shared/redirect.d.ts +1 -0
  211. package/dist/src/shared/redirect.js +7 -0
  212. package/dist/src/shared/redirect.js.map +1 -0
  213. package/dist/src/shared/utils.d.ts +15 -0
  214. package/dist/src/shared/utils.js +53 -0
  215. package/dist/src/shared/utils.js.map +1 -0
  216. package/link.d.ts +1 -0
  217. package/middleware.d.ts +1 -0
  218. package/package.json +48 -28
  219. package/plugin.d.ts +3 -0
  220. package/plugin.js +65 -0
  221. package/src/client/NextIntlClientProvider.tsx +13 -31
  222. package/src/client/index.tsx +17 -0
  223. package/src/client/useClientLocale.tsx +17 -0
  224. package/src/client/usePathname.tsx +33 -0
  225. package/src/client/useRouter.tsx +44 -0
  226. package/src/index.tsx +9 -1
  227. package/src/link/Link.tsx +34 -0
  228. package/src/link/index.tsx +1 -0
  229. package/src/link/react-server/Link.tsx +12 -0
  230. package/src/link/react-server/index.tsx +1 -0
  231. package/src/middleware/NextIntlMiddlewareConfig.tsx +63 -0
  232. package/src/middleware/getAlternateLinksHeaderValue.tsx +90 -0
  233. package/src/middleware/index.tsx +5 -0
  234. package/src/middleware/middleware.tsx +253 -0
  235. package/src/middleware/resolveLocale.tsx +151 -0
  236. package/src/middleware/utils.tsx +61 -0
  237. package/src/react-client/Link.tsx +24 -0
  238. package/src/react-client/index.tsx +23 -0
  239. package/src/react-client/useLocalizedRouter.tsx +17 -0
  240. package/src/react-server/Link.tsx +24 -0
  241. package/src/react-server/index.tsx +18 -2
  242. package/src/react-server/useFormatter.tsx +10 -0
  243. package/src/react-server/useHook.tsx +34 -0
  244. package/src/react-server/useIntl.tsx +12 -2
  245. package/src/react-server/useLocale.tsx +7 -4
  246. package/src/react-server/useNow.tsx +13 -3
  247. package/src/react-server/useTimeZone.tsx +8 -3
  248. package/src/react-server/useTranslations.tsx +10 -10
  249. package/src/server/createRequestConfig.tsx +9 -0
  250. package/src/server/getConfig.tsx +27 -0
  251. package/src/server/getFormatter.tsx +10 -0
  252. package/src/server/getIntl.tsx +20 -0
  253. package/src/server/getLocale.tsx +40 -0
  254. package/src/server/getNow.tsx +9 -0
  255. package/src/server/getRequestConfig.tsx +18 -0
  256. package/src/server/getTimeZone.tsx +9 -0
  257. package/src/server/getTranslations.tsx +102 -0
  258. package/src/server/index.tsx +44 -2
  259. package/src/server/react-client/index.tsx +16 -0
  260. package/src/server/react-client/redirect.tsx +8 -0
  261. package/src/server/redirect.tsx +7 -0
  262. package/src/shared/BaseLink.tsx +52 -0
  263. package/src/shared/NextIntlClientProvider.tsx +54 -0
  264. package/src/shared/constants.tsx +9 -0
  265. package/src/shared/redirect.tsx +7 -0
  266. package/src/shared/utils.tsx +91 -0
  267. package/withNextIntl.d.ts +5 -0
  268. package/withNextIntl.js +13 -0
  269. package/CHANGELOG.md +0 -472
  270. package/client.js +0 -1
  271. package/dist/server/NextI18nConfig.d.ts +0 -5
  272. package/dist/server/NextIntlCookie.d.ts +0 -11
  273. package/dist/server/NextIntlRequestStorage.d.ts +0 -24
  274. package/dist/server/NextIntlServerProvider.d.ts +0 -3
  275. package/dist/server/NextRequestStorage.d.ts +0 -14
  276. package/dist/server/createIntlMiddleware.d.ts +0 -3
  277. package/dist/server/resolveLocale.d.ts +0 -4
  278. package/dist/src/server/NextI18nConfig.d.ts +0 -5
  279. package/dist/src/server/NextI18nConfig.js +0 -2
  280. package/dist/src/server/NextI18nConfig.js.map +0 -1
  281. package/dist/src/server/NextIntlCookie.d.ts +0 -11
  282. package/dist/src/server/NextIntlCookie.js +0 -19
  283. package/dist/src/server/NextIntlCookie.js.map +0 -1
  284. package/dist/src/server/NextIntlRequestStorage.d.ts +0 -24
  285. package/dist/src/server/NextIntlRequestStorage.js +0 -45
  286. package/dist/src/server/NextIntlRequestStorage.js.map +0 -1
  287. package/dist/src/server/NextIntlServerProvider.d.ts +0 -3
  288. package/dist/src/server/NextIntlServerProvider.js +0 -13
  289. package/dist/src/server/NextIntlServerProvider.js.map +0 -1
  290. package/dist/src/server/NextRequestStorage.d.ts +0 -14
  291. package/dist/src/server/NextRequestStorage.js +0 -28
  292. package/dist/src/server/NextRequestStorage.js.map +0 -1
  293. package/dist/src/server/createIntlMiddleware.d.ts +0 -3
  294. package/dist/src/server/createIntlMiddleware.js +0 -22
  295. package/dist/src/server/createIntlMiddleware.js.map +0 -1
  296. package/dist/src/server/resolveLocale.d.ts +0 -4
  297. package/dist/src/server/resolveLocale.js +0 -37
  298. package/dist/src/server/resolveLocale.js.map +0 -1
  299. package/server.js +0 -1
  300. package/src/server/NextI18nConfig.tsx +0 -7
  301. package/src/server/NextIntlCookie.tsx +0 -33
  302. package/src/server/NextIntlRequestStorage.tsx +0 -67
  303. package/src/server/NextIntlServerProvider.tsx +0 -17
  304. package/src/server/NextRequestStorage.tsx +0 -35
  305. package/src/server/createIntlMiddleware.tsx +0 -33
  306. package/src/server/resolveLocale.tsx +0 -56
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,41 +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
 
16
+ <hr />
17
+
18
+ 📣 [Support for Next.js 13 and the App Router has arrived →](https://next-intl-docs.vercel.app/docs/next-13)
19
+
20
+ <hr />
21
+
14
22
  ## Features
15
23
 
16
- 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.
17
25
 
18
- - 🌟 **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.
19
- - 📅 **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.
20
- - 💡 **Hooks-only API**: This ensures that you can use the same API for `children` as well as for attributes which expect strings.
21
- - **Type-safe**: If you're using TypeScript, you'll benefit from autocompletion for available message keys and compile-time errors for typos.
22
- - ⚔️ **Battle-tested building blocks**: This library is a minimal wrapper around built-in browser APIs and supplemental lower-level APIs from Format.JS.
23
- - 🚀 **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.
24
32
 
25
33
  ## What does it look like?
26
34
 
27
35
  This library is based on the premise that messages can be grouped by namespaces (typically a component name).
28
36
 
29
37
  ```jsx
30
- // LatestFollower.js
31
- function LatestFollower({user}) {
32
- const t = useTranslations('LatestFollower');
33
-
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
+
34
45
  return (
35
- <>
36
- <Text>{t('latestFollower', {username: user.name})}</Text>
37
- <IconButton aria-label={t('followBack')} icon={<FollowIcon />} />
38
- </>
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>
39
52
  );
40
53
  }
41
54
  ```
@@ -43,11 +56,24 @@ function LatestFollower({user}) {
43
56
  ```js
44
57
  // en.json
45
58
  {
46
- "LatestFollower": {
47
- "latestFollower": "{username} started following you",
48
- "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}"
49
68
  }
50
69
  }
51
70
  ```
52
71
 
53
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>
package/config.js ADDED
@@ -0,0 +1,3 @@
1
+ throw new Error(
2
+ "Couldn't find next-intl config file. Please follow the instructions at https://next-intl-docs.vercel.app/docs/next-13/server-components"
3
+ );
@@ -0,0 +1,29 @@
1
+ function _extends() {
2
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3
+ for (var i = 1; i < arguments.length; i++) {
4
+ var source = arguments[i];
5
+ for (var key in source) {
6
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
7
+ target[key] = source[key];
8
+ }
9
+ }
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
15
+ function _objectWithoutPropertiesLoose(source, excluded) {
16
+ if (source == null) return {};
17
+ var target = {};
18
+ var sourceKeys = Object.keys(source);
19
+ var key, i;
20
+ for (i = 0; i < sourceKeys.length; i++) {
21
+ key = sourceKeys[i];
22
+ if (excluded.indexOf(key) >= 0) continue;
23
+ target[key] = source[key];
24
+ }
25
+ return target;
26
+ }
27
+
28
+ export { _extends as extends, _objectWithoutPropertiesLoose as objectWithoutPropertiesLoose };
29
+ //# sourceMappingURL=next-intl.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,7 +1,4 @@
1
1
  import { ComponentProps } from 'react';
2
- import { IntlProvider } from 'use-intl';
3
- declare type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {
4
- locale?: string;
5
- };
6
- export default function NextIntlProvider({ locale, ...rest }: Props): JSX.Element;
7
- export {};
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 +1,12 @@
1
+ /**
2
+ * Client-only APIs available via `next-intl/client`.
3
+ */
4
+ import usePathname from './usePathname';
5
+ import useRouter from './useRouter';
6
+ export { default as useRouter } from './useRouter';
7
+ export { default as usePathname } from './usePathname';
8
+ /** @deprecated Is called `usePathname` now. */
9
+ export declare const useUnlocalizedPathname: typeof usePathname;
10
+ /** @deprecated Is called `useRouter` now. */
11
+ export declare const useLocalizedRouter: typeof useRouter;
1
12
  export { default as NextIntlClientProvider } from './NextIntlClientProvider';
@@ -0,0 +1,45 @@
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 '../shared/next-intl.esm2.js';
5
+ import useClientLocale from './next-intl.esm2.js';
6
+
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);
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]);
42
+ }
43
+
44
+ export { useRouter as default };
45
+ //# sourceMappingURL=next-intl.esm.js.map
@@ -0,0 +1 @@
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;;;;"}
@@ -0,0 +1,18 @@
1
+ import { useParams } from 'next/navigation';
2
+ import { useLocale } from 'use-intl';
3
+ import { LOCALE_SEGMENT_NAME } from '../shared/next-intl.esm4.js';
4
+
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;
15
+ }
16
+
17
+ export { useClientLocale as default };
18
+ //# sourceMappingURL=next-intl.esm2.js.map
@@ -0,0 +1 @@
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;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns the pathname without a potential locale prefix.
3
+ *
4
+ * @example
5
+ * ```tsx
6
+ * 'use client';
7
+ *
8
+ * import {usePathname} from 'next-intl/client';
9
+ *
10
+ * // When the user is on `/en`, this will be `/`
11
+ * const pathname = usePathname();
12
+ * ```
13
+ */
14
+ export default function usePathname(): string;
@@ -0,0 +1,24 @@
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
+ */
17
+ export default function useRouter(): {
18
+ push(href: string): void;
19
+ replace(href: string): void;
20
+ prefetch(href: string): void;
21
+ back(): void;
22
+ forward(): void;
23
+ refresh(): void;
24
+ };
package/dist/index.d.ts CHANGED
@@ -1 +1,8 @@
1
- export * from 'use-intl';
1
+ /**
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.
7
+ */
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;