next-intl 2.14.0-beta.2 → 2.14.0-beta.4

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 (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -3
  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/localizeHref.d.ts +2 -2
  6. package/dist/client/next-intl.esm.js +21 -32
  7. package/dist/client/next-intl.esm.js.map +1 -1
  8. package/dist/client/next-intl.esm2.js +14 -20
  9. package/dist/client/next-intl.esm2.js.map +1 -1
  10. package/dist/client/next-intl.esm3.js +18 -4
  11. package/dist/client/next-intl.esm3.js.map +1 -1
  12. package/dist/client/next-intl.esm4.js +4 -20
  13. package/dist/client/next-intl.esm4.js.map +1 -1
  14. package/dist/client/useClientLocale.d.ts +1 -0
  15. package/dist/client/usePathname.d.ts +1 -5
  16. package/dist/index.d.ts +3 -36
  17. package/dist/middleware/NextIntlMiddlewareConfig.d.ts +7 -7
  18. package/dist/next-intl.cjs.development.js +111 -125
  19. package/dist/next-intl.cjs.development.js.map +1 -1
  20. package/dist/next-intl.cjs.production.min.js +1 -1
  21. package/dist/next-intl.cjs.production.min.js.map +1 -1
  22. package/dist/next-intl.esm.js +3 -4
  23. package/dist/next-intl.esm.js.map +1 -1
  24. package/dist/react-client/Link.d.ts +16 -0
  25. package/dist/react-client/next-intl.esm.js +2 -3
  26. package/dist/react-client/next-intl.esm.js.map +1 -1
  27. package/dist/react-client/next-intl.esm2.js +26 -0
  28. package/dist/react-client/next-intl.esm2.js.map +1 -0
  29. package/dist/react-server/Link.d.ts +7 -0
  30. package/dist/react-server/index.d.ts +3 -34
  31. package/dist/server/getFormatter.d.ts +1 -1
  32. package/dist/server/getIntl.d.ts +1 -1
  33. package/dist/server/getRequestConfig.d.ts +3 -3
  34. package/dist/shared/BaseLink.d.ts +7 -0
  35. package/dist/shared/NextIntlClientProvider.d.ts +1 -1
  36. package/dist/shared/constants.d.ts +1 -0
  37. package/dist/shared/isLocalUrl.d.ts +5 -0
  38. package/dist/shared/next-intl.esm.js +36 -65
  39. package/dist/shared/next-intl.esm.js.map +1 -1
  40. package/dist/shared/next-intl.esm2.js +48 -41
  41. package/dist/shared/next-intl.esm2.js.map +1 -1
  42. package/dist/shared/next-intl.esm3.js +7 -8
  43. package/dist/shared/next-intl.esm3.js.map +1 -1
  44. package/dist/shared/next-intl.esm4.js +16 -4
  45. package/dist/shared/next-intl.esm4.js.map +1 -1
  46. package/dist/shared/next-intl.esm5.js +6 -0
  47. package/dist/shared/next-intl.esm5.js.map +1 -0
  48. package/dist/shared/next-intl.esm6.js +10 -0
  49. package/dist/shared/next-intl.esm6.js.map +1 -0
  50. package/dist/shared/prefixHref.d.ts +4 -0
  51. package/dist/shared/unlocalizePathname.d.ts +1 -0
  52. package/dist/src/client/localizeHref.d.ts +2 -2
  53. package/dist/src/client/localizeHref.js +8 -23
  54. package/dist/src/client/localizeHref.js.map +1 -1
  55. package/dist/src/client/useClientLocale.d.ts +1 -0
  56. package/dist/src/client/useClientLocale.js +16 -0
  57. package/dist/src/client/useClientLocale.js.map +1 -0
  58. package/dist/src/client/usePathname.d.ts +1 -5
  59. package/dist/src/client/usePathname.js +7 -26
  60. package/dist/src/client/usePathname.js.map +1 -1
  61. package/dist/src/client/useRouter.js +6 -4
  62. package/dist/src/client/useRouter.js.map +1 -1
  63. package/dist/src/index.d.ts +3 -36
  64. package/dist/src/index.js +2 -2
  65. package/dist/src/index.js.map +1 -1
  66. package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +7 -7
  67. package/dist/src/react-client/Link.d.ts +16 -0
  68. package/dist/src/react-client/Link.js +17 -0
  69. package/dist/src/react-client/Link.js.map +1 -0
  70. package/dist/src/react-server/Link.d.ts +7 -0
  71. package/dist/src/react-server/Link.js +8 -0
  72. package/dist/src/react-server/Link.js.map +1 -0
  73. package/dist/src/react-server/index.d.ts +3 -34
  74. package/dist/src/react-server/index.js +2 -3
  75. package/dist/src/react-server/index.js.map +1 -1
  76. package/dist/src/server/getFormatter.d.ts +1 -1
  77. package/dist/src/server/getIntl.d.ts +1 -1
  78. package/dist/src/server/getRequestConfig.d.ts +3 -3
  79. package/dist/src/server/getRequestConfig.js.map +1 -1
  80. package/dist/src/shared/BaseLink.d.ts +7 -0
  81. package/dist/src/shared/BaseLink.js +38 -0
  82. package/dist/src/shared/BaseLink.js.map +1 -0
  83. package/dist/src/shared/NextIntlClientProvider.d.ts +1 -1
  84. package/dist/src/shared/constants.d.ts +1 -0
  85. package/dist/src/shared/constants.js +2 -0
  86. package/dist/src/shared/constants.js.map +1 -1
  87. package/dist/src/shared/isLocalUrl.d.ts +5 -0
  88. package/dist/src/shared/isLocalUrl.js +10 -0
  89. package/dist/src/shared/isLocalUrl.js.map +1 -0
  90. package/dist/src/shared/prefixHref.d.ts +4 -0
  91. package/dist/src/shared/prefixHref.js +15 -0
  92. package/dist/src/shared/prefixHref.js.map +1 -0
  93. package/dist/src/shared/unlocalizePathname.d.ts +1 -0
  94. package/dist/src/shared/unlocalizePathname.js +4 -0
  95. package/dist/src/shared/unlocalizePathname.js.map +1 -0
  96. package/package.json +23 -22
  97. package/src/client/localizeHref.tsx +15 -24
  98. package/src/client/useClientLocale.tsx +17 -0
  99. package/src/client/usePathname.tsx +8 -32
  100. package/src/client/useRouter.tsx +6 -4
  101. package/src/index.tsx +2 -2
  102. package/src/react-client/Link.tsx +21 -0
  103. package/src/react-server/Link.tsx +12 -0
  104. package/src/react-server/index.tsx +2 -4
  105. package/src/server/getRequestConfig.tsx +3 -3
  106. package/src/shared/BaseLink.tsx +56 -0
  107. package/src/shared/constants.tsx +3 -0
  108. package/src/shared/isLocalUrl.tsx +13 -0
  109. package/src/shared/prefixHref.tsx +21 -0
  110. package/src/shared/unlocalizePathname.tsx +3 -0
  111. package/CHANGELOG.md +0 -562
  112. package/dist/client/getCookieLocale.d.ts +0 -1
  113. package/dist/shared/Link.d.ts +0 -7
  114. package/dist/shared/LocalizedLink.d.ts +0 -7
  115. package/dist/src/client/getCookieLocale.d.ts +0 -1
  116. package/dist/src/client/getCookieLocale.js +0 -17
  117. package/dist/src/client/getCookieLocale.js.map +0 -1
  118. package/dist/src/shared/Link.d.ts +0 -7
  119. package/dist/src/shared/Link.js +0 -45
  120. package/dist/src/shared/Link.js.map +0 -1
  121. package/dist/src/shared/LocalizedLink.d.ts +0 -7
  122. package/dist/src/shared/LocalizedLink.js +0 -18
  123. package/dist/src/shared/LocalizedLink.js.map +0 -1
  124. package/src/.DS_Store +0 -0
  125. package/src/client/getCookieLocale.tsx +0 -19
  126. package/src/shared/Link.tsx +0 -61
  127. package/src/shared/LocalizedLink.tsx +0 -26
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
@@ -9,13 +9,13 @@
9
9
  <br>
10
10
  </h1>
11
11
 
12
- > Internationalization for Next.js that gets out of your way.
12
+ > Internationalization (i18n) for Next.js that gets out of your way.
13
13
 
14
14
  ![Gzipped size](https://badgen.net/bundlephobia/minzip/next-intl) ![Tree shaking supported](https://badgen.net/bundlephobia/tree-shaking/next-intl) [<img src="https://img.shields.io/npm/dw/next-intl.svg" />](https://www.npmjs.com/package/next-intl)
15
15
 
16
16
  <hr />
17
17
 
18
- 📣 [Support for Next.js 13 and the app directory is coming →](https://next-intl-docs.vercel.app/docs/next-13)
18
+ 📣 [Support for Next.js 13 and the App Router has arrived →](https://next-intl-docs.vercel.app/docs/next-13)
19
19
 
20
20
  <hr />
21
21
 
@@ -24,7 +24,7 @@
24
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.
25
25
 
26
26
  - 🌟 **ICU message syntax**: Localize your messages with interpolation, plurals, ordinal pluralization, enum-based label selection, and rich text.
27
- - 📅 **Dates, times & numbers**: Use global formats for a consistent look & feel of your app and apply fine-tuning as necessary.
27
+ - 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
28
28
  - ✅ **Type-safe**: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
29
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
30
  - 🚀 **Fast**: Get the best performance from your app by supporting internationalization on both static and dynamic pages.
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import { UrlObject } from 'url';
3
- export default function localizeHref(href: string, locale?: string, pathname?: string): string;
4
- export default function localizeHref(href: UrlObject | string, locale?: string, pathname?: string): UrlObject | string;
3
+ export default function localizeHref(href: string, locale: string, defaultLocale?: string, pathname?: string): string;
4
+ export default function localizeHref(href: UrlObject | string, locale: string, defaultLocale?: string, pathname?: string): UrlObject | string;
@@ -1,37 +1,26 @@
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';
5
-
6
- function localizeHref(href, locale, pathname) {
7
- var cookieLocale = getCookieLocale();
8
- if (!locale) locale = cookieLocale;
9
-
10
- if (!pathname) {
11
- pathname = window.location.pathname;
12
- }
13
-
14
- var isSwitchingLocale = locale !== cookieLocale;
15
- var isPathnamePrefixed = hasPathnamePrefixed(locale, pathname);
16
-
17
- if (isPathnamePrefixed || isSwitchingLocale) {
18
- var prefixedHref;
19
-
20
- if (typeof href === 'string') {
21
- prefixedHref = localizePathname(locale, href);
22
- } else {
23
- prefixedHref = _extends({}, href);
24
-
25
- if (href.pathname) {
26
- prefixedHref.pathname = localizePathname(locale, href.pathname);
2
+ import { useRouter as useRouter$1 } from 'next/navigation';
3
+ import { useMemo } from 'react';
4
+ import localizeHref from './next-intl.esm3.js';
5
+ import useClientLocale from './next-intl.esm2.js';
6
+
7
+ function useRouter() {
8
+ var router = useRouter$1();
9
+ var locale = useClientLocale();
10
+ return useMemo(function () {
11
+ return _extends({}, router, {
12
+ push: function push(href) {
13
+ return router.push(localizeHref(href, locale));
14
+ },
15
+ replace: function replace(href) {
16
+ return router.replace(localizeHref(href, locale));
17
+ },
18
+ prefetch: function prefetch(href) {
19
+ return router.prefetch(localizeHref(href, locale));
27
20
  }
28
- }
29
-
30
- return prefixedHref;
31
- } else {
32
- return href;
33
- }
21
+ });
22
+ }, [locale, router]);
34
23
  }
35
24
 
36
- export { localizeHref as default };
25
+ export { useRouter as default };
37
26
  //# 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(\n href: string,\n locale?: string,\n pathname?: string\n): string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale?: string,\n pathname?: string\n): UrlObject | string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale?: string,\n pathname?: string\n) {\n const cookieLocale = getCookieLocale();\n if (!locale) locale = cookieLocale;\n\n if (!pathname) {\n pathname = window.location.pathname;\n }\n\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","pathname","cookieLocale","getCookieLocale","window","location","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","prefixedHref","localizePathname"],"mappings":";;;;;AAewB,SAAAA,YAAA,CACtBC,IADsB,EAEtBC,MAFsB,EAGtBC,QAHsB,EAGL;AAEjB,EAAMC,IAAAA,YAAY,GAAGC,eAAe,EAApC,CAAA;AACA,EAAA,IAAI,CAACH,MAAL,EAAaA,MAAM,GAAGE,YAAT,CAAA;;AAEb,EAAI,IAAA,CAACD,QAAL,EAAe;AACbA,IAAAA,QAAQ,GAAGG,MAAM,CAACC,QAAP,CAAgBJ,QAA3B,CAAA;AACD,GAAA;;AAED,EAAA,IAAMK,iBAAiB,GAAGN,MAAM,KAAKE,YAArC,CAAA;AACA,EAAA,IAAMK,kBAAkB,GAAGC,mBAAmB,CAACR,MAAD,EAASC,QAAT,CAA9C,CAAA;;AAEA,EAAIM,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,CAACE,QAAT,EAAmB;AACjBQ,QAAAA,YAAY,CAACR,QAAb,GAAwBS,gBAAgB,CAACV,MAAD,EAASD,IAAI,CAACE,QAAd,CAAxC,CAAA;AACD,OAAA;AACF,KAAA;;AAED,IAAA,OAAOQ,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 './localizeHref';\nimport useClientLocale from './useClientLocale';\n\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(href, locale));\n },\n replace(href: string) {\n return router.replace(localizeHref(href, locale));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(href, locale));\n }\n }),\n [locale, router]\n );\n}\n"],"names":["useRouter","router","useNextRouter","locale","useClientLocale","useMemo","_extends","push","href","localizeHref","replace","prefetch"],"mappings":";;;;;;AAKc,SAAUA,SAASA,GAAA;AAC/B,EAAA,IAAMC,MAAM,GAAGC,WAAa,EAAE,CAAA;AAC9B,EAAA,IAAMC,MAAM,GAAGC,eAAe,EAAE,CAAA;AAEhC,EAAA,OAAOC,OAAO,CACZ,YAAA;IAAA,OAAAC,QAAA,KACKL,MAAM,EAAA;MACTM,IAAI,EAAA,SAAAA,IAACC,CAAAA,IAAY,EAAA;QACf,OAAOP,MAAM,CAACM,IAAI,CAACE,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;OAC/C;MACDO,OAAO,EAAA,SAAAA,OAACF,CAAAA,IAAY,EAAA;QAClB,OAAOP,MAAM,CAACS,OAAO,CAACD,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;OAClD;MACDQ,QAAQ,EAAA,SAAAA,QAACH,CAAAA,IAAY,EAAA;QACnB,OAAOP,MAAM,CAACU,QAAQ,CAACF,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;AACpD,OAAA;AAAC,KAAA,CAAA,CAAA;AAAA,GACD,EACF,CAACA,MAAM,EAAEF,MAAM,CAAC,CACjB,CAAA;AACH;;;;"}
@@ -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.esm5.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;;;;"}
@@ -1,7 +1,21 @@
1
- function hasPathnamePrefixed(locale, pathname) {
2
- var prefix = "/" + locale;
3
- return pathname === prefix || pathname.startsWith(prefix + "/") && pathname.length > prefix.length;
1
+ import prefixHref from '../shared/next-intl.esm4.js';
2
+ import hasPathnamePrefixed from './next-intl.esm4.js';
3
+
4
+ function localizeHref(href, locale, defaultLocale, pathname) {
5
+ if (defaultLocale === void 0) {
6
+ defaultLocale = locale;
7
+ }
8
+ if (!pathname) {
9
+ pathname = window.location.pathname;
10
+ }
11
+ var isSwitchingLocale = locale !== defaultLocale;
12
+ var isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
13
+ var shouldPrefix = isPathnamePrefixed || isSwitchingLocale;
14
+ if (shouldPrefix && locale != null) {
15
+ return prefixHref(href, locale);
16
+ }
17
+ return href;
4
18
  }
5
19
 
6
- export { hasPathnamePrefixed as default };
20
+ export { localizeHref as default };
7
21
  //# sourceMappingURL=next-intl.esm3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm3.js","sources":["../../src/client/hasPathnamePrefixed.tsx"],"sourcesContent":["export default function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return (\n pathname === prefix ||\n (pathname.startsWith(`${prefix}/`) && pathname.length > prefix.length)\n );\n}\n"],"names":["hasPathnamePrefixed","locale","pathname","prefix","startsWith","length"],"mappings":"AAAc,SAAUA,mBAAV,CAA8BC,MAA9B,EAA8CC,QAA9C,EAA8D;AAC1E,EAAMC,IAAAA,MAAM,SAAOF,MAAnB,CAAA;AACA,EAAA,OACEC,QAAQ,KAAKC,MAAb,IACCD,QAAQ,CAACE,UAAT,CAAuBD,MAAvB,GAAA,GAAA,CAAA,IAAqCD,QAAQ,CAACG,MAAT,GAAkBF,MAAM,CAACE,MAFjE,CAAA;AAID;;;;"}
1
+ {"version":3,"file":"next-intl.esm3.js","sources":["../../src/client/localizeHref.tsx"],"sourcesContent":["import {UrlObject} from 'url';\nimport prefixHref from '../shared/prefixHref';\nimport hasPathnamePrefixed from './hasPathnamePrefixed';\n\nexport default function localizeHref(\n href: string,\n locale: string,\n defaultLocale?: string,\n pathname?: string\n): string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale?: string,\n pathname?: string\n): UrlObject | string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname?: string\n) {\n if (!pathname) {\n pathname = window.location.pathname;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n"],"names":["localizeHref","href","locale","defaultLocale","pathname","window","location","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","shouldPrefix","prefixHref"],"mappings":";;;AAgBwB,SAAAA,YAAYA,CAClCC,IAAwB,EACxBC,MAAc,EACdC,aAAA,EACAC,QAAiB,EAAA;AAAA,EAAA,IADjBD,aAAA,KAAA,KAAA,CAAA,EAAA;AAAAA,IAAAA,aAAA,GAAwBD,MAAM,CAAA;AAAA,GAAA;EAG9B,IAAI,CAACE,QAAQ,EAAE;AACbA,IAAAA,QAAQ,GAAGC,MAAM,CAACC,QAAQ,CAACF,QAAQ,CAAA;AACpC,GAAA;AAED,EAAA,IAAMG,iBAAiB,GAAGL,MAAM,KAAKC,aAAa,CAAA;EAClD,IAAMK,kBAAkB,GACtBN,MAAM,IAAI,IAAI,IAAIO,mBAAmB,CAACP,MAAM,EAAEE,QAAQ,CAAC,CAAA;AACzD,EAAA,IAAMM,YAAY,GAAGF,kBAAkB,IAAID,iBAAiB,CAAA;AAE5D,EAAA,IAAIG,YAAY,IAAIR,MAAM,IAAI,IAAI,EAAE;AAClC,IAAA,OAAOS,UAAU,CAACV,IAAI,EAAEC,MAAM,CAAC,CAAA;AAChC,GAAA;AAED,EAAA,OAAOD,IAAI,CAAA;AACb;;;;"}
@@ -1,23 +1,7 @@
1
- import { COOKIE_LOCALE_NAME } from '../shared/next-intl.esm4.js';
2
-
3
- function getCookieValueByName(name) {
4
- // https://stackoverflow.com/a/15724300/343045
5
- var value = "; " + document.cookie;
6
- var parts = value.split("; " + name + "=");
7
-
8
- if (parts.length === 2) {
9
- var _parts$pop;
10
-
11
- var part = (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift();
12
- if (part) return part;
13
- }
14
-
15
- throw new Error("Unable to find next-intl cookie, have you configured the middleware?");
16
- }
17
-
18
- function getCookieLocale() {
19
- return getCookieValueByName(COOKIE_LOCALE_NAME);
1
+ function hasPathnamePrefixed(locale, pathname) {
2
+ var prefix = "/" + locale;
3
+ return pathname === prefix || pathname.startsWith(prefix + "/") && pathname.length > prefix.length;
20
4
  }
21
5
 
22
- export { getCookieLocale as default };
6
+ export { hasPathnamePrefixed as default };
23
7
  //# sourceMappingURL=next-intl.esm4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm4.js","sources":["../../src/client/getCookieLocale.tsx"],"sourcesContent":["import {COOKIE_LOCALE_NAME} from '../shared/constants';\n\nfunction getCookieValueByName(name: string) {\n // https://stackoverflow.com/a/15724300/343045\n const value = `; ${document.cookie}`;\n const parts = value.split(`; ${name}=`);\n if (parts.length === 2) {\n const part = parts.pop()?.split(';').shift();\n if (part) return part;\n }\n\n throw new Error(\n `Unable to find next-intl cookie, have you configured the middleware?`\n );\n}\n\nexport default function getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n"],"names":["getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","COOKIE_LOCALE_NAME"],"mappings":";;AAEA,SAASA,oBAAT,CAA8BC,IAA9B,EAA0C;AACxC;AACA,EAAA,IAAMC,KAAK,GAAA,IAAA,GAAQC,QAAQ,CAACC,MAA5B,CAAA;AACA,EAAA,IAAMC,KAAK,GAAGH,KAAK,CAACI,KAAN,CAAA,IAAA,GAAiBL,IAAjB,GAAd,GAAA,CAAA,CAAA;;AACA,EAAA,IAAII,KAAK,CAACE,MAAN,KAAiB,CAArB,EAAwB;AAAA,IAAA,IAAA,UAAA,CAAA;;AACtB,IAAA,IAAMC,IAAI,GAAA,CAAA,UAAA,GAAGH,KAAK,CAACI,GAAN,EAAH,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,UAAA,CAAaH,KAAb,CAAmB,GAAnB,CAAA,CAAwBI,KAAxB,EAAb,CAAA;AACA,IAAIF,IAAAA,IAAJ,EAAU,OAAOA,IAAP,CAAA;AACX,GAAA;;AAED,EAAM,MAAA,IAAIG,KAAJ,CAAN,sEAAA,CAAA,CAAA;AAGD,CAAA;;AAEa,SAAUC,eAAV,GAAyB;AACrC,EAAOZ,OAAAA,oBAAoB,CAACa,kBAAD,CAA3B,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"next-intl.esm4.js","sources":["../../src/client/hasPathnamePrefixed.tsx"],"sourcesContent":["export default function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return (\n pathname === prefix ||\n (pathname.startsWith(`${prefix}/`) && pathname.length > prefix.length)\n );\n}\n"],"names":["hasPathnamePrefixed","locale","pathname","prefix","startsWith","length"],"mappings":"AAAc,SAAUA,mBAAmBA,CAACC,MAAc,EAAEC,QAAgB,EAAA;EAC1E,IAAMC,MAAM,SAAOF,MAAQ,CAAA;AAC3B,EAAA,OACEC,QAAQ,KAAKC,MAAM,IAClBD,QAAQ,CAACE,UAAU,CAAID,MAAM,GAAG,GAAA,CAAC,IAAID,QAAQ,CAACG,MAAM,GAAGF,MAAM,CAACE,MAAO,CAAA;AAE1E;;;;"}
@@ -0,0 +1 @@
1
+ export default function useClientLocale(): string;
@@ -1,11 +1,7 @@
1
- export declare function unlocalizePathname(pathname: string): string;
2
1
  /**
3
2
  * Returns the pathname without a potential locale prefix.
4
3
  *
5
4
  * This can be helpful e.g. to implement navigation links,
6
5
  * where the active link is highlighted.
7
- *
8
- * Note that on the server side `null` is returned, only on
9
- * the client side the correct pathname will be returned.
10
6
  */
11
- export default function usePathname(): string | null;
7
+ export default function usePathname(): string;
package/dist/index.d.ts CHANGED
@@ -2,44 +2,11 @@
2
2
  * This is the main entry file when non-'react-server' environments import
3
3
  * from 'next-intl'. Make sure this mirrors the API from 'react-server'.
4
4
  */
5
- /// <reference types="react" />
6
- /// <reference types="node" />
5
+ import Link from './react-client/Link';
7
6
  export * from 'use-intl';
8
7
  export { default as useLocalizedRouter } from './react-client/useLocalizedRouter';
9
- export { default as Link } from './shared/Link';
8
+ export { default as Link } from './react-client/Link';
10
9
  /** @deprecated Is called `Link` now. */
11
- export declare const LocalizedLink: import("react").ForwardRefExoticComponent<Pick<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
12
- href: string | import("url").UrlObject;
13
- /** @deprecated Is called `Link` now. */
14
- as?: (string | import("url").UrlObject) | undefined;
15
- replace?: boolean | undefined;
16
- scroll?: boolean | undefined;
17
- shallow?: boolean | undefined;
18
- passHref?: boolean | undefined;
19
- prefetch?: boolean | undefined;
20
- locale?: string | false | undefined;
21
- legacyBehavior?: boolean | undefined;
22
- onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
23
- onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
24
- onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
25
- }> & {
26
- href: string | import("url").UrlObject;
27
- /** @deprecated Is called `Link` now. */
28
- as?: (string | import("url").UrlObject) | undefined;
29
- replace?: boolean | undefined;
30
- scroll?: boolean | undefined;
31
- shallow?: boolean | undefined;
32
- passHref?: boolean | undefined;
33
- prefetch?: boolean | undefined;
34
- locale?: string | false | undefined;
35
- legacyBehavior?: boolean | undefined;
36
- onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
37
- onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
38
- onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
39
- } & {
40
- children?: import("react").ReactNode;
41
- } & import("react").RefAttributes<HTMLAnchorElement>, "locale"> & {
42
- locale?: string | undefined;
43
- }, "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" | "tw" | "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>>;
10
+ export declare const LocalizedLink: typeof Link;
44
11
  export { default as NextIntlClientProvider } from './shared/NextIntlClientProvider';
45
12
  export { default as NextIntlProvider } from './shared/NextIntlClientProvider';
@@ -1,10 +1,10 @@
1
- declare type RoutingConfigPrefix = {
1
+ type RoutingConfigPrefix = {
2
2
  type: 'prefix';
3
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
4
  */
5
5
  prefix?: 'as-needed' | 'always';
6
6
  };
7
- declare type RoutingConfigDomain = {
7
+ type RoutingConfigDomain = {
8
8
  type: 'domain';
9
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
10
  domains: Array<{
@@ -12,8 +12,8 @@ declare type RoutingConfigDomain = {
12
12
  locale: string;
13
13
  }>;
14
14
  };
15
- declare type LocalePrefix = 'as-needed' | 'always';
16
- declare type RoutingBaseConfig = {
15
+ type LocalePrefix = 'as-needed' | 'always';
16
+ type RoutingBaseConfig = {
17
17
  /** A list of all locales that are supported. */
18
18
  locales: Array<string>;
19
19
  defaultLocale: string;
@@ -21,14 +21,14 @@ declare type RoutingBaseConfig = {
21
21
  */
22
22
  localePrefix?: LocalePrefix;
23
23
  };
24
- export declare type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> & {
24
+ export type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> & {
25
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
26
  domain: string;
27
27
  locales?: RoutingBaseConfig['locales'];
28
28
  /** @deprecated Use `defaultLocale` instead. */
29
29
  locale?: string;
30
30
  };
31
- declare type MiddlewareConfig = RoutingBaseConfig & {
31
+ type MiddlewareConfig = RoutingBaseConfig & {
32
32
  /** Can be used to change the locale handling per domain. */
33
33
  domains?: Array<DomainConfig>;
34
34
  /** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
@@ -38,7 +38,7 @@ declare type MiddlewareConfig = RoutingBaseConfig & {
38
38
  /** @deprecated Deprecated in favor of `localePrefix` and `domains`. */
39
39
  routing?: RoutingConfigPrefix | RoutingConfigDomain;
40
40
  };
41
- export declare type MiddlewareConfigWithDefaults = MiddlewareConfig & {
41
+ export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
42
42
  alternateLinks: boolean;
43
43
  localePrefix: LocalePrefix;
44
44
  localeDetection: boolean;