next-intl 2.15.0-beta.2 → 2.15.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/link/Link.d.ts +3 -3
- package/dist/link/next-intl.esm.js +12 -10
- package/dist/link/next-intl.esm.js.map +1 -1
- package/dist/next-intl.cjs.development.js +11 -9
- package/dist/next-intl.cjs.development.js.map +1 -1
- package/dist/next-intl.cjs.production.min.js +1 -1
- package/dist/next-intl.cjs.production.min.js.map +1 -1
- package/dist/src/link/Link.d.ts +3 -3
- package/dist/src/link/Link.js +6 -5
- package/dist/src/link/Link.js.map +1 -1
- package/dist/src/middleware/middleware.js +7 -9
- package/dist/src/middleware/middleware.js.map +1 -1
- package/dist/src/react-server/useHook.js +10 -6
- package/dist/src/react-server/useHook.js.map +1 -1
- package/package.json +2 -2
- package/src/link/Link.tsx +7 -5
- package/src/middleware/middleware.tsx +9 -9
- package/src/react-server/useHook.tsx +10 -6
package/dist/link/Link.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentProps } from 'react';
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
2
|
import BaseLink from '../shared/BaseLink';
|
|
3
3
|
type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
4
4
|
locale?: string;
|
|
@@ -23,5 +23,5 @@ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
|
23
23
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
24
24
|
* page to be overwritten before the user even decides to change the locale.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
export
|
|
26
|
+
declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
27
|
+
export default _default;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
3
|
import useClientLocale from '../client/next-intl.esm2.js';
|
|
4
4
|
import BaseLink from '../shared/next-intl.esm3.js';
|
|
5
5
|
|
|
6
6
|
var _excluded = ["locale"];
|
|
7
|
+
function Link(_ref, ref) {
|
|
8
|
+
var locale = _ref.locale,
|
|
9
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
10
|
+
var defaultLocale = useClientLocale();
|
|
11
|
+
return React.createElement(BaseLink, _extends({
|
|
12
|
+
ref: ref,
|
|
13
|
+
locale: locale || defaultLocale
|
|
14
|
+
}, rest));
|
|
15
|
+
}
|
|
7
16
|
/**
|
|
8
17
|
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
9
18
|
* necessary.
|
|
@@ -24,14 +33,7 @@ var _excluded = ["locale"];
|
|
|
24
33
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
25
34
|
* page to be overwritten before the user even decides to change the locale.
|
|
26
35
|
*/
|
|
27
|
-
|
|
28
|
-
var locale = _ref.locale,
|
|
29
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
|
-
var defaultLocale = useClientLocale();
|
|
31
|
-
return React.createElement(BaseLink, _extends({
|
|
32
|
-
locale: locale || defaultLocale
|
|
33
|
-
}, rest));
|
|
34
|
-
}
|
|
36
|
+
var Link$1 = /*#__PURE__*/forwardRef(Link);
|
|
35
37
|
|
|
36
|
-
export { Link as default };
|
|
38
|
+
export { Link$1 as default };
|
|
37
39
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":["../../src/link/Link.tsx"],"sourcesContent":["import React, {ComponentProps} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":["../../src/link/Link.tsx"],"sourcesContent":["import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n"],"names":["Link","_ref","ref","locale","rest","_objectWithoutPropertiesLoose","_excluded","defaultLocale","useClientLocale","React","createElement","BaseLink","_extends","forwardRef"],"mappings":";;;;;;AAQA,SAASA,IAAIA,CAAAC,IAAA,EAA2BC,GAAiB,EAAA;AAAA,EAAA,IAA1CC,MAAM,GAAAF,IAAA,CAANE,MAAM;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAJ,IAAA,EAAAK,SAAA,CAAA,CAAA;AAC5B,EAAA,IAAMC,aAAa,GAAGC,eAAe,EAAE,CAAA;AACvC,EAAA,OAAOC,KAAC,CAAAC,aAAA,CAAAC,QAAQ,EAAAC,QAAA,CAAA;AAACV,IAAAA,GAAG,EAAEA,GAAG;IAAEC,MAAM,EAAEA,MAAM,IAAII,aAAAA;GAAmBH,EAAAA,IAAI,EAAI,CAAA;AAC1E,CAAA;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;AACH,aAAeS,aAAAA,UAAU,CAACb,IAAI,CAAC;;;;"}
|
|
@@ -148,6 +148,15 @@ function BaseLink(_ref, ref) {
|
|
|
148
148
|
var BaseLink$1 = /*#__PURE__*/React.forwardRef(BaseLink);
|
|
149
149
|
|
|
150
150
|
var _excluded$1 = ["locale"];
|
|
151
|
+
function Link(_ref, ref) {
|
|
152
|
+
var locale = _ref.locale,
|
|
153
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
154
|
+
var defaultLocale = useClientLocale();
|
|
155
|
+
return React__default["default"].createElement(BaseLink$1, _extends({
|
|
156
|
+
ref: ref,
|
|
157
|
+
locale: locale || defaultLocale
|
|
158
|
+
}, rest));
|
|
159
|
+
}
|
|
151
160
|
/**
|
|
152
161
|
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
153
162
|
* necessary.
|
|
@@ -168,14 +177,7 @@ var _excluded$1 = ["locale"];
|
|
|
168
177
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
169
178
|
* page to be overwritten before the user even decides to change the locale.
|
|
170
179
|
*/
|
|
171
|
-
|
|
172
|
-
var locale = _ref.locale,
|
|
173
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
174
|
-
var defaultLocale = useClientLocale();
|
|
175
|
-
return React__default["default"].createElement(BaseLink$1, _extends({
|
|
176
|
-
locale: locale || defaultLocale
|
|
177
|
-
}, rest));
|
|
178
|
-
}
|
|
180
|
+
var Link$1 = /*#__PURE__*/React.forwardRef(Link);
|
|
179
181
|
|
|
180
182
|
// TODO: Only available for backwards compatibility
|
|
181
183
|
// during the beta, remove for stable release
|
|
@@ -186,7 +188,7 @@ function LinkDeprecated(props) {
|
|
|
186
188
|
console.warn("\n\nDEPRECATION WARNING: The import for `Link` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\n\n");
|
|
187
189
|
hasWarned$1 = true;
|
|
188
190
|
}
|
|
189
|
-
return React__default["default"].createElement(Link, _extends({}, props));
|
|
191
|
+
return React__default["default"].createElement(Link$1, _extends({}, props));
|
|
190
192
|
}
|
|
191
193
|
|
|
192
194
|
var _excluded = ["children", "locale", "now"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/client/useRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.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\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\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}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\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` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default function Link({locale, ...rest}: Props) {\n const defaultLocale = useClientLocale();\n return <BaseLink locale={locale || defaultLocale} {...rest} />;\n}\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\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","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n","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","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","locale","params","useParams","useLocale","isRelativeHref","href","pathname","startsWith","isLocalHref","host","hostname","hasProtocol","test","localizeHref","defaultLocale","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","shouldPrefix","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","prefix","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","process","console","error","React","createElement","NextLink","forwardRef","Link","hasWarned","LinkDeprecated","props","warn","NextIntlClientProvider","children","now","router","useRouter","Date","Error","IntlProvider","useNextRouter","useMemo","localize","window","location","push","replace","useLocalizedRouterDeprecated","LocalizedLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAOA;AACO,IAAMA,mBAAmB,GAAG,QAAQ;;ACJ7B,SAAUC,eAAeA,GAAA;AACrC,EAAA,IAAIC,MAAM,CAAA;AAEV,EAAA,IAAMC,MAAM,GAAGC,oBAAS,EAAE,CAAA;AAC1B,EAAA,IAAID,MAAM,CAACH,mBAAmB,CAAC,EAAE;AAC/BE,IAAAA,MAAM,GAAGC,MAAM,CAACH,mBAAmB,CAAC,CAAA;AACrC,GAAA,MAAM;AACL;IACAE,MAAM,GAAGG,iBAAS,EAAE,CAAA;AACrB,GAAA;AAED,EAAA,OAAOH,MAAM,CAAA;AACf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,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;OACnC;MACD4D,OAAO,EAAA,SAAAA,OAAC5D,CAAAA,IAAY,EAAA;QAClB,OAAOiD,MAAM,CAACW,OAAO,CAACJ,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;OACtC;MACDwB,QAAQ,EAAA,SAAAA,QAACxB,CAAAA,IAAY,EAAA;QACnB,OAAOiD,MAAM,CAACzB,QAAQ,CAACgC,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;AACxC,OAAA;AAAC,KAAA,CAAA,CAAA;AAEL,GAAC,EAAE,CAACL,MAAM,EAAEsD,MAAM,CAAC,CAAC,CAAA;AACtB;;ACzCA;AACA;AAEA,IAAIP,SAAS,GAAG,KAAK,CAAA;AAEP,SAAUmB,4BAA4BA,GAAA;EAClD,IAAI,CAACnB,SAAS,EAAE;IACdP,OAAO,CAACU,IAAI,CAAA,8RAC4R,CACvS,CAAA;AACDH,IAAAA,SAAS,GAAG,IAAI,CAAA;AACjB,GAAA;EAED,OAAOQ,SAAS,EAAE,CAAA;AACpB;;AChBA;;;;;;;;AAQG;AAUH;AACO,IAAMY,aAAa,GAAGrB;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/client/useRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.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\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\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}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\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` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\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","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n","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","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","locale","params","useParams","useLocale","isRelativeHref","href","pathname","startsWith","isLocalHref","host","hostname","hasProtocol","test","localizeHref","defaultLocale","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","shouldPrefix","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","prefix","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","process","console","error","React","createElement","NextLink","forwardRef","Link","hasWarned","LinkDeprecated","props","warn","NextIntlClientProvider","children","now","router","useRouter","Date","Error","IntlProvider","useNextRouter","useMemo","localize","window","location","push","replace","useLocalizedRouterDeprecated","LocalizedLink"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAOA;AACO,IAAMA,mBAAmB,GAAG,QAAQ;;ACJ7B,SAAUC,eAAeA,GAAA;AACrC,EAAA,IAAIC,MAAM,CAAA;AAEV,EAAA,IA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eAAe,EAAE,CAAA;EAEhC,OAAO6D,aAAO,CAAC,YAAK;IAClB,SAASC,QAAQA,CAACxD,IAAY,EAAA;AAC5B,MAAA,OAAOQ,YAAY,CAACR,IAAI,EAAEL,MAAM,EAAEA,MAAM,EAAE8D,MAAM,CAACC,QAAQ,CAACzD,QAAQ,CAAC,CAAA;AACrE,KAAA;IAEA,OAAAgB,QAAA,KACKgC,MAAM,EAAA;MACTU,IAAI,EAAA,SAAAA,IAAC3D,CAAAA,IAAY,EAAA;QACf,OAAOiD,MAAM,CAACU,IAAI,CAACH,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;OACnC;MACD4D,OAAO,EAAA,SAAAA,OAAC5D,CAAAA,IAAY,EAAA;QAClB,OAAOiD,MAAM,CAACW,OAAO,CAACJ,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;OACtC;MACDwB,QAAQ,EAAA,SAAAA,QAACxB,CAAAA,IAAY,EAAA;QACnB,OAAOiD,MAAM,CAACzB,QAAQ,CAACgC,QAAQ,CAACxD,IAAI,CAAC,CAAC,CAAA;AACxC,OAAA;AAAC,KAAA,CAAA,CAAA;AAEL,GAAC,EAAE,CAACL,MAAM,EAAEsD,MAAM,CAAC,CAAC,CAAA;AACtB;;ACzCA;AACA;AAEA,IAAIP,SAAS,GAAG,KAAK,CAAA;AAEP,SAAUmB,4BAA4BA,GAAA;EAClD,IAAI,CAACnB,SAAS,EAAE;IACdP,OAAO,CAACU,IAAI,CAAA,8RAC4R,CACvS,CAAA;AACDH,IAAAA,SAAS,GAAG,IAAI,CAAA;AACjB,GAAA;EAED,OAAOQ,SAAS,EAAE,CAAA;AACpB;;AChBA;;;;;;;;AAQG;AAUH;AACO,IAAMY,aAAa,GAAGrB;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("next/navigation"),n=require("use-intl"),r=require("next/link"),o=require("next/router");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),i=a(r);function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l.apply(this,arguments)}function c(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}var f="locale";function s(){var e=t.useParams();return e[f]?e[f]:n.useLocale()}function p(e){return"object"==typeof e?null==e.host&&null==e.hostname:!/^[a-z]+:/i.test(e)}function d(e,t,n,r){if(void 0===n&&(n=t),!p(e)||function(e){var t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}(e))return e;var o=t!==n,a=null==t||function(e,t){var n="/"+e;return t===n||t.startsWith(n+"/")}(t,r);return(a||o)&&null!=t?h(e,t):e}function h(e,t){var n;return"string"==typeof e?n=v(t,e):(n=l({},e),e.pathname&&(n.pathname=v(t,e.pathname))),n}function v(e,t){var n="/"+e;return"/"!==t&&(n+=t),n}var m=["href","locale","prefetch"];function x(n,r){var o=n.href,a=n.locale,f=n.prefetch,v=c(n,m),x=t.usePathname(),y=s(),w=a!==y,b=e.useState((function(){return p(o)&&a?h(o,a):o})),P=b[0],g=b[1];return e.useEffect((function(){g(d(o,a,y,null!=x?x:void 0))}),[y,o,a,x]),w&&(f=!1),u.default.createElement(i.default,l({ref:r,href:P,prefetch:f},v))}var y=e.forwardRef(x),w=["locale"];function b(e){var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("next/navigation"),n=require("use-intl"),r=require("next/link"),o=require("next/router");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),i=a(r);function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l.apply(this,arguments)}function c(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}var f="locale";function s(){var e=t.useParams();return e[f]?e[f]:n.useLocale()}function p(e){return"object"==typeof e?null==e.host&&null==e.hostname:!/^[a-z]+:/i.test(e)}function d(e,t,n,r){if(void 0===n&&(n=t),!p(e)||function(e){var t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}(e))return e;var o=t!==n,a=null==t||function(e,t){var n="/"+e;return t===n||t.startsWith(n+"/")}(t,r);return(a||o)&&null!=t?h(e,t):e}function h(e,t){var n;return"string"==typeof e?n=v(t,e):(n=l({},e),e.pathname&&(n.pathname=v(t,e.pathname))),n}function v(e,t){var n="/"+e;return"/"!==t&&(n+=t),n}var m=["href","locale","prefetch"];function x(n,r){var o=n.href,a=n.locale,f=n.prefetch,v=c(n,m),x=t.usePathname(),y=s(),w=a!==y,b=e.useState((function(){return p(o)&&a?h(o,a):o})),P=b[0],g=b[1];return e.useEffect((function(){g(d(o,a,y,null!=x?x:void 0))}),[y,o,a,x]),w&&(f=!1),u.default.createElement(i.default,l({ref:r,href:P,prefetch:f},v))}var y=e.forwardRef(x),w=["locale"];function b(e,t){var n=e.locale,r=c(e,w),o=s();return u.default.createElement(y,l({ref:t,locale:n||o},r))}var P=e.forwardRef(b),g=!1;function O(e){return g||(console.warn("\n\nDEPRECATION WARNING: The import for `Link` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\n\n"),g=!0),u.default.createElement(P,l({},e))}var E=["children","locale","now"];function R(e){var t,r=e.children,a=e.locale,i=e.now,f=c(e,E);try{t=o.useRouter()}catch(e){}if(!a&&t&&(a=t.locale),"string"==typeof i&&(i=new Date(i)),!a)throw new Error(void 0);return u.default.createElement(n.IntlProvider,l({locale:a,now:i},f),r)}var j=!1,k=O;exports.Link=O,exports.LocalizedLink=k,exports.NextIntlClientProvider=R,exports.NextIntlProvider=R,exports.useLocalizedRouter=function(){return j||(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"),j=!0),function(){var n=t.useRouter(),r=s();return e.useMemo((function(){function e(e){return d(e,r,r,window.location.pathname)}return l({},n,{push:function(t){return n.push(e(t))},replace:function(t){return n.replace(e(t))},prefetch:function(t){return n.prefetch(e(t))}})}),[r,n])}()},Object.keys(n).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return n[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/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.tsx","../src/client/useRouter.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\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\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}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\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` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default function Link({locale, ...rest}: Props) {\n const defaultLocale = useClientLocale();\n return <BaseLink locale={locale || defaultLocale} {...rest} />;\n}\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\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","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","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","params","useParams","useLocale","isLocalHref","href","host","hostname","test","localizeHref","locale","defaultLocale","pathname","startsWith","isRelativeHref","isSwitchingLocale","isPathnamePrefixed","prefix","hasPathnamePrefixed","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","React","createElement","NextLink","BaseLink$1","forwardRef","Link","hasWarned","LinkDeprecated","props","console","warn","NextIntlClientProvider","router","children","now","useRouter","error","Date","Error","IntlProvider","LocalizedLink","useNextRouter","useMemo","localize","window","location","push","replace"],"mappings":"goBAQO,IAAMA,EAAsB,SCJrB,SAAUC,IACtB,IAEMC,EAASC,EAAAA,YAQf,OAPID,EAAOF,GACAE,EAAOF,GAGPI,EAASA,WAItB,CCLM,SAAUC,EAAYC,GAC1B,MAAoB,iBAATA,EACW,MAAbA,EAAKC,MAAiC,MAAjBD,EAAKE,UAEb,YAAYC,KAAKH,EAGzC,CAcM,SAAUI,EACdJ,EACAK,EACAC,EACAC,GAEA,QAHA,IAAAD,IAAAA,EAAwBD,IAGnBN,EAAYC,IAhCb,SAAyBA,GAC7B,IAAMO,EAA2B,iBAATP,EAAoBA,EAAKO,SAAWP,EAC5D,OAAmB,MAAZO,IAAqBA,EAASC,WAAW,IAClD,C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P,OAAO6C,EAAOtB,SAASiC,EAASxD,GAClC,GAEJ,GAAG,CAACK,EAAQwC,GACd,CF5BSG,EACT"}
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/constants.tsx","../src/client/useClientLocale.tsx","../src/shared/utils.tsx","../src/shared/BaseLink.tsx","../src/link/Link.tsx","../src/react-client/Link.tsx","../src/shared/NextIntlClientProvider.tsx","../src/react-client/useLocalizedRouter.tsx","../src/react-client/index.tsx","../src/client/useRouter.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\n// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n","import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n","import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\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}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n","'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n const pathname = usePathname();\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\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` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n","import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n","import React, {ComponentProps} from 'react';\nimport Link from '../link';\n\n// TODO: Only available for backwards compatibility\n// during the beta, remove for stable release\n\nlet hasWarned = false;\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport default function LinkDeprecated(props: ComponentProps<typeof Link>) {\n if (!hasWarned) {\n console.warn(\n `\\n\\nDEPRECATION WARNING: The import for \\`Link\\` from next-intl has changed.\n\nPreviously: import {Link} from 'next-intl';\nNow: import Link from 'next-intl/link';\n\nPlease upgrade your import accordingly. See also https://next-intl-docs.vercel.app/docs/next-13/navigation#link\\n\\n`\n );\n hasWarned = true;\n }\n\n return <Link {...props} />;\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","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","/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nimport Link from './Link';\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n\n/** @deprecated Is available as `import Link from 'next-intl/link'` now. */\nexport const LocalizedLink = Link;\nexport {default as Link} from './Link';\n\nexport {default as useLocalizedRouter} from './useLocalizedRouter';\n","import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href: string) {\n return router.push(localize(href));\n },\n replace(href: string) {\n return router.replace(localize(href));\n },\n prefetch(href: string) {\n return router.prefetch(localize(href));\n }\n };\n }, [locale, router]);\n}\n"],"names":["LOCALE_SEGMENT_NAME","useClientLocale","params","useParams","useLocale","isLocalHref","href","host","hostname","test","localizeHref","locale","defaultLocale","pathname","startsWith","isRelativeHref","isSwitchingLocale","isPathnamePrefixed","prefix","hasPathnamePrefixed","prefixHref","prefixedHref","localizePathname","_extends","localizedHref","_excluded","BaseLink","_ref","ref","prefetch","rest","_objectWithoutPropertiesLoose","usePathname","isChangingLocale","_useState","useState","setLocalizedHref","useEffect","undefined","React","createElement","NextLink","BaseLink$1","forwardRef","Link","Link$1","hasWarned","LinkDeprecated","props","console","warn","NextIntlClientProvider","router","children","now","useRouter","error","Date","Error","IntlProvider","LocalizedLink","useNextRouter","useMemo","localize","window","location","push","replace"],"mappings":"goBAQO,IAAMA,EAAsB,SCJrB,SAAUC,IACtB,IAEMC,EAASC,EAAAA,YAQf,OAPID,EAAOF,GACAE,EAAOF,GAGPI,EAASA,WAItB,CCLM,SAAUC,EAAYC,GAC1B,MAAoB,iBAATA,EACW,MAAbA,EAAKC,MAAiC,MAAjBD,EAAKE,UAEb,YAAYC,KAAKH,EAGzC,CAcM,SAAUI,EACdJ,EACAK,EACAC,EACAC,GAEA,QAHA,IAAAD,IAAAA,EAAwBD,IAGnBN,EAAYC,IAhCb,SAAyBA,GAC7B,IAAMO,EAA2B,iBAATP,EAAoBA,EAAKO,SAAWP,EAC5D,OAAmB,MAAZO,IAAqBA,EAASC,WAAW,IAClD,CA6B4BC,CAAeT,GACvC,OAAOA,EAGT,IAAMU,EAAoBL,IAAWC,EAC/BK,EACM,MAAVN,GA2CY,SAAoBA,EAAgBE,GAClD,IAAMK,MAAaP,EACnB,OAAOE,IAAaK,GAAUL,EAASC,WAAcI,EAAM,IAC7D,CA9CsBC,CAAoBR,EAAQE,GAGhD,OAFqBI,GAAsBD,IAEb,MAAVL,EACXS,EAAWd,EAAMK,GAGnBL,CACT,CAOgB,SAAAc,EAAWd,EAA0BK,GACnD,IAAIU,EAUJ,MAToB,iBAATf,EACTe,EAAeC,EAAiBX,EAAQL,IAExCe,EAAYE,EAAOjB,GAAAA,GACfA,EAAKO,WACPQ,E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vB,EAAA,CAAA,WAAA,SAAA,OAYW,SAAA0B,EAAsBxB,GAKtC,IACFyB,EALJC,EAAQ1B,EAAR0B,SACA1C,EAAMgB,EAANhB,OACA2C,EAAG3B,EAAH2B,IACGxB,EAAIC,EAAAJ,EAAAF,GAGP,IAGE2B,EAASG,EAASA,WACnB,CAAC,MAAOC,GACP,CAgBF,IAXK7C,GAAUyC,IACbzC,EAASyC,EAAOzC,QAMC,iBAAR2C,IACTA,EAAM,IAAIG,KAAKH,KAGZ3C,EACH,MAAM,IAAI+C,WAGJpB,GAIR,OACEC,UAACC,cAAAmB,EAAYA,aAAApC,EAAA,CAACZ,OAAQA,EAAQ2C,IAAKA,GAASxB,GACzCuB,EAGP,CChDA,IAAIP,GAAY,ECcHc,EAAgBhB,gIDZf,WAQZ,OAPKE,IACHG,QAAQC,KAAI,gSAGZJ,GAAY,GESF,WACZ,IAAMM,EAASS,EAAAA,YACTlD,EAASV,IAEf,OAAO6D,EAAOA,SAAC,WACb,SAASC,EAASzD,GAChB,OAAOI,EAAaJ,EAAMK,EAAQA,EAAQqD,OAAOC,SAASpD,SAC5D,CAEA,OAAAU,KACK6B,EAAM,CACTc,KAAI,SAAC5D,GACH,OAAO8C,EAAOc,KAAKH,EAASzD,GAC7B,EACD6D,QAAO,SAAC7D,GACN,OAAO8C,EAAOe,QAAQJ,EAASzD,GAChC,EACDuB,SAAQ,SAACvB,GACP,OAAO8C,EAAOvB,SAASkC,EAASzD,GAClC,GAEJ,GAAG,CAACK,EAAQyC,GACd,CF5BSG,EACT"}
|
package/dist/src/link/Link.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentProps } from 'react';
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
2
|
import BaseLink from '../shared/BaseLink';
|
|
3
3
|
type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
4
4
|
locale?: string;
|
|
@@ -23,5 +23,5 @@ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
|
23
23
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
24
24
|
* page to be overwritten before the user even decides to change the locale.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
export
|
|
26
|
+
declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
27
|
+
export default _default;
|
package/dist/src/link/Link.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
2
|
import useClientLocale from '../client/useClientLocale';
|
|
3
3
|
import BaseLink from '../shared/BaseLink';
|
|
4
|
+
function Link({ locale, ...rest }, ref) {
|
|
5
|
+
const defaultLocale = useClientLocale();
|
|
6
|
+
return React.createElement(BaseLink, { ref: ref, locale: locale || defaultLocale, ...rest });
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
9
|
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
6
10
|
* necessary.
|
|
@@ -21,8 +25,5 @@ import BaseLink from '../shared/BaseLink';
|
|
|
21
25
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
22
26
|
* page to be overwritten before the user even decides to change the locale.
|
|
23
27
|
*/
|
|
24
|
-
export default
|
|
25
|
-
const defaultLocale = useClientLocale();
|
|
26
|
-
return React.createElement(BaseLink, { locale: locale || defaultLocale, ...rest });
|
|
27
|
-
}
|
|
28
|
+
export default forwardRef(Link);
|
|
28
29
|
//# sourceMappingURL=Link.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../../src/link/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Link.js","sourceRoot":"","sources":["../../../src/link/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAC,MAAM,OAAO,CAAC;AACxD,OAAO,eAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAM1C,SAAS,IAAI,CAAC,EAAC,MAAM,EAAE,GAAG,IAAI,EAAQ,EAAE,GAAiB;IACvD,MAAM,aAAa,GAAG,eAAe,EAAE,CAAC;IACxC,OAAO,oBAAC,QAAQ,IAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,KAAM,IAAI,GAAI,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAe,UAAU,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -71,16 +71,14 @@ export default function createMiddleware(config) {
|
|
|
71
71
|
const domainConfigs = ((_b = configWithDefaults.domains) === null || _b === void 0 ? void 0 : _b.filter((curDomain) => isLocaleSupportedOnDomain(locale, curDomain))) || [];
|
|
72
72
|
const hasUnknownHost = configWithDefaults.domains != null && !domain;
|
|
73
73
|
function getResponseInit() {
|
|
74
|
-
|
|
74
|
+
const responseInit = {
|
|
75
|
+
request: {
|
|
76
|
+
headers: request.headers
|
|
77
|
+
}
|
|
78
|
+
};
|
|
75
79
|
if (hasOutdatedCookie) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
request.headers.set(HEADER_LOCALE_NAME, locale);
|
|
79
|
-
responseInit = {
|
|
80
|
-
request: {
|
|
81
|
-
headers: request.headers
|
|
82
|
-
}
|
|
83
|
-
};
|
|
80
|
+
responseInit.request.headers = new Headers(responseInit.request.headers);
|
|
81
|
+
responseInit.request.headers.set(HEADER_LOCALE_NAME, locale);
|
|
84
82
|
}
|
|
85
83
|
return responseInit;
|
|
86
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/middleware/middleware.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAC,MAAM,aAAa,CAAC;AACtD,OAAO,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;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AQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;SAClD;QAED,IACE,kBAAkB,CAAC,cAAc;YACjC,kBAAkB,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EACrC;YACA,QAAQ,CAAC,OAAO,CAAC,GAAG,CAClB,MAAM,EACN,4BAA4B,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAC1D,CAAC;SACH;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -6,15 +6,19 @@ export default function useHook(hookName, promise) {
|
|
|
6
6
|
catch (error) {
|
|
7
7
|
if (error instanceof TypeError &&
|
|
8
8
|
error.message.includes("Cannot read properties of null (reading 'use')")) {
|
|
9
|
-
throw new Error(`\`${hookName}\` is not callable within an async component.
|
|
9
|
+
throw new Error(`\`${hookName}\` is not callable within an async component. To resolve this, you can split your component into two, leaving the async code in the first one and moving the usage of \`${hookName}\` to the second one.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Example:
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
async function Profile() {
|
|
14
|
+
const user = await getUser();
|
|
15
|
+
return <ProfileContent user={user} />;
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
function ProfileContent({user}) {
|
|
19
|
+
// Call \`${hookName}\` here and use the \`user\` prop
|
|
20
|
+
return ...;
|
|
21
|
+
}`, { cause: error });
|
|
18
22
|
}
|
|
19
23
|
else {
|
|
20
24
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHook.js","sourceRoot":"","sources":["../../../src/react-server/useHook.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,QAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC;KACrB;IAAC,OAAO,KAAU,EAAE;QACnB,IACE,KAAK,YAAY,SAAS;YAC1B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,gDAAgD,CAAC,EACxE;YACA,MAAM,IAAI,KAAK,CACb,KAAK,QAAQ
|
|
1
|
+
{"version":3,"file":"useHook.js","sourceRoot":"","sources":["../../../src/react-server/useHook.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,QAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC;KACrB;IAAC,OAAO,KAAU,EAAE;QACnB,IACE,KAAK,YAAY,SAAS;YAC1B,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,gDAAgD,CAAC,EACxE;YACA,MAAM,IAAI,KAAK,CACb,KAAK,QAAQ,2KAA2K,QAAQ;;;;;;;;;;cAU1L,QAAQ;;EAEpB,EACM,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;SACH;aAAM;YACL,MAAM,KAAK,CAAC;SACb;KACF;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "2.15.0-beta.
|
|
3
|
+
"version": "2.15.0-beta.4",
|
|
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.",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
63
63
|
"negotiator": "^0.6.3",
|
|
64
64
|
"server-only": "0.0.1",
|
|
65
|
-
"use-intl": "^2.14.
|
|
65
|
+
"use-intl": "^2.14.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
package/src/link/Link.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {ComponentProps} from 'react';
|
|
1
|
+
import React, {ComponentProps, forwardRef} from 'react';
|
|
2
2
|
import useClientLocale from '../client/useClientLocale';
|
|
3
3
|
import BaseLink from '../shared/BaseLink';
|
|
4
4
|
|
|
@@ -6,6 +6,11 @@ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
|
6
6
|
locale?: string;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
function Link({locale, ...rest}: Props, ref: Props['ref']) {
|
|
10
|
+
const defaultLocale = useClientLocale();
|
|
11
|
+
return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
/**
|
|
10
15
|
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
11
16
|
* necessary.
|
|
@@ -26,7 +31,4 @@ type Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {
|
|
|
26
31
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
27
32
|
* page to be overwritten before the user even decides to change the locale.
|
|
28
33
|
*/
|
|
29
|
-
export default
|
|
30
|
-
const defaultLocale = useClientLocale();
|
|
31
|
-
return <BaseLink locale={locale || defaultLocale} {...rest} />;
|
|
32
|
-
}
|
|
34
|
+
export default forwardRef(Link);
|
|
@@ -104,17 +104,17 @@ export default function createMiddleware(config: MiddlewareConfig) {
|
|
|
104
104
|
const hasUnknownHost = configWithDefaults.domains != null && !domain;
|
|
105
105
|
|
|
106
106
|
function getResponseInit() {
|
|
107
|
-
|
|
107
|
+
const responseInit = {
|
|
108
|
+
request: {
|
|
109
|
+
headers: request.headers
|
|
110
|
+
}
|
|
111
|
+
};
|
|
108
112
|
|
|
109
113
|
if (hasOutdatedCookie) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
responseInit
|
|
114
|
-
request: {
|
|
115
|
-
headers: request.headers
|
|
116
|
-
}
|
|
117
|
-
};
|
|
114
|
+
responseInit.request.headers = new Headers(
|
|
115
|
+
responseInit.request.headers
|
|
116
|
+
);
|
|
117
|
+
responseInit.request.headers.set(HEADER_LOCALE_NAME, locale);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
return responseInit;
|
|
@@ -12,15 +12,19 @@ export default function useHook<Value>(
|
|
|
12
12
|
error.message.includes("Cannot read properties of null (reading 'use')")
|
|
13
13
|
) {
|
|
14
14
|
throw new Error(
|
|
15
|
-
`\`${hookName}\` is not callable within an async component.
|
|
15
|
+
`\`${hookName}\` is not callable within an async component. To resolve this, you can split your component into two, leaving the async code in the first one and moving the usage of \`${hookName}\` to the second one.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Example:
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
async function Profile() {
|
|
20
|
+
const user = await getUser();
|
|
21
|
+
return <ProfileContent user={user} />;
|
|
22
|
+
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
function ProfileContent({user}) {
|
|
25
|
+
// Call \`${hookName}\` here and use the \`user\` prop
|
|
26
|
+
return ...;
|
|
27
|
+
}`,
|
|
24
28
|
{cause: error}
|
|
25
29
|
);
|
|
26
30
|
} else {
|