next-intl 2.12.0-beta.2 → 2.12.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 (36) hide show
  1. package/dist/client/next-intl.esm.js +19 -32
  2. package/dist/client/next-intl.esm.js.map +1 -1
  3. package/dist/client/next-intl.esm2.js +32 -19
  4. package/dist/client/next-intl.esm2.js.map +1 -1
  5. package/dist/client/usePathname.d.ts +3 -3
  6. package/dist/middleware/NextIntlMiddlewareConfig.d.ts +27 -3
  7. package/dist/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  8. package/dist/middleware/resolveLocale.d.ts +3 -6
  9. package/dist/next-intl.esm.js +4 -4
  10. package/dist/react-client/next-intl.esm.js +1 -1
  11. package/dist/shared/next-intl.esm.js +31 -54
  12. package/dist/shared/next-intl.esm.js.map +1 -1
  13. package/dist/shared/next-intl.esm2.js +54 -31
  14. package/dist/shared/next-intl.esm2.js.map +1 -1
  15. package/dist/src/client/usePathname.d.ts +3 -3
  16. package/dist/src/client/usePathname.js +6 -3
  17. package/dist/src/client/usePathname.js.map +1 -1
  18. package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +27 -3
  19. package/dist/src/middleware/getAlternateLinksHeaderValue.d.ts +6 -0
  20. package/dist/src/middleware/{setAlternateLinksHeader.js → getAlternateLinksHeaderValue.js} +22 -14
  21. package/dist/src/middleware/getAlternateLinksHeaderValue.js.map +1 -0
  22. package/dist/src/middleware/middleware.js +86 -15
  23. package/dist/src/middleware/middleware.js.map +1 -1
  24. package/dist/src/middleware/resolveLocale.d.ts +3 -6
  25. package/dist/src/middleware/resolveLocale.js +41 -22
  26. package/dist/src/middleware/resolveLocale.js.map +1 -1
  27. package/package.json +1 -1
  28. package/plugin.js +6 -0
  29. package/src/client/usePathname.tsx +7 -3
  30. package/src/middleware/NextIntlMiddlewareConfig.tsx +33 -4
  31. package/src/middleware/{setAlternateLinksHeader.tsx → getAlternateLinksHeaderValue.tsx} +29 -18
  32. package/src/middleware/middleware.tsx +119 -16
  33. package/src/middleware/resolveLocale.tsx +71 -25
  34. package/dist/middleware/setAlternateLinksHeader.d.ts +0 -6
  35. package/dist/src/middleware/setAlternateLinksHeader.d.ts +0 -6
  36. package/dist/src/middleware/setAlternateLinksHeader.js.map +0 -1
@@ -1,37 +1,24 @@
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.esm3.js';
4
- import hasPathnamePrefixed from './next-intl.esm4.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.esm2.js';
5
+
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));
27
18
  }
28
- }
29
-
30
- return prefixedHref;
31
- } else {
32
- return href;
33
- }
19
+ });
20
+ }, [router]);
34
21
  }
35
22
 
36
- export { localizeHref as default };
23
+ export { useRouter as default };
37
24
  //# 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';\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,24 +1,37 @@
1
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';
5
-
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));
2
+ import localizePathname from '../shared/next-intl.esm3.js';
3
+ import getCookieLocale from './next-intl.esm3.js';
4
+ import hasPathnamePrefixed from './next-intl.esm4.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);
18
27
  }
19
- });
20
- }, [router]);
28
+ }
29
+
30
+ return prefixedHref;
31
+ } else {
32
+ return href;
33
+ }
21
34
  }
22
35
 
23
- export { useRouter as default };
36
+ export { localizeHref as default };
24
37
  //# 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/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;;;;"}
@@ -2,10 +2,10 @@ export declare function unlocalizePathname(pathname: string): string;
2
2
  /**
3
3
  * Returns the pathname without a potential locale prefix.
4
4
  *
5
- * Note that on the server side `null` is returned, only on
6
- * the client side the correct pathname will be returned.
7
- *
8
5
  * This can be helpful e.g. to implement navigation links,
9
6
  * 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
10
  */
11
11
  export default function usePathname(): string | null;
