next-intl 2.14.0-beta.2 → 2.14.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 (34) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +3 -3
  3. package/dist/client/next-intl.esm.js +1 -1
  4. package/dist/client/next-intl.esm4.js +1 -1
  5. package/dist/next-intl.cjs.development.js +20 -5
  6. package/dist/next-intl.cjs.development.js.map +1 -1
  7. package/dist/next-intl.cjs.production.min.js +1 -1
  8. package/dist/next-intl.cjs.production.min.js.map +1 -1
  9. package/dist/server/getRequestConfig.d.ts +1 -1
  10. package/dist/shared/isLocalUrl.d.ts +5 -0
  11. package/dist/shared/next-intl.esm.js +11 -5
  12. package/dist/shared/next-intl.esm.js.map +1 -1
  13. package/dist/shared/next-intl.esm3.js +7 -8
  14. package/dist/shared/next-intl.esm3.js.map +1 -1
  15. package/dist/shared/next-intl.esm4.js +10 -4
  16. package/dist/shared/next-intl.esm4.js.map +1 -1
  17. package/dist/shared/next-intl.esm5.js +6 -0
  18. package/dist/shared/next-intl.esm5.js.map +1 -0
  19. package/dist/src/server/getRequestConfig.d.ts +1 -1
  20. package/dist/src/server/getRequestConfig.js.map +1 -1
  21. package/dist/src/shared/Link.js +12 -6
  22. package/dist/src/shared/Link.js.map +1 -1
  23. package/dist/src/shared/isLocalUrl.d.ts +5 -0
  24. package/dist/src/shared/isLocalUrl.js +10 -0
  25. package/dist/src/shared/isLocalUrl.js.map +1 -0
  26. package/package.json +2 -2
  27. package/src/server/getRequestConfig.tsx +3 -3
  28. package/src/shared/Link.tsx +11 -5
  29. package/src/shared/isLocalUrl.tsx +13 -0
  30. package/dist/shared/LocalizedLink.d.ts +0 -7
  31. package/dist/src/shared/LocalizedLink.d.ts +0 -7
  32. package/dist/src/shared/LocalizedLink.js +0 -18
  33. package/dist/src/shared/LocalizedLink.js.map +0 -1
  34. package/src/shared/LocalizedLink.tsx +0 -26
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 2.13.1 (2023-04-14)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Improve error message when trying to render an array as a message ([#244](https://github.com/amannn/next-intl/issues/244)) ([c6a4f7a](https://github.com/amannn/next-intl/commit/c6a4f7a338d0b2cf7be545cb5203949679c187fc))
12
+
13
+
14
+
15
+
16
+
6
17
  # 2.13.0 (2023-04-12)
7
18
 
8
19
 
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,5 +1,5 @@
1
1
  import { extends as _extends } from '../_virtual/next-intl.esm.js';
2
- import localizePathname from '../shared/next-intl.esm3.js';
2
+ import localizePathname from '../shared/next-intl.esm4.js';
3
3
  import getCookieLocale from './next-intl.esm4.js';
4
4
  import hasPathnamePrefixed from './next-intl.esm3.js';
5
5
 
@@ -1,4 +1,4 @@
1
- import { COOKIE_LOCALE_NAME } from '../shared/next-intl.esm4.js';
1
+ import { COOKIE_LOCALE_NAME } from '../shared/next-intl.esm5.js';
2
2
 
3
3
  function getCookieValueByName(name) {
4
4
  // https://stackoverflow.com/a/15724300/343045
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var url = require('url');
5
6
  var NextLink = require('next/link');
6
7
  var navigation = require('next/navigation');
7
8
  var React = require('react');
@@ -10,6 +11,7 @@ var router = require('next/router');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
14
+ var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
13
15
  var NextLink__default = /*#__PURE__*/_interopDefaultLegacy(NextLink);
14
16
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
15
17
 
@@ -114,6 +116,15 @@ function localizeHref(href, locale, pathname) {
114
116
  }
115
117
  }
116
118
 
119
+ function isLocalUrl(url) {
120
+ if (typeof url === 'object') {
121
+ return url.host == null && url.hostname == null;
122
+ } else {
123
+ var hasProtocol = /^[a-z]+:/i.test(url);
124
+ return !hasProtocol;
125
+ }
126
+ }
127
+
117
128
  var _excluded$1 = ["href", "locale", "prefetch"];
118
129
  /**
119
130
  * Wraps `next/link` and prefixes the `href` with the current locale.
@@ -140,7 +151,9 @@ function Link(_ref, ref) {
140
151
 
141
152
  var pathname = navigation.usePathname();
142
153
  React.useEffect(function () {
143
- setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
154
+ if (isLocalUrl(href)) {
155
+ setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
156
+ }
144
157
  }, [href, locale, pathname]);
145
158
 
146
159
  if (locale !== undefined) {
@@ -153,10 +166,12 @@ function Link(_ref, ref) {
153
166
 
154
167
  var localizedHrefString;
155
168
 
156
- if (typeof localizedHref === 'string') {
157
- localizedHrefString = localizedHref;
158
- } else if (localizedHref) {
159
- localizedHrefString = localizedHref.toString();
169
+ if (localizedHref) {
170
+ if (typeof localizedHref === 'string') {
171
+ localizedHrefString = localizedHref;
172
+ } else {
173
+ localizedHrefString = url__default["default"].format(localizedHref);
174
+ }
160
175
  }
161
176
 
162
177
  return (// eslint-disable-next-line jsx-a11y/anchor-has-content
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/localizePathname.tsx","../src/shared/constants.tsx","../src/client/getCookieLocale.tsx","../src/client/hasPathnamePrefixed.tsx","../src/client/localizeHref.tsx","../src/shared/Link.tsx","../src/client/useRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/NextIntlClientProvider.tsx","../src/index.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n","// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n","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","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","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","'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","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","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","'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\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","/**\n * This is the main entry file when non-'react-server' environments import\n * from 'next-intl'. Make sure this mirrors the API from 'react-server'.\n */\n\nimport Link from './shared/Link';\n\nexport * from 'use-intl';\n\nexport {default as useLocalizedRouter} from './react-client/useLocalizedRouter';\nexport {default as Link} from './shared/Link';\n\n/** @deprecated Is called `Link` now. */\nexport const LocalizedLink = Link;\n\nexport {default as NextIntlClientProvider} from './shared/NextIntlClientProvider';\n\n// Legacy export for compatibility\nexport {default as NextIntlProvider} from './shared/NextIntlClientProvider';\n"],"names":["localizePathname","locale","pathname","localizedHref","COOKIE_LOCALE_NAME","getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","hasPathnamePrefixed","prefix","startsWith","localizeHref","href","cookieLocale","window","location","isSwitchingLocale","isPathnamePrefixed","prefixedHref","Link","ref","prefetch","rest","_excluded","useState","setLocalizedHref","usePathname","useEffect","undefined","process","console","error","localizedHrefString","toString","React","createElement","NextLink","forwardRef","useRouter","router","useNextRouter","useMemo","push","replace","hasWarned","useLocalizedRouterDeprecated","warn","NextIntlClientProvider","children","now","Date","IntlProvider","LocalizedLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAc,SAAUA,gBAAV,CAA2BC,MAA3B,EAA2CC,QAA3C,EAA2D;AACvE,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,QAAQ,KAAK,GAAjB,EAAsB;AACpBC,IAAAA,aAAa,IAAID,QAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;ACRD;AACA;AACO,IAAMC,kBAAkB,GAAG,aAA3B;;ACAP,SAASC,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,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MAAtB;AAA8B0D,IAAAA,GAAG,EAAEA,GAAAA;AAAnC,GAA4C3B,EAAAA,IAA5C,CACG0B,EAAAA,QADH,CADF,CAAA;AAKD;;ACrDD;;;AAGG;AASH;;AACO,IAAMI,aAAa,GAAGjC;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/localizePathname.tsx","../src/shared/constants.tsx","../src/client/getCookieLocale.tsx","../src/client/hasPathnamePrefixed.tsx","../src/client/localizeHref.tsx","../src/shared/isLocalUrl.tsx","../src/shared/Link.tsx","../src/client/useRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/NextIntlClientProvider.tsx","../src/index.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n","// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n","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","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","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","import NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Url = ComponentProps<typeof NextLink>['href'];\n\nexport default function isLocalUrl(url: Url) {\n if (typeof url === 'object') {\n return url.host == null && url.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(url);\n return !hasProtocol;\n }\n}\n","'use client';\n\nimport url from 'url';\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport localizeHref from '../client/localizeHref';\nimport isLocalURL from './isLocalUrl';\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 if (isLocalURL(href)) {\n setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));\n }\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 (localizedHref) {\n if (typeof localizedHref === 'string') {\n localizedHrefString = localizedHref;\n } else {\n localizedHrefString = url.format(localizedHref);\n }\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","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","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","'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\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","/**\n * This is the main entry file when non-'react-server' environments import\n * from 'next-intl'. Make sure this mirrors the API from 'react-server'.\n */\n\nimport Link from './shared/Link';\n\nexport * from 'use-intl';\n\nexport {default as useLocalizedRouter} from './react-client/useLocalizedRouter';\nexport {default as Link} from './shared/Link';\n\n/** @deprecated Is called `Link` now. */\nexport const LocalizedLink = Link;\n\nexport {default as NextIntlClientProvider} from './shared/NextIntlClientProvider';\n\n// Legacy export for compatibility\nexport {default as NextIntlProvider} from './shared/NextIntlClientProvider';\n"],"names":["localizePathname","locale","pathname","localizedHref","COOKIE_LOCALE_NAME","getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","hasPathnamePrefixed","prefix","startsWith","localizeHref","href","cookieLocale","window","location","isSwitchingLocale","isPathnamePrefixed","prefixedHref","isLocalUrl","url","host","hostname","hasProtocol","test","Link","ref","prefetch","rest","_excluded","useState","setLocalizedHref","usePathname","useEffect","isLocalURL","undefined","process","console","error","localizedHrefString","format","React","createElement","NextLink","forwardRef","useRouter","router","useNextRouter","useMemo","push","replace","hasWarned","useLocalizedRouterDeprecated","warn","NextIntlClientProvider","children","now","Date","IntlProvider","LocalizedLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAc,SAAUA,gBAAV,CAA2BC,MAA3B,EAA2CC,QAA3C,EAA2D;AACvE,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,QAAQ,KAAK,GAAjB,EAAsB;AACpBC,IAAAA,aAAa,IAAID,QAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;ACRD;AACA;AACO,IAAMC,kBAAkB,GAAG,aAA3B;;ACAP,SAASC,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;AA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AA,IAAI,CAAC/C,MAAD,IAAWuD,QAAf,EAAuB;AACrBvD,IAAAA,MAAM,GAAGuD,QAAM,CAACvD,MAAhB,CAAA;AACD,GAdK;AAiBN;AACA;;;AACA,EAAA,IAAI,OAAOiE,GAAP,KAAe,QAAnB,EAA6B;AAC3BA,IAAAA,GAAG,GAAG,IAAIC,IAAJ,CAASD,GAAT,CAAN,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACjE,MAAL,EAAa;AACX,IAAA,MAAM,IAAIe,KAAJ,CAEA,+MADJ,CADI,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OACEmC,yBAAC,CAAAC,aAAD,CAACgB,oBAAD,EAAA,QAAA,CAAA;AAAcnE,IAAAA,MAAM,EAAEA,MAAtB;AAA8BiE,IAAAA,GAAG,EAAEA,GAAAA;AAAnC,GAA4C5B,EAAAA,IAA5C,CACG2B,EAAAA,QADH,CADF,CAAA;AAKD;;ACrDD;;;AAGG;AASH;;AACO,IAAMI,aAAa,GAAGlC;;;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/link"),t=require("next/navigation"),r=require("react"),n=require("use-intl"),o=require("next/router");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=i(e),u=i(r);function l(){return l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function c(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}function f(e,t){var r="/"+e;return"/"!==t&&(r+=t),r}function s(e,t,r){var n=function(e){var t=("; "+document.cookie).split("; NEXT_LOCALE=");if(2===t.length){var r,n=null==(r=t.pop())?void 0:r.split(";").shift();if(n)return n}throw new Error("Unable to find next-intl cookie, have you configured the middleware?")}();t||(t=n),r||(r=window.location.pathname);var o,i=t!==n,a=function(e,t){var r="/"+e;return t===r||t.startsWith(r+"/")&&t.length>r.length}(t,r);return a||i?("string"==typeof e?o=f(t,e):(o=l({},e),e.pathname&&(o.pathname=f(t,e.pathname))),o):e}var p=["href","locale","prefetch"];function d(e,n){var o,i=e.href,f=e.locale,d=e.prefetch,h=c(e,p),v=r.useState(i),x=v[0],m=v[1],w=t.usePathname();return r.useEffect((function(){m(s(i,f,null!=w?w:void 0))}),[i,f,w]),void 0!==f?("string"==typeof x?o=x:x&&(o=x.toString()),u.default.createElement("a",l({ref:n,href:o},h))):u.default.createElement(a.default,l({ref:n,href:x,prefetch:d},h))}var h=r.forwardRef(d),v=!1,x=["children","locale","now"];function m(e){var t,r=e.children,i=e.locale,a=e.now,f=c(e,x);try{t=o.useRouter()}catch(e){}if(!i&&t&&(i=t.locale),"string"==typeof a&&(a=new Date(a)),!i)throw new Error(void 0);return u.default.createElement(n.IntlProvider,l({locale:i,now:a},f),r)}var w=h;exports.Link=h,exports.LocalizedLink=w,exports.NextIntlClientProvider=m,exports.NextIntlProvider=m,exports.useLocalizedRouter=function(){return v||(console.warn("\n\nDEPRECATION WARNING: The `useLocalizedRouter` import from `next-intl` is deprecated and will be removed in the stable release of next-intl. Please import `useLocalizedRouter` from `next-intl/client` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\n\n"),v=!0),function(){var e=t.useRouter();return r.useMemo((function(){return l({},e,{push:function(t){return e.push(s(t))},replace:function(t){return e.replace(s(t))},prefetch:function(t){return e.prefetch(s(t))}})}),[e])}()},Object.keys(n).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[e]}})}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("url"),t=require("next/link"),r=require("next/navigation"),n=require("react"),o=require("use-intl"),i=require("next/router");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=u(e),l=u(t),c=u(n);function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},f.apply(this,arguments)}function s(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}function p(e,t){var r="/"+e;return"/"!==t&&(r+=t),r}function d(e,t,r){var n=function(e){var t=("; "+document.cookie).split("; NEXT_LOCALE=");if(2===t.length){var r,n=null==(r=t.pop())?void 0:r.split(";").shift();if(n)return n}throw new Error("Unable to find next-intl cookie, have you configured the middleware?")}();t||(t=n),r||(r=window.location.pathname);var o,i=t!==n,u=function(e,t){var r="/"+e;return t===r||t.startsWith(r+"/")&&t.length>r.length}(t,r);return u||i?("string"==typeof e?o=p(t,e):(o=f({},e),e.pathname&&(o.pathname=p(t,e.pathname))),o):e}var h=["href","locale","prefetch"];function v(e,t){var o,i=e.href,u=e.locale,p=e.prefetch,v=s(e,h),m=n.useState(i),x=m[0],w=m[1],y=r.usePathname();return n.useEffect((function(){(function(e){return"object"==typeof e?null==e.host&&null==e.hostname:!/^[a-z]+:/i.test(e)})(i)&&w(d(i,u,null!=y?y:void 0))}),[i,u,y]),void 0!==u?(x&&(o="string"==typeof x?x:a.default.format(x)),c.default.createElement("a",f({ref:t,href:o},v))):c.default.createElement(l.default,f({ref:t,href:x,prefetch:p},v))}var m=n.forwardRef(v),x=!1,w=["children","locale","now"];function y(e){var t,r=e.children,n=e.locale,u=e.now,a=s(e,w);try{t=i.useRouter()}catch(e){}if(!n&&t&&(n=t.locale),"string"==typeof u&&(u=new Date(u)),!n)throw new Error(void 0);return c.default.createElement(o.IntlProvider,f({locale:n,now:u},a),r)}var b=m;exports.Link=m,exports.LocalizedLink=b,exports.NextIntlClientProvider=y,exports.NextIntlProvider=y,exports.useLocalizedRouter=function(){return x||(console.warn("\n\nDEPRECATION WARNING: The `useLocalizedRouter` import from `next-intl` is deprecated and will be removed in the stable release of next-intl. Please import `useLocalizedRouter` from `next-intl/client` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\n\n"),x=!0),function(){var e=r.useRouter();return n.useMemo((function(){return f({},e,{push:function(t){return e.push(d(t))},replace:function(t){return e.replace(d(t))},prefetch:function(t){return e.prefetch(d(t))}})}),[e])}()},Object.keys(o).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return o[e]}})}));
2
2
  //# sourceMappingURL=next-intl.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/localizePathname.tsx","../src/client/localizeHref.tsx","../src/client/getCookieLocale.tsx","../src/client/hasPathnamePrefixed.tsx","../src/shared/Link.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/NextIntlClientProvider.tsx","../src/index.tsx","../src/client/useRouter.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n","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","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","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","'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","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","'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\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","/**\n * This is the main entry file when non-'react-server' environments import\n * from 'next-intl'. Make sure this mirrors the API from 'react-server'.\n */\n\nimport Link from './shared/Link';\n\nexport * from 'use-intl';\n\nexport {default as useLocalizedRouter} from './react-client/useLocalizedRouter';\nexport {default as Link} from './shared/Link';\n\n/** @deprecated Is called `Link` now. */\nexport const LocalizedLink = Link;\n\nexport {default as NextIntlClientProvider} from './shared/NextIntlClientProvider';\n\n// Legacy export for compatibility\nexport {default as NextIntlProvider} from './shared/NextIntlClientProvider';\n","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":["localizePathname","locale","pathname","localizedHref","localizeHref","href","cookieLocale","name","parts","document","cookie","split","length","_parts$pop","part","pop","shift","Error","getCookieValueByName","window","location","prefixedHref","isSwitchingLocale","isPathnamePrefixed","prefix","startsWith","hasPathnamePrefixed","Link","ref","localizedHrefString","prefetch","rest","_objectWithoutPropertiesLoose","_ref","_excluded","useState","_useState","setLocalizedHref","usePathname","useEffect","undefined","toString","React","createElement","_extends","NextLink","Link$1","forwardRef","hasWarned","NextIntlClientProvider","children","router","now","useRouter","error","Date","IntlProvider","LocalizedLink","console","warn","useNextRouter","useMemo","push","replace"],"mappings":"4mBAAc,SAAUA,EAAiBC,EAAgBC,GACnDC,IAAAA,EAAgB,IAAMF,EAM1B,MAJiB,MAAbC,I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vB,KAAMwB,GAAyBE,KAK9CW,UAACC,cAAAE,EAAD,QAAAD,EAAA,CAAUhB,IAAKA,EAAKvB,KAAMF,EAAe2B,SAAUA,GAAcC,IAIrE,IAAAe,EAAeC,EAAAA,WAAWpB,GCvDtBqB,GAAY,gCCOQ,SAAAC,EAKhBhB,GAJNiB,IAKIC,EALJD,IAAAA,SACAjD,IAAAA,OACAmD,IAAAA,IACGrB,EACGC,EAAAC,EAAAC,GAEF,IAGFiB,EAASE,EAASA,YAClB,MAAOC,IAiBL,IAXCrD,GAAUkD,IACblD,EAASkD,EAAOlD,QAMC,iBAARmD,IACTA,EAAM,IAAIG,KAAKH,KAGZnD,EACH,MAAM,IAAIgB,WAGJuB,GAIR,OACEE,UAACC,cAAAa,EAADA,aAAAZ,EAAA,CAAc3C,OAAQA,EAAQmD,IAAKA,GAASrB,GACzCmB,GCrCA,IAAMO,EAAgB9B,gIFNf,WAQZ,OAPKqB,IACHU,QAAQC,KAAR,gSAGAX,GAAY,GGRF,WACNG,IAAAA,EAASS,EAAAA,YAEf,OAAOC,EAAOA,SACZ,WAAA,OAAAjB,EAAA,GACKO,EADL,CAEEW,KAAKzD,SAAAA,GACI8C,OAAAA,EAAOW,KAAK1D,EAAaC,KAElC0D,QAAQ1D,SAAAA,GACC8C,OAAAA,EAAOY,QAAQ3D,EAAaC,KAErCyB,SAASzB,SAAAA,GACA8C,OAAAA,EAAOrB,SAAS1B,EAAaC,SAGxC,CAAC8C,IHLIE"}
1
+ {"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/localizePathname.tsx","../src/client/localizeHref.tsx","../src/client/getCookieLocale.tsx","../src/client/hasPathnamePrefixed.tsx","../src/shared/Link.tsx","../src/shared/isLocalUrl.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/NextIntlClientProvider.tsx","../src/index.tsx","../src/client/useRouter.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n","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","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","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","'use client';\n\nimport url from 'url';\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport localizeHref from '../client/localizeHref';\nimport isLocalURL from './isLocalUrl';\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 if (isLocalURL(href)) {\n setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));\n }\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 (localizedHref) {\n if (typeof localizedHref === 'string') {\n localizedHrefString = localizedHref;\n } else {\n localizedHrefString = url.format(localizedHref);\n }\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","import NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Url = ComponentProps<typeof NextLink>['href'];\n\nexport default function isLocalUrl(url: Url) {\n if (typeof url === 'object') {\n return url.host == null && url.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(url);\n return !hasProtocol;\n }\n}\n","import useRouter from '../client/useRouter';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\nexport default function useLocalizedRouterDeprecated() {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The \\`useLocalizedRouter\\` import from \\`next-intl\\` is deprecated and will be removed in the stable release of next-intl. Please import \\`useLocalizedRouter\\` from \\`next-intl/client\\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\\n\\n`\n );\n hasWarned = true;\n }\n\n return useRouter();\n}\n","'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\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","/**\n * This is the main entry file when non-'react-server' environments import\n * from 'next-intl'. Make sure this mirrors the API from 'react-server'.\n */\n\nimport Link from './shared/Link';\n\nexport * from 'use-intl';\n\nexport {default as useLocalizedRouter} from './react-client/useLocalizedRouter';\nexport {default as Link} from './shared/Link';\n\n/** @deprecated Is called `Link` now. */\nexport const LocalizedLink = Link;\n\nexport {default as NextIntlClientProvider} from './shared/NextIntlClientProvider';\n\n// Legacy export for compatibility\nexport {default as NextIntlProvider} from './shared/NextIntlClientProvider';\n","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":["localizePathname","locale","pathname","localizedHref","localizeHref","href","cookieLocale","name","parts","document","cookie","split","length","_parts$pop","part","pop","shift","Error","getCookieValueByName","window","location","prefixedHref","isSwitchingLocale","isPathnamePrefixed","prefix","startsWith","hasPathnamePrefixed","Link","ref","localizedHrefString","prefetch","rest","_objectWithoutPropertiesLoose","_ref","_excluded","useState","_useState","setLocalizedHref","usePathname","useEffect","url","host","hostname","test","isLocalURL","undefined","format","React","createElement","_extends","NextLink","Link$1","forwardRef","hasWarned","NextIntlClientProvider","children","router","now","useRouter","error","Date","IntlProvider","LocalizedLink","console","warn","useNextRouter","useMemo","push","replace"],"mappings":"ooBAAc,SAAUA,EAAiBC,EAAgBC,GACnDC,IAAAA,EAAgB,IAAMF,EAM1B,MAJiB,MAAbC,IACFC,GAAiBD,GAGZC,ECQe,SAAAC,EACtBC,EACAJ,EACAC,GAEMI,IAAAA,EClBR,SAA8BC,GAE5B,IACMC,GADK,KAAQC,SAASC,QACRC,MAAN,kBACd,GAAqB,IAAjBH,EAAMI,OAAc,CAAA,IAAAC,EAChBC,EAAO,OAAHD,EAAGL,EAAMO,YAAN,EAAAF,EAAaF,MAAM,KAAKK,QACjCF,GAAAA,EAAM,OAAOA,EAGb,MAAA,IAAIG,MAAV,wEAMOC,GDIFjB,IAAQA,EAASK,GAEjBJ,IACHA,EAAWiB,OAAOC,SA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,OACAwD,IAAAA,IACG1B,EACGC,EAAAC,EAAAC,GAEF,IAGFsB,EAASE,EAASA,YAClB,MAAOC,IAiBL,IAXC1D,GAAUuD,IACbvD,EAASuD,EAAOvD,QAMC,iBAARwD,IACTA,EAAM,IAAIG,KAAKH,KAGZxD,EACH,MAAM,IAAIgB,WAGJ4B,GAIR,OACEE,UAACC,cAAAa,EAADA,aAAAZ,EAAA,CAAchD,OAAQA,EAAQwD,IAAKA,GAAS1B,GACzCwB,GCrCA,IAAMO,EAAgBnC,gIFNf,WAQZ,OAPK0B,IACHU,QAAQC,KAAR,gSAGAX,GAAY,GGRF,WACNG,IAAAA,EAASS,EAAAA,YAEf,OAAOC,EAAOA,SACZ,WAAA,OAAAjB,EAAA,GACKO,EADL,CAEEW,KAAK9D,SAAAA,GACImD,OAAAA,EAAOW,KAAK/D,EAAaC,KAElC+D,QAAQ/D,SAAAA,GACCmD,OAAAA,EAAOY,QAAQhE,EAAaC,KAErCyB,SAASzB,SAAAA,GACAmD,OAAAA,EAAO1B,SAAS1B,EAAaC,SAGxC,CAACmD,IHLIE"}
@@ -6,5 +6,5 @@ export declare type GetRequestConfigParams = {
6
6
  /**
7
7
  * Should be called in `i18n.ts` to create the configuration for the current request.
8
8
  */
9
- export default function getRequestConfig(createRequestConfig: ({ locale }: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): ({ locale }: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
9
+ export default function getRequestConfig(createRequestConfig: (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
10
10
  export {};
@@ -0,0 +1,5 @@
1
+ import NextLink from 'next/link';
2
+ import { ComponentProps } from 'react';
3
+ declare type Url = ComponentProps<typeof NextLink>['href'];
4
+ export default function isLocalUrl(url: Url): boolean;
5
+ export {};
@@ -1,8 +1,10 @@
1
1
  import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
2
+ import url from 'url';
2
3
  import NextLink from 'next/link';
3
4
  import { usePathname } from 'next/navigation';
4
5
  import React, { forwardRef, useState, useEffect } from 'react';
5
6
  import localizeHref from '../client/next-intl.esm.js';
7
+ import isLocalUrl from './next-intl.esm3.js';
6
8
 
7
9
  var _excluded = ["href", "locale", "prefetch"];
8
10
  /**
@@ -30,7 +32,9 @@ function Link(_ref, ref) {
30
32
 
31
33
  var pathname = usePathname();
32
34
  useEffect(function () {
33
- setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
35
+ if (isLocalUrl(href)) {
36
+ setLocalizedHref(localizeHref(href, locale, pathname != null ? pathname : undefined));
37
+ }
34
38
  }, [href, locale, pathname]);
35
39
 
36
40
  if (locale !== undefined) {
@@ -43,10 +47,12 @@ function Link(_ref, ref) {
43
47
 
44
48
  var localizedHrefString;
45
49
 
46
- if (typeof localizedHref === 'string') {
47
- localizedHrefString = localizedHref;
48
- } else if (localizedHref) {
49
- localizedHrefString = localizedHref.toString();
50
+ if (localizedHref) {
51
+ if (typeof localizedHref === 'string') {
52
+ localizedHrefString = localizedHref;
53
+ } else {
54
+ localizedHrefString = url.format(localizedHref);
55
+ }
50
56
  }
51
57
 
52
58
  return (// eslint-disable-next-line jsx-a11y/anchor-has-content
@@ -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,gBAA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;AAGD,CAAA;;AAED,aAAemB,aAAAA,UAAU,CAACxB,IAAD,CAAzB;;;;"}
1
+ {"version":3,"file":"next-intl.esm.js","sources":["../../src/shared/Link.tsx"],"sourcesContent":["'use client';\n\nimport url from 'url';\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport localizeHref from '../client/localizeHref';\nimport isLocalURL from './isLocalUrl';\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 if (isLocalURL(href)) {\n setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));\n }\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 (localizedHref) {\n if (typeof localizedHref === 'string') {\n localizedHrefString = localizedHref;\n } else {\n localizedHrefString = url.format(localizedHref);\n }\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","isLocalURL","localizeHref","undefined","process","env","NODE_ENV","console","error","localizedHrefString","url","format","React","createElement","NextLink","forwardRef"],"mappings":";;;;;;;;;AAaA;;;;;;;;;;;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;AACb,IAAA,IAAIC,UAAU,CAACV,IAAD,CAAd,EAAsB;AACpBM,MAAAA,gBAAgB,CAACK,YAAY,CAACX,IAAD,EAAOC,MAAP,EAAeM,QAAf,IAAeA,IAAAA,GAAAA,QAAf,GAA2BK,SAA3B,CAAb,CAAhB,CAAA;AACD,KAAA;AACF,GAJQ,EAIN,CAACZ,IAAD,EAAOC,MAAP,EAAeM,QAAf,CAJM,CAAT,CAAA;;AAMA,EAAIN,IAAAA,MAAM,KAAKW,SAAf,EAA0B;AACxB;AACA;AACA;AAEA,IAAIV,IAAAA,QAAQ,IAAIW,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,IAAIb,aAAJ,EAAmB;AACjB,MAAA,IAAI,OAAOA,aAAP,KAAyB,QAA7B,EAAuC;AACrCa,QAAAA,mBAAmB,GAAGb,aAAtB,CAAA;AACD,OAFD,MAEO;AACLa,QAAAA,mBAAmB,GAAGC,GAAG,CAACC,MAAJ,CAAWf,aAAX,CAAtB,CAAA;AACD,OAAA;AACF,KAAA;;AAED,IACE;AACAgB,MAAAA,KAAG,CAAAC,aAAH,CAAG,GAAH,EAAA,QAAA,CAAA;AAAGvB,QAAAA,GAAG,EAAEA,GAAR;AAAaC,QAAAA,IAAI,EAAEkB,mBAAAA;AAAnB,OAAA,EAA4Cf,IAA5C,CAAA,CAAA;AAFF,MAAA;AAID,GAAA;;AAED,EAAA,OACEkB,KAAC,CAAAC,aAAD,CAACC,QAAD,EAAA,QAAA,CAAA;AAAUxB,IAAAA,GAAG,EAAEA,GAAf;AAAoBC,IAAAA,IAAI,EAAEK,aAA1B;AAAyCH,IAAAA,QAAQ,EAAEA,QAAAA;AAAnD,GAAA,EAAiEC,IAAjE,CADF,CAAA,CAAA;AAGD,CAAA;;AAED,aAAeqB,aAAAA,UAAU,CAAC1B,IAAD,CAAzB;;;;"}
@@ -1,12 +1,11 @@
1
- function localizePathname(locale, pathname) {
2
- var localizedHref = '/' + locale;
3
-
4
- if (pathname !== '/') {
5
- localizedHref += pathname;
1
+ function isLocalUrl(url) {
2
+ if (typeof url === 'object') {
3
+ return url.host == null && url.hostname == null;
4
+ } else {
5
+ var hasProtocol = /^[a-z]+:/i.test(url);
6
+ return !hasProtocol;
6
7
  }
7
-
8
- return localizedHref;
9
8
  }
10
9
 
11
- export { localizePathname as default };
10
+ export { isLocalUrl as default };
12
11
  //# sourceMappingURL=next-intl.esm3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm3.js","sources":["../../src/shared/localizePathname.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n"],"names":["localizePathname","locale","pathname","localizedHref"],"mappings":"AAAc,SAAUA,gBAAV,CAA2BC,MAA3B,EAA2CC,QAA3C,EAA2D;AACvE,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,QAAQ,KAAK,GAAjB,EAAsB;AACpBC,IAAAA,aAAa,IAAID,QAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"next-intl.esm3.js","sources":["../../src/shared/isLocalUrl.tsx"],"sourcesContent":["import NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Url = ComponentProps<typeof NextLink>['href'];\n\nexport default function isLocalUrl(url: Url) {\n if (typeof url === 'object') {\n return url.host == null && url.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(url);\n return !hasProtocol;\n }\n}\n"],"names":["isLocalUrl","url","host","hostname","hasProtocol","test"],"mappings":"AAKwB,SAAAA,UAAA,CAAWC,GAAX,EAAmB;AACzC,EAAA,IAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,IAAOA,OAAAA,GAAG,CAACC,IAAJ,IAAY,IAAZ,IAAoBD,GAAG,CAACE,QAAJ,IAAgB,IAA3C,CAAA;AACD,GAFD,MAEO;AACL,IAAA,IAAMC,WAAW,GAAG,WAAA,CAAYC,IAAZ,CAAiBJ,GAAjB,CAApB,CAAA;AACA,IAAA,OAAO,CAACG,WAAR,CAAA;AACD,GAAA;AACF;;;;"}
@@ -1,6 +1,12 @@
1
- // Reuse the legacy cookie name
2
- // https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
3
- var COOKIE_LOCALE_NAME = 'NEXT_LOCALE'; // Should take precedence over the cookie
1
+ function localizePathname(locale, pathname) {
2
+ var localizedHref = '/' + locale;
4
3
 
5
- export { COOKIE_LOCALE_NAME };
4
+ if (pathname !== '/') {
5
+ localizedHref += pathname;
6
+ }
7
+
8
+ return localizedHref;
9
+ }
10
+
11
+ export { localizePathname as default };
6
12
  //# sourceMappingURL=next-intl.esm4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-intl.esm4.js","sources":["../../src/shared/constants.tsx"],"sourcesContent":["// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n"],"names":["COOKIE_LOCALE_NAME"],"mappings":"AAAA;AACA;AACaA,IAAAA,kBAAkB,GAAG;;;;"}
1
+ {"version":3,"file":"next-intl.esm4.js","sources":["../../src/shared/localizePathname.tsx"],"sourcesContent":["export default function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n"],"names":["localizePathname","locale","pathname","localizedHref"],"mappings":"AAAc,SAAUA,gBAAV,CAA2BC,MAA3B,EAA2CC,QAA3C,EAA2D;AACvE,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,QAAQ,KAAK,GAAjB,EAAsB;AACpBC,IAAAA,aAAa,IAAID,QAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,6 @@
1
+ // Reuse the legacy cookie name
2
+ // https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
3
+ var COOKIE_LOCALE_NAME = 'NEXT_LOCALE'; // Should take precedence over the cookie
4
+
5
+ export { COOKIE_LOCALE_NAME };
6
+ //# sourceMappingURL=next-intl.esm5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-intl.esm5.js","sources":["../../src/shared/constants.tsx"],"sourcesContent":["// Reuse the legacy cookie name\n// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie\nexport const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';\n\n// Should take precedence over the cookie\nexport const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';\n"],"names":["COOKIE_LOCALE_NAME"],"mappings":"AAAA;AACA;AACaA,IAAAA,kBAAkB,GAAG;;;;"}
@@ -6,5 +6,5 @@ export declare type GetRequestConfigParams = {
6
6
  /**
7
7
  * Should be called in `i18n.ts` to create the configuration for the current request.
8
8
  */
9
- export default function getRequestConfig(createRequestConfig: ({ locale }: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): ({ locale }: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
9
+ export default function getRequestConfig(createRequestConfig: (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>): (params: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>;
10
10
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestConfig.js","sourceRoot":"","sources":["../../../src/server/getRequestConfig.tsx"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,mBAEoE;IAEpE,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"getRequestConfig.js","sourceRoot":"","sources":["../../../src/server/getRequestConfig.tsx"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,mBAE2C;IAE3C,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -1,8 +1,10 @@
1
1
  'use client';
2
+ import url from 'url';
2
3
  import NextLink from 'next/link';
3
4
  import { usePathname } from 'next/navigation';
4
5
  import React, { forwardRef, useEffect, useState } from 'react';
5
6
  import localizeHref from '../client/localizeHref';
7
+ import isLocalURL from './isLocalUrl';
6
8
  /**
7
9
  * Wraps `next/link` and prefixes the `href` with the current locale.
8
10
  *
@@ -19,7 +21,9 @@ function Link({ href, locale, prefetch, ...rest }, ref) {
19
21
  const [localizedHref, setLocalizedHref] = useState(href);
20
22
  const pathname = usePathname();
21
23
  useEffect(() => {
22
- setLocalizedHref(localizeHref(href, locale, pathname !== null && pathname !== void 0 ? pathname : undefined));
24
+ if (isLocalURL(href)) {
25
+ setLocalizedHref(localizeHref(href, locale, pathname !== null && pathname !== void 0 ? pathname : undefined));
26
+ }
23
27
  }, [href, locale, pathname]);
24
28
  if (locale !== undefined) {
25
29
  // If Next.js fixes the bug where the markup isn't updated correctly when
@@ -29,11 +33,13 @@ function Link({ href, locale, prefetch, ...rest }, ref) {
29
33
  console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link`.`');
30
34
  }
31
35
  let localizedHrefString;
32
- if (typeof localizedHref === 'string') {
33
- localizedHrefString = localizedHref;
34
- }
35
- else if (localizedHref) {
36
- localizedHrefString = localizedHref.toString();
36
+ if (localizedHref) {
37
+ if (typeof localizedHref === 'string') {
38
+ localizedHrefString = localizedHref;
39
+ }
40
+ else {
41
+ localizedHrefString = url.format(localizedHref);
42
+ }
37
43
  }
38
44
  return (
39
45
  // eslint-disable-next-line jsx-a11y/anchor-has-content
@@ -1 +1 @@
1
- {"version":3,"file":"Link.js","sourceRoot":"","sources":["../../../src/shared/Link.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC7E,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAMlD;;;;;;;;;;;GAWG;AACH,SAAS,IAAI,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAQ,EAAE,GAAiB;IACvE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CA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AE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,KAAM,IAAI,GAAI,CAC1E,CAAC;AACJ,CAAC;AAED,eAAe,UAAU,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import NextLink from 'next/link';
2
+ import { ComponentProps } from 'react';
3
+ declare type Url = ComponentProps<typeof NextLink>['href'];
4
+ export default function isLocalUrl(url: Url): boolean;
5
+ export {};
@@ -0,0 +1,10 @@
1
+ export default function isLocalUrl(url) {
2
+ if (typeof url === 'object') {
3
+ return url.host == null && url.hostname == null;
4
+ }
5
+ else {
6
+ const hasProtocol = /^[a-z]+:/i.test(url);
7
+ return !hasProtocol;
8
+ }
9
+ }
10
+ //# sourceMappingURL=isLocalUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isLocalUrl.js","sourceRoot":"","sources":["../../../src/shared/isLocalUrl.tsx"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,GAAQ;IACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,GAAG,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC;KACjD;SAAM;QACL,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,WAAW,CAAC;KACrB;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "2.14.0-beta.2",
3
+ "version": "2.14.0-beta.3",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "A minimal, but complete solution for internationalization in Next.js apps.",
@@ -66,7 +66,7 @@
66
66
  "@formatjs/intl-localematcher": "0.2.32",
67
67
  "negotiator": "0.6.3",
68
68
  "server-only": "0.0.1",
69
- "use-intl": "^2.13.0"
69
+ "use-intl": "^2.13.1"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
@@ -10,9 +10,9 @@ export type GetRequestConfigParams = {
10
10
  * Should be called in `i18n.ts` to create the configuration for the current request.
11
11
  */
12
12
  export default function getRequestConfig(
13
- createRequestConfig: ({
14
- locale
15
- }: GetRequestConfigParams) => RequestConfig | Promise<RequestConfig>
13
+ createRequestConfig: (
14
+ params: GetRequestConfigParams
15
+ ) => RequestConfig | Promise<RequestConfig>
16
16
  ) {
17
17
  return createRequestConfig;
18
18
  }
@@ -1,9 +1,11 @@
1
1
  'use client';
2
2
 
3
+ import url from 'url';
3
4
  import NextLink from 'next/link';
4
5
  import {usePathname} from 'next/navigation';
5
6
  import React, {ComponentProps, forwardRef, useEffect, useState} from 'react';
6
7
  import localizeHref from '../client/localizeHref';
8
+ import isLocalURL from './isLocalUrl';
7
9
 
8
10
  type Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {
9
11
  locale?: string;
@@ -26,7 +28,9 @@ function Link({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {
26
28
  const pathname = usePathname();
27
29
 
28
30
  useEffect(() => {
29
- setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));
31
+ if (isLocalURL(href)) {
32
+ setLocalizedHref(localizeHref(href, locale, pathname ?? undefined));
33
+ }
30
34
  }, [href, locale, pathname]);
31
35
 
32
36
  if (locale !== undefined) {
@@ -41,10 +45,12 @@ function Link({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {
41
45
  }
42
46
 
43
47
  let localizedHrefString;
44
- if (typeof localizedHref === 'string') {
45
- localizedHrefString = localizedHref;
46
- } else if (localizedHref) {
47
- localizedHrefString = localizedHref.toString();
48
+ if (localizedHref) {
49
+ if (typeof localizedHref === 'string') {
50
+ localizedHrefString = localizedHref;
51
+ } else {
52
+ localizedHrefString = url.format(localizedHref);
53
+ }
48
54
  }
49
55
 
50
56
  return (
@@ -0,0 +1,13 @@
1
+ import NextLink from 'next/link';
2
+ import {ComponentProps} from 'react';
3
+
4
+ type Url = ComponentProps<typeof NextLink>['href'];
5
+
6
+ export default function isLocalUrl(url: Url) {
7
+ if (typeof url === 'object') {
8
+ return url.host == null && url.hostname == null;
9
+ } else {
10
+ const hasProtocol = /^[a-z]+:/i.test(url);
11
+ return !hasProtocol;
12
+ }
13
+ }
@@ -1,7 +0,0 @@
1
- import Link from 'next/link';
2
- import React, { ComponentProps } from 'react';
3
- declare type Props = Omit<ComponentProps<typeof Link>, 'locale'> & {
4
- locale?: string;
5
- };
6
- declare const _default: React.ForwardRefExoticComponent<Pick<Props, "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"> & React.RefAttributes<HTMLAnchorElement>>;
7
- export default _default;
@@ -1,7 +0,0 @@
1
- import Link from 'next/link';
2
- import React, { ComponentProps } from 'react';
3
- declare type Props = Omit<ComponentProps<typeof Link>, 'locale'> & {
4
- locale?: string;
5
- };
6
- declare const _default: React.ForwardRefExoticComponent<Pick<Props, "replace" | "href" | "as" | "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"> & React.RefAttributes<HTMLAnchorElement>>;
7
- export default _default;
@@ -1,18 +0,0 @@
1
- 'use client';
2
- import Link from 'next/link';
3
- import { usePathname } from 'next/navigation';
4
- import React, { forwardRef, useEffect, useState } from 'react';
5
- import localizeHref from '../client/localizeHref';
6
- /**
7
- * Wraps `next/link` and prefixes the `href` with the current locale.
8
- */
9
- function LocalizedLink({ href, locale, ...rest }, ref) {
10
- const [localizedHref, setLocalizedHref] = useState(href);
11
- const pathname = usePathname();
12
- useEffect(() => {
13
- setLocalizedHref(localizeHref(href, locale));
14
- }, [href, locale, pathname]);
15
- return React.createElement(Link, { ref: ref, href: localizedHref, ...rest });
16
- }
17
- export default forwardRef(LocalizedLink);
18
- //# sourceMappingURL=LocalizedLink.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocalizedLink.js","sourceRoot":"","sources":["../../../src/shared/LocalizedLink.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC7E,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAMlD;;GAEG;AACH,SAAS,aAAa,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAQ,EAAE,GAAiB;IACtE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAc,IAAI,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,gBAAgB,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE7B,OAAO,oBAAC,IAAI,IAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,KAAM,IAAI,GAAI,CAAC;AAC3D,CAAC;AAED,eAAe,UAAU,CAAC,aAAa,CAAC,CAAC"}
@@ -1,26 +0,0 @@
1
- 'use client';
2
-
3
- import Link from 'next/link';
4
- import {usePathname} from 'next/navigation';
5
- import React, {ComponentProps, forwardRef, useEffect, useState} from 'react';
6
- import localizeHref from '../client/localizeHref';
7
-
8
- type Props = Omit<ComponentProps<typeof Link>, 'locale'> & {
9
- locale?: string;
10
- };
11
-
12
- /**
13
- * Wraps `next/link` and prefixes the `href` with the current locale.
14
- */
15
- function LocalizedLink({href, locale, ...rest}: Props, ref: Props['ref']) {
16
- const [localizedHref, setLocalizedHref] = useState<typeof href>(href);
17
- const pathname = usePathname();
18
-
19
- useEffect(() => {
20
- setLocalizedHref(localizeHref(href, locale));
21
- }, [href, locale, pathname]);
22
-
23
- return <Link ref={ref} href={localizedHref} {...rest} />;
24
- }
25
-
26
- export default forwardRef(LocalizedLink);