@@ -1,13 +1,37 @@
1
+ export declare 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
+ export declare type DomainConfig = {
8
+ /** The domain name (e.g. "example.de" or "de.example.com"). */
9
+ domain: string;
10
+ locale: string;
11
+ };
12
+ export declare type RoutingConfigDomain = {
13
+ type: 'domain';
14
+ /** 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. */
15
+ domains: Array<{
16
+ domain: string;
17
+ locale: string;
18
+ }>;
19
+ };
1
20
  declare type NextIntlMiddlewareConfig = {
2
21
  /** A list of all locales that are supported. */
3
22
  locales: Array<string>;
4
23
  defaultLocale: string;
5
- /** Configure a list of domains where the `defaultLocale` is changed (e.g. `es.example.com/about`, `example.fr/about`). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
24
+ /** 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 */
25
+ alternateLinks?: boolean;
26
+ /** @deprecated Deprecated in favour of `routing`. */
6
27
  domains?: Array<{
7
28
  domain: string;
8
29
  defaultLocale: string;
9
30
  }>;
10
- /** 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 */
11
- alternateLinks?: boolean;
31
+ routing?: RoutingConfigPrefix | RoutingConfigDomain;
32
+ };
33
+ export declare type NextIntlMiddlewareConfigWithDefaults = NextIntlMiddlewareConfig & {
34
+ alternateLinks: boolean;
35
+ routing: RoutingConfigPrefix | RoutingConfigDomain;
12
36
  };
13
37
  export default NextIntlMiddlewareConfig;
@@ -0,0 +1,6 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { NextIntlMiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
3
+ /**
4
+ * See https://developers.google.com/search/docs/specialty/international/localized-versions
5
+ */
6
+ export default function getAlternateLinksHeaderValue(config: NextIntlMiddlewareConfigWithDefaults, request: NextRequest): string;
@@ -1,9 +1,6 @@
1
1
  import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
- import NextIntlMiddlewareConfig from './NextIntlMiddlewareConfig';
3
- export default function resolveLocale(i18n: NextIntlMiddlewareConfig, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
2
+ import { DomainConfig, NextIntlMiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
3
+ export default function resolveLocale(config: NextIntlMiddlewareConfigWithDefaults, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
4
4
  locale: string;
5
- domain: {
6
- domain: string;
7
- defaultLocale: string;
8
- } | undefined;
5
+ domain?: DomainConfig;
9
6
  };
@@ -1,7 +1,7 @@
1
- import Link from './shared/next-intl.esm.js';
2
- export { default as Link } from './shared/next-intl.esm.js';
3
- import NextIntlClientProvider from './shared/next-intl.esm2.js';
4
- export { default as NextIntlClientProvider } from './shared/next-intl.esm2.js';
1
+ import Link from './shared/next-intl.esm2.js';
2
+ export { default as Link } from './shared/next-intl.esm2.js';
3
+ import NextIntlClientProvider from './shared/next-intl.esm.js';
4
+ export { default as NextIntlClientProvider } from './shared/next-intl.esm.js';
5
5
  export * from 'use-intl';
6
6
  export { default as useLocalizedRouter } from './react-client/next-intl.esm.js';
7
7
 
@@ -1,4 +1,4 @@
1
- import useRouter from '../client/next-intl.esm2.js';
1
+ import useRouter from '../client/next-intl.esm.js';
2
2
 
3
3
  // during the beta, remove for stable release
4
4
 
@@ -1,70 +1,47 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
2
- import NextLink from 'next/link';
3
- import { usePathname } from 'next/navigation';
4
- import React, { forwardRef, useState, useEffect } from 'react';
5
- import localizeHref from '../client/next-intl.esm.js';
2
+ import { useRouter } from 'next/router';
3
+ import React from 'react';
4
+ import { IntlProvider } from 'use-intl';
6
5
 
7
- var _excluded = ["href", "locale", "prefetch"];
8
- /**
9
- * Wraps `next/link` and prefixes the `href` with the current locale.
10
- *
11
- * Note that when a `locale` prop is passed, two de-optimizations are made:
12
- *
13
- * 1. The `prefetch` prop is not supported. This is because Next.js prefetches
14
- * the page and the `set-cookie` response header will cause the locale cookie
15
- * on the current page to be overwritten.
16
- * 2. A regular anchor tag is used instead of `next/link`. This is to avoid a
17
- * bug with Server Components where the markup wouldn't be updated correctly
18
- * otherwise.
19
- */
6
+ var _excluded = ["children", "locale", "now"];
20
7
 
21
- function Link(_ref, ref) {
22
- var href = _ref.href,
8
+ function NextIntlClientProvider(_ref) {
9
+ var children = _ref.children,
23
10
  locale = _ref.locale,
24
- prefetch = _ref.prefetch,
11
+ now = _ref.now,
25
12
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
26
13
 
27
- var _useState = useState(href),
28
- localizedHref = _useState[0],
29
- setLocalizedHref = _useState[1];
14
+ var router;
30
15
 
31
- var pathname = usePathname();
32
- useEffect(function () {
33
- setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
34
- }, [href, locale, pathname]);
16
+ try {
17
+ // Reading from context is practically ok to do conditionally
18
+ // eslint-disable-next-line react-hooks/rules-of-hooks
19
+ router = useRouter();
20
+ } catch (error) {// Calling `useRouter` is not supported in the app folder
21
+ } // The router can be undefined if used in a context outside
22
+ // of Next.js (e.g. unit tests, Storybook, ...)
35
23
 
36
- if (locale !== undefined) {
37
- // If Next.js fixes the bug where the markup isn't updated correctly when
38
- // the locale changes, we can remove this check. Note however that we still
39
- // need to disable prefetching (see comment above).
40
- if (prefetch && process.env.NODE_ENV !== 'production') {
41
- console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link`.`');
42
- }
43
24
 
44
- var localizedHrefString;
25
+ if (!locale && router) {
26
+ locale = router.locale;
27
+ } // Currently RSC serialize dates to strings, therefore make sure we have
28
+ // a date object. We might be able to remove this once more types have
29
+ // first-class serialization support (https://github.com/facebook/react/issues/25687)
45
30
 
46
- if (typeof localizedHref === 'string') {
47
- localizedHrefString = localizedHref;
48
- } else if (localizedHref) {
49
- localizedHrefString = localizedHref.toString();
50
- }
51
31
 
52
- return (// eslint-disable-next-line jsx-a11y/anchor-has-content
53
- React.createElement("a", _extends({
54
- ref: ref,
55
- href: localizedHrefString
56
- }, rest))
57
- );
32
+ if (typeof now === 'string') {
33
+ now = new Date(now);
58
34
  }
59
35
 
60
- return React.createElement(NextLink, _extends({
61
- ref: ref,
62
- href: localizedHref,
63
- prefetch: prefetch
64
- }, rest));
65
- }
36
+ if (!locale) {
37
+ throw new Error(process.env.NODE_ENV !== 'production' ? "Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing)." : undefined);
38
+ }
66
39
 
67
- var Link$1 = /*#__PURE__*/forwardRef(Link);
40
+ return React.createElement(IntlProvider, _extends({
41
+ locale: locale,
42
+ now: now
43
+ }, rest), children);
44
+ }
68
45
 
69
- export { Link$1 as default };
46
+ export { NextIntlClientProvider as default };
70
47
  //# sourceMappingURL=next-intl.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm.js","sources":["../../src/shared/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport localizeHref from '../client/localizeHref';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale?: string;\n};\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n *\n * Note that when a `locale` prop is passed, two de-optimizations are made:\n *\n * 1. The `prefetch` prop is not supported. This is because Next.js prefetches\n * the page and the `set-cookie` response header will cause the locale cookie\n * on the current page to be overwritten.\n * 2. A regular anchor tag is used instead of `next/link`. This is to avoid a\n * bug with Server Components where the markup wouldn't be updated correctly\n * otherwise.\n */\nfunction Link({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const [localizedHref, setLocalizedHref] = useState<typeof href>(href);\n const pathname = usePathname();\n\n useEffect(() => {\n setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));\n }, [href, locale, pathname]);\n\n if (locale !== undefined) {\n // If Next.js fixes the bug where the markup isn't updated correctly when\n // the locale changes, we can remove this check. Note however that we still\n // need to disable prefetching (see comment above).\n\n if (prefetch && process.env.NODE_ENV !== 'production') {\n console.error(\n 'The `prefetch` prop is currently not supported when using the `locale` prop on `Link`.`'\n );\n }\n\n let localizedHrefString;\n if (typeof localizedHref === 'string') {\n localizedHrefString = localizedHref;\n } else if (localizedHref) {\n localizedHrefString = localizedHref.toString();\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/anchor-has-content\n <a ref={ref} href={localizedHrefString} {...rest} />\n );\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(Link);\n"],"names":["Link","ref","href","locale","prefetch","rest","useState","localizedHref","setLocalizedHref","pathname","usePathname","useEffect","localizeHref","undefined","process","env","NODE_ENV","console","error","localizedHrefString","toString","React","createElement","NextLink","forwardRef"],"mappings":";;;;;;;AAWA;;;;;;;;;;;AAWG;;AACH,SAASA,IAAT,CAAwDC,IAAAA,EAAAA,GAAxD,EAAyE;AAAA,EAA1DC,IAAAA,IAA0D,QAA1DA,IAA0D;AAAA,MAApDC,MAAoD,QAApDA,MAAoD;AAAA,MAA5CC,QAA4C,QAA5CA,QAA4C;AAAA,MAA/BC,IAA+B,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACvE,EAA0CC,IAAAA,SAAAA,GAAAA,QAAQ,CAAcJ,IAAd,CAAlD;AAAA,MAAOK,aAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAsBC,gBAAtB,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AACA,EAAMC,IAAAA,QAAQ,GAAGC,WAAW,EAA5B,CAAA;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACbH,IAAAA,gBAAgB,CAACI,YAAY,CAACV,IAAD,EAAOC,MAAP,EAAeM,QAAf,IAAeA,IAAAA,GAAAA,QAAf,GAA2BI,SAA3B,CAAb,CAAhB,CAAA;AACD,GAFQ,EAEN,CAACX,IAAD,EAAOC,MAAP,EAAeM,QAAf,CAFM,CAAT,CAAA;;AAIA,EAAIN,IAAAA,MAAM,KAAKU,SAAf,EAA0B;AACxB;AACA;AACA;AAEA,IAAIT,IAAAA,QAAQ,IAAIU,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzC,EAAuD;AACrDC,MAAAA,OAAO,CAACC,KAAR,CACE,yFADF,CAAA,CAAA;AAGD,KAAA;;AAED,IAAA,IAAIC,mBAAJ,CAAA;;AACA,IAAA,IAAI,OAAOZ,aAAP,KAAyB,QAA7B,EAAuC;AACrCY,MAAAA,mBAAmB,GAAGZ,aAAtB,CAAA;AACD,KAFD,MAEO,IAAIA,aAAJ,EAAmB;AACxBY,MAAAA,mBAAmB,GAAGZ,aAAa,CAACa,QAAd,EAAtB,CAAA;AACD,KAAA;;AAED,IACE;AACAC,MAAAA,KAAG,CAAAC,aAAH,CAAG,GAAH,EAAA,QAAA,CAAA;AAAGrB,QAAAA,GAAG,EAAEA,GAAR;AAAaC,QAAAA,IAAI,EAAEiB,mBAAAA;AAAnB,OAAA,EAA4Cd,IAA5C,CAAA,CAAA;AAFF,MAAA;AAID,GAAA;;AAED,EAAA,OACEgB,KAAC,CAAAC,aAAD,CAACC,QAAD,EAAA,QAAA,CAAA;AAAUtB,IAAAA,GAAG,EAAEA,GAAf;AAAoBC,IAAAA,IAAI,EAAEK,aAA1B;AAAyCH,IAAAA,QAAQ,EAAEA,QAAAA;AAAnD,GAAA,EAAiEC,IAAjE,CADF,CAAA,CAAA;AAGD,CAAA;;AAED,aAAemB,aAAAA,UAAU,CAACxB,IAAD,CAAzB;;;;"}
1
+ {"version":3,"file":"next-intl.esm.js","sources":["../../src/shared/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\n// Move this from /client to default\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["NextIntlClientProvider","children","locale","now","rest","router","useRouter","error","Date","Error","process","env","NODE_ENV","undefined","React","createElement","IntlProvider"],"mappings":";;;;;;;AAcwB,SAAAA,sBAAA,CAKhB,IAAA,EAAA;AAAA,EAJNC,IAAAA,QAIM,QAJNA,QAIM;AAAA,MAHNC,MAGM,QAHNA,MAGM;AAAA,MAFNC,GAEM,QAFNA,GAEM;AAAA,MADHC,IACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAA,IAAIC,MAAJ,CAAA;;AACA,EAAI,IAAA;AACF;AACA;AACAA,IAAAA,MAAM,GAAGC,SAAS,EAAlB,CAAA;AACD,GAJD,CAIE,OAAOC,KAAP,EAAc;AAEf,GARK;AAWN;;;AACA,EAAA,IAAI,CAACL,MAAD,IAAWG,MAAf,EAAuB;AACrBH,IAAAA,MAAM,GAAGG,MAAM,CAACH,MAAhB,CAAA;AACD,GAdK;AAiBN;AACA;;;AACA,EAAA,IAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;AAC3BA,IAAAA,GAAG,GAAG,IAAIK,IAAJ,CAASL,GAAT,CAAN,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACD,MAAL,EAAa;AACX,IAAA,MAAM,IAAIO,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,+MADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OACEC,KAAC,CAAAC,aAAD,CAACC,YAAD,EAAA,QAAA,CAAA;AAAcd,IAAAA,MAAM,EAAEA,MAAtB;AAA8BC,IAAAA,GAAG,EAAEA,GAAAA;AAAnC,GAA4CC,EAAAA,IAA5C,CACGH,EAAAA,QADH,CADF,CAAA;AAKD;;;;"}
@@ -1,47 +1,70 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
2
- import { useRouter } from 'next/router';
3
- import React from 'react';
4
- import { IntlProvider } from 'use-intl';
2
+ import NextLink from 'next/link';
3
+ import { usePathname } from 'next/navigation';
4
+ import React, { forwardRef, useState, useEffect } from 'react';
5
+ import localizeHref from '../client/next-intl.esm2.js';
5
6
 
6
- var _excluded = ["children", "locale", "now"];
7
+ var _excluded = ["href", "locale", "prefetch"];
8
+ /**
9
+ * Wraps `next/link` and prefixes the `href` with the current locale.
10
+ *
11
+ * Note that when a `locale` prop is passed, two de-optimizations are made:
12
+ *
13
+ * 1. The `prefetch` prop is not supported. This is because Next.js prefetches
14
+ * the page and the `set-cookie` response header will cause the locale cookie
15
+ * on the current page to be overwritten.
16
+ * 2. A regular anchor tag is used instead of `next/link`. This is to avoid a
17
+ * bug with Server Components where the markup wouldn't be updated correctly
18
+ * otherwise.
19
+ */
7
20
 
8
- function NextIntlClientProvider(_ref) {
9
- var children = _ref.children,
21
+ function Link(_ref, ref) {
22
+ var href = _ref.href,
10
23
  locale = _ref.locale,
11
- now = _ref.now,
24
+ prefetch = _ref.prefetch,
12
25
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
13
26
 
14
- var router;
27
+ var _useState = useState(href),
28
+ localizedHref = _useState[0],
29
+ setLocalizedHref = _useState[1];
15
30
 
16
- try {
17
- // Reading from context is practically ok to do conditionally
18
- // eslint-disable-next-line react-hooks/rules-of-hooks
19
- router = useRouter();
20
- } catch (error) {// Calling `useRouter` is not supported in the app folder
21
- } // The router can be undefined if used in a context outside
22
- // of Next.js (e.g. unit tests, Storybook, ...)
31
+ var pathname = usePathname();
32
+ useEffect(function () {
33
+ setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
34
+ }, [href, locale, pathname]);
23
35
 
36
+ if (locale !== undefined) {
37
+ // If Next.js fixes the bug where the markup isn't updated correctly when
38
+ // the locale changes, we can remove this check. Note however that we still
39
+ // need to disable prefetching (see comment above).
40
+ if (prefetch && process.env.NODE_ENV !== 'production') {
41
+ console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link`.`');
42
+ }
24
43
 
25
- if (!locale && router) {
26
- locale = router.locale;
27
- } // Currently RSC serialize dates to strings, therefore make sure we have
28
- // a date object. We might be able to remove this once more types have
29
- // first-class serialization support (https://github.com/facebook/react/issues/25687)
44
+ var localizedHrefString;
30
45
 
46
+ if (typeof localizedHref === 'string') {
47
+ localizedHrefString = localizedHref;
48
+ } else if (localizedHref) {
49
+ localizedHrefString = localizedHref.toString();
50
+ }
31
51
 
32
- if (typeof now === 'string') {
33
- now = new Date(now);
52
+ return (// eslint-disable-next-line jsx-a11y/anchor-has-content
53
+ React.createElement("a", _extends({
54
+ ref: ref,
55
+ href: localizedHrefString
56
+ }, rest))
57
+ );
34
58
  }
35
59
 
36
- if (!locale) {
37
- throw new Error(process.env.NODE_ENV !== 'production' ? "Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing)." : undefined);
38
- }
39
-
40
- return React.createElement(IntlProvider, _extends({
41
- locale: locale,
42
- now: now
43
- }, rest), children);
60
+ return React.createElement(NextLink, _extends({
61
+ ref: ref,
62
+ href: localizedHref,
63
+ prefetch: prefetch
64
+ }, rest));
44
65
  }
45
66
 
46
- export { NextIntlClientProvider as default };
67
+ var Link$1 = /*#__PURE__*/forwardRef(Link);
68
+
69
+ export { Link$1 as default };
47
70
  //# sourceMappingURL=next-intl.esm2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm2.js","sources":["../../src/shared/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\n// Move this from /client to default\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["NextIntlClientProvider","children","locale","now","rest","router","useRouter","error","Date","Error","process","env","NODE_ENV","undefined","React","createElement","IntlProvider"],"mappings":";;;;;;;AAcwB,SAAAA,sBAAA,CAKhB,IAAA,EAAA;AAAA,EAJNC,IAAAA,QAIM,QAJNA,QAIM;AAAA,MAHNC,MAGM,QAHNA,MAGM;AAAA,MAFNC,GAEM,QAFNA,GAEM;AAAA,MADHC,IACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAA,IAAIC,MAAJ,CAAA;;AACA,EAAI,IAAA;AACF;AACA;AACAA,IAAAA,MAAM,GAAGC,SAAS,EAAlB,CAAA;AACD,GAJD,CAIE,OAAOC,KAAP,EAAc;AAEf,GARK;AAWN;;;AACA,EAAA,IAAI,CAACL,MAAD,IAAWG,MAAf,EAAuB;AACrBH,IAAAA,MAAM,GAAGG,MAAM,CAACH,MAAhB,CAAA;AACD,GAdK;AAiBN;AACA;;;AACA,EAAA,IAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;AAC3BA,IAAAA,GAAG,GAAG,IAAIK,IAAJ,CAASL,GAAT,CAAN,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACD,MAAL,EAAa;AACX,IAAA,MAAM,IAAIO,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,+MADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OACEC,KAAC,CAAAC,aAAD,CAACC,YAAD,EAAA,QAAA,CAAA;AAAcd,IAAAA,MAAM,EAAEA,MAAtB;AAA8BC,IAAAA,GAAG,EAAEA,GAAAA;AAAnC,GAA4CC,EAAAA,IAA5C,CACGH,EAAAA,QADH,CADF,CAAA;AAKD;;;;"}
1
+ {"version":3,"file":"next-intl.esm2.js","sources":["../../src/shared/Link.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport localizeHref from '../client/localizeHref';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale?: string;\n};\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n *\n * Note that when a `locale` prop is passed, two de-optimizations are made:\n *\n * 1. The `prefetch` prop is not supported. This is because Next.js prefetches\n * the page and the `set-cookie` response header will cause the locale cookie\n * on the current page to be overwritten.\n * 2. A regular anchor tag is used instead of `next/link`. This is to avoid a\n * bug with Server Components where the markup wouldn't be updated correctly\n * otherwise.\n */\nfunction Link({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const [localizedHref, setLocalizedHref] = useState<typeof href>(href);\n const pathname = usePathname();\n\n useEffect(() => {\n setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));\n }, [href, locale, pathname]);\n\n if (locale !== undefined) {\n // If Next.js fixes the bug where the markup isn't updated correctly when\n // the locale changes, we can remove this check. Note however that we still\n // need to disable prefetching (see comment above).\n\n if (prefetch && process.env.NODE_ENV !== 'production') {\n console.error(\n 'The `prefetch` prop is currently not supported when using the `locale` prop on `Link`.`'\n );\n }\n\n let localizedHrefString;\n if (typeof localizedHref === 'string') {\n localizedHrefString = localizedHref;\n } else if (localizedHref) {\n localizedHrefString = localizedHref.toString();\n }\n\n return (\n // eslint-disable-next-line jsx-a11y/anchor-has-content\n <a ref={ref} href={localizedHrefString} {...rest} />\n );\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(Link);\n"],"names":["Link","ref","href","locale","prefetch","rest","useState","localizedHref","setLocalizedHref","pathname","usePathname","useEffect","localizeHref","undefined","process","env","NODE_ENV","console","error","localizedHrefString","toString","React","createElement","NextLink","forwardRef"],"mappings":";;;;;;;AAWA;;;;;;;;;;;AAWG;;AACH,SAASA,IAAT,CAAwDC,IAAAA,EAAAA,GAAxD,EAAyE;AAAA,EAA1DC,IAAAA,IAA0D,QAA1DA,IAA0D;AAAA,MAApDC,MAAoD,QAApDA,MAAoD;AAAA,MAA5CC,QAA4C,QAA5CA,QAA4C;AAAA,MAA/BC,IAA+B,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACvE,EAA0CC,IAAAA,SAAAA,GAAAA,QAAQ,CAAcJ,IAAd,CAAlD;AAAA,MAAOK,aAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAsBC,gBAAtB,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AACA,EAAMC,IAAAA,QAAQ,GAAGC,WAAW,EAA5B,CAAA;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACbH,IAAAA,gBAAgB,CAACI,YAAY,CAACV,IAAD,EAAOC,MAAP,EAAeM,QAAf,IAAeA,IAAAA,GAAAA,QAAf,GAA2BI,SAA3B,CAAb,CAAhB,CAAA;AACD,GAFQ,EAEN,CAACX,IAAD,EAAOC,MAAP,EAAeM,QAAf,CAFM,CAAT,CAAA;;AAIA,EAAIN,IAAAA,MAAM,KAAKU,SAAf,EAA0B;AACxB;AACA;AACA;AAEA,IAAIT,IAAAA,QAAQ,IAAIU,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzC,EAAuD;AACrDC,MAAAA,OAAO,CAACC,KAAR,CACE,yFADF,CAAA,CAAA;AAGD,KAAA;;AAED,IAAA,IAAIC,mBAAJ,CAAA;;AACA,IAAA,IAAI,OAAOZ,aAAP,KAAyB,QAA7B,EAAuC;AACrCY,MAAAA,mBAAmB,GAAGZ,aAAtB,CAAA;AACD,KAFD,MAEO,IAAIA,aAAJ,EAAmB;AACxBY,MAAAA,mBAAmB,GAAGZ,aAAa,CAACa,QAAd,EAAtB,CAAA;AACD,KAAA;;AAED,IACE;AACAC,MAAAA,KAAG,CAAAC,aAAH,CAAG,GAAH,EAAA,QAAA,CAAA;AAAGrB,QAAAA,GAAG,EAAEA,GAAR;AAAaC,QAAAA,IAAI,EAAEiB,mBAAAA;AAAnB,OAAA,EAA4Cd,IAA5C,CAAA,CAAA;AAFF,MAAA;AAID,GAAA;;AAED,EAAA,OACEgB,KAAC,CAAAC,aAAD,CAACC,QAAD,EAAA,QAAA,CAAA;AAAUtB,IAAAA,GAAG,EAAEA,GAAf;AAAoBC,IAAAA,IAAI,EAAEK,aAA1B;AAAyCH,IAAAA,QAAQ,EAAEA,QAAAA;AAAnD,GAAA,EAAiEC,IAAjE,CADF,CAAA,CAAA;AAGD,CAAA;;AAED,aAAemB,aAAAA,UAAU,CAACxB,IAAD,CAAzB;;;;"}
@@ -2,10 +2,10 @@ export declare function unlocalizePathname(pathname: string): string;
2
2
  /**
3
3
  * Returns the pathname without a potential locale prefix.
4
4
  *
5
- * Note that on the server side `null` is returned, only on
6
- * the client side the correct pathname will be returned.
7
- *
8
5
  * This can be helpful e.g. to implement navigation links,
9
6
  * 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
10
  */
11
11
  export default function usePathname(): string | null;
@@ -9,14 +9,17 @@ export function unlocalizePathname(pathname) {
9
9
  /**
10
10
  * Returns the pathname without a potential locale prefix.
11
11
  *
12
- * Note that on the server side `null` is returned, only on
13
- * the client side the correct pathname will be returned.
14
- *
15
12
  * This can be helpful e.g. to implement navigation links,
16
13
  * where the active link is highlighted.
14
+ *
15
+ * Note that on the server side `null` is returned, only on
16
+ * the client side the correct pathname will be returned.
17
17
  */
18
18
  export default function usePathname() {
19
19
  const pathname = useNextPathname();
20
+ // TODO: Once `useParams` is a thing, we can set this on the initial render.
21
+ // The `pathname` can either be prefixed with a locale or not, since we don't
22
+ // know the matched locale during SSR, we can't safely remove the prefix.
20
23
  const [unlocalizedPathname, setUnlocalizedPathname] = useState(null);
21
24
  useEffect(() => {
22
25
  if (pathname == null) {
@@ -1 +1 @@
1
- {"version":3,"file":"usePathname.js","sourceRoot":"","sources":["../../../src/client/usePathname.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAC,WAAW,IAAI,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AACnD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IACnC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAC5D,IAAI,CACL,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,IAAI,IAAI,EAAE;YACpB,sBAAsB,CAAC,QAAQ,CAAC,CAAC;YACjC,OAAO;SACR;QAED,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;QACvC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAEvE,IAAI,kBAAkB,EAAE;YACtB,sBAAsB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;SACtD;aAAM;YACL,sBAAsB,CAAC,QAAQ,CAAC,CAAC;SAClC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"usePathname.js","sourceRoot":"","sources":["../../../src/client/usePathname.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAC,WAAW,IAAI,eAAe,EAAC,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AACnD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,MAAM,QAAQ,GAAG,eAAe,EAAE,CAAC;IAEnC,4EAA4E;IAC5E,6EAA6E;IAC7E,yEAAyE;IACzE,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAC5D,IAAI,CACL,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,IAAI,IAAI,EAAE;YACpB,sBAAsB,CAAC,QAAQ,CAAC,CAAC;YACjC,OAAO;SACR;QAED,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;QACvC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAEvE,IAAI,kBAAkB,EAAE;YACtB,sBAAsB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;SACtD;aAAM;YACL,sBAAsB,CAAC,QAAQ,CAAC,CAAC;SAClC;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -1,13 +1,37 @@
1
+ export declare 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
+ export declare type DomainConfig = {
8
+ /** The domain name (e.g. "example.de" or "de.example.com"). */
9
+ domain: string;
10
+ locale: string;
11
+ };
12
+ export declare type RoutingConfigDomain = {
13
+ type: 'domain';
14
+ /** 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. */
15
+ domains: Array<{
16
+ domain: string;
17
+ locale: string;
18
+ }>;
19
+ };
1
20
  declare type NextIntlMiddlewareConfig = {
2
21
  /** A list of all locales that are supported. */
3
22
  locales: Array<string>;
4
23
  defaultLocale: string;
5
- /** Configure a list of domains where the `defaultLocale` is changed (e.g. `es.example.com/about`, `example.fr/about`). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
24
+ /** 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 */
25
+ alternateLinks?: boolean;
26
+ /** @deprecated Deprecated in favour of `routing`. */
6
27
  domains?: Array<{
7
28
  domain: string;
8
29
  defaultLocale: string;
9
30
  }>;
10
- /** 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 */
11
- alternateLinks?: boolean;
31
+ routing?: RoutingConfigPrefix | RoutingConfigDomain;
32
+ };
33
+ export declare type NextIntlMiddlewareConfigWithDefaults = NextIntlMiddlewareConfig & {
34
+ alternateLinks: boolean;
35
+ routing: RoutingConfigPrefix | RoutingConfigDomain;
12
36
  };
13
37
  export default NextIntlMiddlewareConfig;
@@ -0,0 +1,6 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { NextIntlMiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
3
+ /**
4
+ * See https://developers.google.com/search/docs/specialty/international/localized-versions
5
+ */
6
+ export default function getAlternateLinksHeaderValue(config: NextIntlMiddlewareConfigWithDefaults, request: NextRequest): string;