next-intl 2.11.0-beta.2 → 2.11.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.
- package/dist/client/index.d.ts +2 -0
- package/dist/client/next-intl.esm.js +38 -31
- package/dist/client/next-intl.esm.js.map +1 -1
- package/dist/client/next-intl.esm2.js +37 -0
- package/dist/client/next-intl.esm2.js.map +1 -0
- package/dist/client/useLocalizedRouter.d.ts +8 -0
- package/dist/client/useUnlocalizedPathname.d.ts +2 -0
- package/dist/next-intl.cjs.development.js +13 -1
- 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/next-intl.esm.js +5 -3
- package/dist/next-intl.esm.js.map +1 -1
- package/dist/react-client/next-intl.esm.js +13 -4
- package/dist/react-client/next-intl.esm.js.map +1 -1
- package/dist/react-client/next-intl.esm2.js +4 -41
- package/dist/react-client/next-intl.esm2.js.map +1 -1
- package/dist/react-client/useLocalizedRouter.d.ts +1 -1
- package/dist/shared/next-intl.esm.js +1 -1
- package/dist/shared/next-intl.esm2.js +4 -10
- package/dist/shared/next-intl.esm2.js.map +1 -1
- package/dist/shared/next-intl.esm3.js +10 -4
- package/dist/shared/next-intl.esm3.js.map +1 -1
- package/dist/src/client/index.d.ts +2 -0
- package/dist/src/client/index.js +2 -0
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/client/useLocalizedRouter.d.ts +8 -0
- package/dist/src/client/useLocalizedRouter.js +34 -0
- package/dist/src/client/useLocalizedRouter.js.map +1 -0
- package/dist/src/client/useUnlocalizedPathname.d.ts +2 -0
- package/dist/src/client/useUnlocalizedPathname.js +10 -0
- package/dist/src/client/useUnlocalizedPathname.js.map +1 -0
- package/dist/src/react-client/useLocalizedRouter.d.ts +1 -1
- package/dist/src/react-client/useLocalizedRouter.js +9 -31
- package/dist/src/react-client/useLocalizedRouter.js.map +1 -1
- package/dist/src/react-server/useConfig.js +3 -2
- package/dist/src/react-server/useConfig.js.map +1 -1
- package/package.json +2 -2
- package/src/client/index.tsx +2 -0
- package/src/client/useLocalizedRouter.tsx +42 -0
- package/src/client/useUnlocalizedPathname.tsx +11 -0
- package/src/react-client/useLocalizedRouter.tsx +12 -37
- package/src/react-server/useConfig.tsx +7 -2
- package/withNextIntl.js +3 -0
package/dist/client/index.d.ts
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRouter } from 'next/
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
router = useRouter();
|
|
18
|
-
} catch (error) {// Calling `useRouter` is not supported in the app folder
|
|
19
|
-
} // The router can be undefined if used in a context outside
|
|
20
|
-
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!locale && router) {
|
|
24
|
-
locale = router.locale;
|
|
1
|
+
import { extends as _extends } from '../_virtual/next-intl.esm.js';
|
|
2
|
+
import { useRouter } from 'next/navigation';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { COOKIE_LOCALE_NAME } from '../shared/next-intl.esm2.js';
|
|
5
|
+
import localizeHref from '../shared/next-intl.esm3.js';
|
|
6
|
+
|
|
7
|
+
function getCookieValueByName(name) {
|
|
8
|
+
// https://stackoverflow.com/a/15724300/343045
|
|
9
|
+
var value = "; " + document.cookie;
|
|
10
|
+
var parts = value.split("; " + name + "=");
|
|
11
|
+
|
|
12
|
+
if (parts.length === 2) {
|
|
13
|
+
var _parts$pop;
|
|
14
|
+
|
|
15
|
+
var part = (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift();
|
|
16
|
+
if (part) return part;
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
throw new Error("Unable to find next-intl cookie, have you configured the middleware?");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getCookieLocale() {
|
|
23
|
+
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
function useLocalizedRouter() {
|
|
27
|
+
var router = useRouter();
|
|
28
|
+
return useMemo(function () {
|
|
29
|
+
return _extends({}, router, {
|
|
30
|
+
push: function push(href) {
|
|
31
|
+
return router.push(localizeHref(getCookieLocale(), href));
|
|
32
|
+
},
|
|
33
|
+
replace: function replace(href) {
|
|
34
|
+
return router.replace(localizeHref(getCookieLocale(), href));
|
|
35
|
+
},
|
|
36
|
+
prefetch: function prefetch(href) {
|
|
37
|
+
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}, [router]);
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
export {
|
|
43
|
+
export { useLocalizedRouter as default };
|
|
37
44
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":["../../src/client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":["../../src/client/useLocalizedRouter.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport localizeHref from '../shared/localizeHref';\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\nfunction getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n\nexport default function useLocalizedRouter() {\n const router = useRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(getCookieLocale(), href));\n },\n replace(href: string) {\n return router.replace(localizeHref(getCookieLocale(), href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(getCookieLocale(), href));\n }\n }),\n [router]\n );\n}\n"],"names":["getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","COOKIE_LOCALE_NAME","useLocalizedRouter","router","useRouter","useMemo","push","href","localizeHref","replace","prefetch"],"mappings":";;;;;;AAKA,SAASA,oBAAT,CAA8BC,IAA9B,EAA0C;AACxC;AACA,EAAA,IAAMC,KAAK,GAAA,IAAA,GAAQC,QAAQ,CAACC,MAA5B,CAAA;AACA,EAAA,IAAMC,KAAK,GAAGH,KAAK,CAACI,KAAN,CAAA,IAAA,GAAiBL,IAAjB,GAAd,GAAA,CAAA,CAAA;;AACA,EAAA,IAAII,KAAK,CAACE,MAAN,KAAiB,CAArB,EAAwB;AAAA,IAAA,IAAA,UAAA,CAAA;;AACtB,IAAA,IAAMC,IAAI,GAAA,CAAA,UAAA,GAAGH,KAAK,CAACI,GAAN,EAAH,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,UAAA,CAAaH,KAAb,CAAmB,GAAnB,CAAA,CAAwBI,KAAxB,EAAb,CAAA;AACA,IAAIF,IAAAA,IAAJ,EAAU,OAAOA,IAAP,CAAA;AACX,GAAA;;AAED,EAAM,MAAA,IAAIG,KAAJ,CAAN,sEAAA,CAAA,CAAA;AAGD,CAAA;;AAED,SAASC,eAAT,GAAwB;AACtB,EAAOZ,OAAAA,oBAAoB,CAACa,kBAAD,CAA3B,CAAA;AACD,CAAA;;AAEa,SAAUC,kBAAV,GAA4B;AACxC,EAAMC,IAAAA,MAAM,GAAGC,SAAS,EAAxB,CAAA;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OAAA,QAAA,CAAA,EAAA,EACKF,MADL,EAAA;AAEEG,MAAAA,IAFF,EAEOC,SAAAA,IAAAA,CAAAA,IAFP,EAEmB;AACf,QAAOJ,OAAAA,MAAM,CAACG,IAAP,CAAYE,YAAY,CAACR,eAAe,EAAhB,EAAoBO,IAApB,CAAxB,CAAP,CAAA;AACD,OAJH;AAKEE,MAAAA,OALF,EAKUF,SAAAA,OAAAA,CAAAA,IALV,EAKsB;AAClB,QAAOJ,OAAAA,MAAM,CAACM,OAAP,CAAeD,YAAY,CAACR,eAAe,EAAhB,EAAoBO,IAApB,CAA3B,CAAP,CAAA;AACD,OAPH;AAQEG,MAAAA,QARF,EAQWH,SAAAA,QAAAA,CAAAA,IARX,EAQuB;AACnB,QAAOJ,OAAAA,MAAM,CAACO,QAAP,CAAgBF,YAAY,CAACR,eAAe,EAAhB,EAAoBO,IAApB,CAA5B,CAAP,CAAA;AACD,OAAA;AAVH,KAAA,CAAA,CAAA;AAAA,GADY,EAaZ,CAACJ,MAAD,CAbY,CAAd,CAAA;AAeD;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
|
|
2
|
+
import { useRouter } from 'next/router';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { IntlProvider } from 'use-intl';
|
|
5
|
+
|
|
6
|
+
var _excluded = ["children", "locale"];
|
|
7
|
+
function NextIntlClientProvider(_ref) {
|
|
8
|
+
var children = _ref.children,
|
|
9
|
+
locale = _ref.locale,
|
|
10
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
11
|
+
|
|
12
|
+
var router;
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
// Reading from context is practically ok to do conditionally
|
|
16
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
17
|
+
router = useRouter();
|
|
18
|
+
} catch (error) {// Calling `useRouter` is not supported in the app folder
|
|
19
|
+
} // The router can be undefined if used in a context outside
|
|
20
|
+
// of Next.js (e.g. unit tests, Storybook, ...)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if (!locale && router) {
|
|
24
|
+
locale = router.locale;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!locale) {
|
|
28
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing)." : undefined);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return React.createElement(IntlProvider, _extends({
|
|
32
|
+
locale: locale
|
|
33
|
+
}, rest), children);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { NextIntlClientProvider as default };
|
|
37
|
+
//# sourceMappingURL=next-intl.esm2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale'> & {\n locale?: string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\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 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} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["NextIntlClientProvider","children","locale","rest","router","useRouter","error","Error","process","env","NODE_ENV","undefined","React","createElement","IntlProvider"],"mappings":";;;;;;AAUwB,SAAAA,sBAAA,CAIhB,IAAA,EAAA;AAAA,EAHNC,IAAAA,QAGM,QAHNA,QAGM;AAAA,MAFNC,MAEM,QAFNA,MAEM;AAAA,MADHC,IACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAA,IAAIC,MAAJ,CAAA;;AACA,EAAI,IAAA;AACF;AACA;AACAA,IAAAA,MAAM,GAAGC,SAAS,EAAlB,CAAA;AACD,GAJD,CAIE,OAAOC,KAAP,EAAc;AAEf,GARK;AAWN;;;AACA,EAAA,IAAI,CAACJ,MAAD,IAAWE,MAAf,EAAuB;AACrBF,IAAAA,MAAM,GAAGE,MAAM,CAACF,MAAhB,CAAA;AACD,GAAA;;AAED,EAAI,IAAA,CAACA,MAAL,EAAa;AACX,IAAA,MAAM,IAAIK,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,+MADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OACEC,KAAA,CAAAC,aAAA,CAACC,YAAD,EAAA,QAAA,CAAA;AAAcZ,IAAAA,MAAM,EAAEA,MAAAA;AAAtB,GAAkCC,EAAAA,IAAlC,CACGF,EAAAA,QADH,CADF,CAAA;AAKD;;;;"}
|
|
@@ -96,6 +96,18 @@ function useLocalizedRouter() {
|
|
|
96
96
|
}, [router]);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// during the beta, remove for stable release
|
|
100
|
+
|
|
101
|
+
var hasWarned = false;
|
|
102
|
+
function useLocalizedRouterDeprecated() {
|
|
103
|
+
if (!hasWarned) {
|
|
104
|
+
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");
|
|
105
|
+
hasWarned = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return useLocalizedRouter();
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
var _excluded$1 = ["href", "locale"];
|
|
100
112
|
function createLocalizedLinkComponent(useLocale) {
|
|
101
113
|
/**
|
|
@@ -163,7 +175,7 @@ function NextIntlClientProvider(_ref) {
|
|
|
163
175
|
|
|
164
176
|
exports.LocalizedLink = LocalizedLink;
|
|
165
177
|
exports.NextIntlProvider = NextIntlClientProvider;
|
|
166
|
-
exports.useLocalizedRouter =
|
|
178
|
+
exports.useLocalizedRouter = useLocalizedRouterDeprecated;
|
|
167
179
|
Object.keys(useIntl).forEach(function (k) {
|
|
168
180
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
169
181
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/constants.tsx","../src/shared/localizeHref.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/createLocalizedLinkComponent.tsx","../src/react-client/LocalizedLink.tsx","../src/client/NextIntlClientProvider.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","export default function localizeHref(locale: string, href: string) {\n let localizedHref = '/' + locale;\n\n if (href !== '/') {\n localizedHref += href;\n }\n\n return localizedHref;\n}\n","import {useRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport localizeHref from '../shared/localizeHref';\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\nfunction getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n\nexport default function useLocalizedRouter() {\n const router = useRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(getCookieLocale(), href));\n },\n replace(href: string) {\n return router.replace(localizeHref(getCookieLocale(), href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(getCookieLocale(), href));\n }\n }),\n [router]\n );\n}\n","import Link from 'next/link';\nimport React, {ComponentProps, forwardRef} from 'react';\nimport localizeHref from './localizeHref';\n\ntype Props = Omit<ComponentProps<typeof Link>, 'locale'> & {\n locale?: string;\n};\n\nexport default function createLocalizedLinkComponent(useLocale: () => string) {\n /**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n */\n function LocalizedLink({href, locale, ...rest}: Props, ref: Props['ref']) {\n const curLocale = useLocale();\n if (!locale) locale = curLocale;\n\n let localizedHref;\n if (typeof href === 'string') {\n localizedHref = localizeHref(locale, href);\n } else {\n localizedHref = {...href};\n if (href.pathname) {\n localizedHref.pathname = localizeHref(locale, href.pathname);\n }\n }\n\n return <Link ref={ref} href={localizedHref} {...rest} />;\n }\n\n return forwardRef(LocalizedLink);\n}\n","import {useLocale} from 'use-intl';\nimport createLocalizedLinkComponent from '../shared/createLocalizedLinkComponent';\n\nconst LocalizedLink = createLocalizedLinkComponent(useLocale);\n\nexport default LocalizedLink;\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'> & {\n locale?: string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\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 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} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["COOKIE_LOCALE_NAME","localizeHref","locale","href","localizedHref","getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","useLocalizedRouter","router","useRouter","useMemo","push","replace","prefetch","createLocalizedLinkComponent","useLocale","LocalizedLink","ref","rest","_excluded","curLocale","pathname","React","createElement","Link","forwardRef","NextIntlClientProvider","children","error","IntlProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACO,IAAMA,kBAAkB,GAAG,aAA3B;;ACFO,SAAUC,YAAV,CAAuBC,MAAvB,EAAuCC,IAAvC,EAAmD;AAC/D,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,IAAI,KAAK,GAAb,EAAkB;AAChBC,IAAAA,aAAa,IAAID,IAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;ACHD,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;;AAED,SAASC,eAAT,GAAwB;AACtB,EAAOZ,OAAAA,oBAAoB,CAACL,kBAAD,CAA3B,CAAA;AACD,CAAA;;AAEa,SAAUkB,kBAAV,GAA4B;AACxC,EAAMC,IAAAA,MAAM,GAAGC,oBAAS,EAAxB,CAAA;AAEA,EAAA,OAAOC,aAAO,CACZ,YAAA;AAAA,IAAA,OAAA,QAAA,CAAA,EAAA,EACKF,MADL,EAAA;AAEEG,MAAAA,IAFF,EAEOnB,SAAAA,IAAAA,CAAAA,IAFP,EAEmB;AACf,QAAOgB,OAAAA,MAAM,CAACG,IAAP,CAAYrB,YAAY,CAACgB,eAAe,EAAhB,EAAoBd,IAApB,CAAxB,CAAP,CAAA;AACD,OAJH;AAKEoB,MAAAA,OALF,EAKUpB,SAAAA,OAAAA,CAAAA,IALV,EAKsB;AAClB,QAAOgB,OAAAA,MAAM,CAACI,OAAP,CAAetB,YAAY,CAACgB,eAAe,EAAhB,EAAoBd,IAApB,CAA3B,CAAP,CAAA;AACD,OAPH;AAQEqB,MAAAA,QARF,EAQWrB,SAAAA,QAAAA,CAAAA,IARX,EAQuB;AACnB,QAAOgB,OAAAA,MAAM,CAACK,QAAP,CAAgBvB,YAAY,CAACgB,eAAe,EAAhB,EAAoBd,IAApB,CAA5B,CAAP,CAAA;AACD,OAAA;AAVH,KAAA,CAAA,CAAA;AAAA,GADY,EAaZ,CAACgB,MAAD,CAbY,CAAd,CAAA;AAeD;;;
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.development.js","sources":["../src/shared/constants.tsx","../src/shared/localizeHref.tsx","../src/client/useLocalizedRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/createLocalizedLinkComponent.tsx","../src/react-client/LocalizedLink.tsx","../src/client/NextIntlClientProvider.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","export default function localizeHref(locale: string, href: string) {\n let localizedHref = '/' + locale;\n\n if (href !== '/') {\n localizedHref += href;\n }\n\n return localizedHref;\n}\n","import {useRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport localizeHref from '../shared/localizeHref';\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\nfunction getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n\nexport default function useLocalizedRouter() {\n const router = useRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(getCookieLocale(), href));\n },\n replace(href: string) {\n return router.replace(localizeHref(getCookieLocale(), href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(getCookieLocale(), href));\n }\n }),\n [router]\n );\n}\n","import useLocalizedRouter from '../client/useLocalizedRouter';\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 useLocalizedRouter();\n}\n","import Link from 'next/link';\nimport React, {ComponentProps, forwardRef} from 'react';\nimport localizeHref from './localizeHref';\n\ntype Props = Omit<ComponentProps<typeof Link>, 'locale'> & {\n locale?: string;\n};\n\nexport default function createLocalizedLinkComponent(useLocale: () => string) {\n /**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n */\n function LocalizedLink({href, locale, ...rest}: Props, ref: Props['ref']) {\n const curLocale = useLocale();\n if (!locale) locale = curLocale;\n\n let localizedHref;\n if (typeof href === 'string') {\n localizedHref = localizeHref(locale, href);\n } else {\n localizedHref = {...href};\n if (href.pathname) {\n localizedHref.pathname = localizeHref(locale, href.pathname);\n }\n }\n\n return <Link ref={ref} href={localizedHref} {...rest} />;\n }\n\n return forwardRef(LocalizedLink);\n}\n","import {useLocale} from 'use-intl';\nimport createLocalizedLinkComponent from '../shared/createLocalizedLinkComponent';\n\nconst LocalizedLink = createLocalizedLinkComponent(useLocale);\n\nexport default LocalizedLink;\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'> & {\n locale?: string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\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 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} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["COOKIE_LOCALE_NAME","localizeHref","locale","href","localizedHref","getCookieValueByName","name","value","document","cookie","parts","split","length","part","pop","shift","Error","getCookieLocale","useLocalizedRouter","router","useRouter","useMemo","push","replace","prefetch","hasWarned","useLocalizedRouterDeprecated","console","warn","createLocalizedLinkComponent","useLocale","LocalizedLink","ref","rest","_excluded","curLocale","pathname","React","createElement","Link","forwardRef","NextIntlClientProvider","children","error","IntlProvider"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("use-intl"),r=require("next/navigation"),t=require("react"),n=require("next/link"),o=require("next/router");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=u(t),a=u(n);function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("use-intl"),r=require("next/navigation"),t=require("react"),n=require("next/link"),o=require("next/router");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=u(t),a=u(n);function l(){return l=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},l.apply(this,arguments)}function c(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r.indexOf(t=u[n])>=0||(o[t]=e[t]);return o}function f(e,r){var t="/"+e;return"/"!==r&&(t+=r),t}function s(){return function(e){var r=("; "+document.cookie).split("; NEXT_LOCALE=");if(2===r.length){var t,n=null==(t=r.pop())?void 0:t.split(";").shift();if(n)return n}throw new Error("Unable to find next-intl cookie, have you configured the middleware?")}()}var p=!1,d=["href","locale"];function h(e){return t.forwardRef((function(r,t){var n,o=r.href,u=r.locale,s=c(r,d),p=e();return u||(u=p),"string"==typeof o?n=f(u,o):(n=l({},o),o.pathname&&(n.pathname=f(u,o.pathname))),i.default.createElement(a.default,l({ref:t,href:n},s))}))}var v=["children","locale"];exports.LocalizedLink=h(e.useLocale),exports.NextIntlProvider=function(r){var t,n=r.children,u=r.locale,a=c(r,v);try{t=o.useRouter()}catch(e){}if(!u&&t&&(u=t.locale),!u)throw new Error(void 0);return i.default.createElement(e.IntlProvider,l({locale:u},a),n)},exports.useLocalizedRouter=function(){return p||(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"),p=!0),function(){var e=r.useRouter();return t.useMemo((function(){return l({},e,{push:function(r){return e.push(f(s(),r))},replace:function(r){return e.replace(f(s(),r))},prefetch:function(r){return e.prefetch(f(s(),r))}})}),[e])}()},Object.keys(e).forEach((function(r){"default"===r||exports.hasOwnProperty(r)||Object.defineProperty(exports,r,{enumerable:!0,get:function(){return e[r]}})}));
|
|
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/localizeHref.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/createLocalizedLinkComponent.tsx","../src/react-client/LocalizedLink.tsx","../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["export default function localizeHref(locale: string, href: string) {\n let localizedHref = '/' + locale;\n\n if (href !== '/') {\n localizedHref += href;\n }\n\n return localizedHref;\n}\n","import {useRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport localizeHref from '../shared/localizeHref';\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\nfunction getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n\nexport default function useLocalizedRouter() {\n const router = useRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(getCookieLocale(), href));\n },\n replace(href: string) {\n return router.replace(localizeHref(getCookieLocale(), href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(getCookieLocale(), href));\n }\n }),\n [router]\n );\n}\n","import Link from 'next/link';\nimport React, {ComponentProps, forwardRef} from 'react';\nimport localizeHref from './localizeHref';\n\ntype Props = Omit<ComponentProps<typeof Link>, 'locale'> & {\n locale?: string;\n};\n\nexport default function createLocalizedLinkComponent(useLocale: () => string) {\n /**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n */\n function LocalizedLink({href, locale, ...rest}: Props, ref: Props['ref']) {\n const curLocale = useLocale();\n if (!locale) locale = curLocale;\n\n let localizedHref;\n if (typeof href === 'string') {\n localizedHref = localizeHref(locale, href);\n } else {\n localizedHref = {...href};\n if (href.pathname) {\n localizedHref.pathname = localizeHref(locale, href.pathname);\n }\n }\n\n return <Link ref={ref} href={localizedHref} {...rest} />;\n }\n\n return forwardRef(LocalizedLink);\n}\n","import {useLocale} from 'use-intl';\nimport createLocalizedLinkComponent from '../shared/createLocalizedLinkComponent';\n\nconst LocalizedLink = createLocalizedLinkComponent(useLocale);\n\nexport default LocalizedLink;\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'> & {\n locale?: string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\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 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} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["localizeHref","locale","href","localizedHref","getCookieLocale","getCookieValueByName","name","parts","document","cookie","split","length","_parts$pop","part","pop","shift","Error","createLocalizedLinkComponent","useLocale","forwardRef","LocalizedLink","ref","rest","_objectWithoutPropertiesLoose","_ref","_excluded","curLocale","pathname","React","createElement","Link","_extends","children","router","useRouter","error","undefined","IntlProvider","useMemo","push","replace","prefetch"],"mappings":"4mBAAc,SAAUA,EAAaC,EAAgBC,GAC/CC,IAAAA,EAAgB,IAAMF,EAM1B,MAJa,MAATC,IACFC,GAAiBD,GAGZC,ECYT,SAASC,IACAC,OAfT,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,wEAMOX,
|
|
1
|
+
{"version":3,"file":"next-intl.cjs.production.min.js","sources":["../src/shared/localizeHref.tsx","../src/client/useLocalizedRouter.tsx","../src/react-client/useLocalizedRouter.tsx","../src/shared/createLocalizedLinkComponent.tsx","../src/react-client/LocalizedLink.tsx","../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["export default function localizeHref(locale: string, href: string) {\n let localizedHref = '/' + locale;\n\n if (href !== '/') {\n localizedHref += href;\n }\n\n return localizedHref;\n}\n","import {useRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport localizeHref from '../shared/localizeHref';\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\nfunction getCookieLocale() {\n return getCookieValueByName(COOKIE_LOCALE_NAME);\n}\n\nexport default function useLocalizedRouter() {\n const router = useRouter();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(getCookieLocale(), href));\n },\n replace(href: string) {\n return router.replace(localizeHref(getCookieLocale(), href));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(getCookieLocale(), href));\n }\n }),\n [router]\n );\n}\n","import useLocalizedRouter from '../client/useLocalizedRouter';\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 useLocalizedRouter();\n}\n","import Link from 'next/link';\nimport React, {ComponentProps, forwardRef} from 'react';\nimport localizeHref from './localizeHref';\n\ntype Props = Omit<ComponentProps<typeof Link>, 'locale'> & {\n locale?: string;\n};\n\nexport default function createLocalizedLinkComponent(useLocale: () => string) {\n /**\n * Wraps `next/link` and prefixes the `href` with the current locale.\n */\n function LocalizedLink({href, locale, ...rest}: Props, ref: Props['ref']) {\n const curLocale = useLocale();\n if (!locale) locale = curLocale;\n\n let localizedHref;\n if (typeof href === 'string') {\n localizedHref = localizeHref(locale, href);\n } else {\n localizedHref = {...href};\n if (href.pathname) {\n localizedHref.pathname = localizeHref(locale, href.pathname);\n }\n }\n\n return <Link ref={ref} href={localizedHref} {...rest} />;\n }\n\n return forwardRef(LocalizedLink);\n}\n","import {useLocale} from 'use-intl';\nimport createLocalizedLinkComponent from '../shared/createLocalizedLinkComponent';\n\nconst LocalizedLink = createLocalizedLinkComponent(useLocale);\n\nexport default LocalizedLink;\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'> & {\n locale?: string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\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 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} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"names":["localizeHref","locale","href","localizedHref","getCookieLocale","getCookieValueByName","name","parts","document","cookie","split","length","_parts$pop","part","pop","shift","Error","hasWarned","createLocalizedLinkComponent","useLocale","forwardRef","LocalizedLink","ref","rest","_objectWithoutPropertiesLoose","_ref","_excluded","curLocale","pathname","React","createElement","Link","_extends","children","router","useRouter","error","undefined","IntlProvider","console","warn","useMemo","push","replace","prefetch","useLocalizedRouter"],"mappings":"4mBAAc,SAAUA,EAAaC,EAAgBC,GAC/CC,IAAAA,EAAgB,IAAMF,EAM1B,MAJa,MAATC,IACFC,GAAiBD,GAGZC,ECYT,SAASC,IACAC,OAfT,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,wEAMOX,GCfT,IAAIY,GAAY,sBCGQ,SAAAC,EAA6BC,GAqB5CC,OAAAA,EAAAA,YAjBEC,SAA8CC,EAAAA,GAA/BpB,IAIlBC,EAJkBD,IAAAA,KAAMD,IAAAA,OAAWsB,EAA+BC,EAAAC,EAAAC,GAChEC,EAAYR,IAalB,OAZKlB,IAAQA,EAAS0B,GAGF,iBAATzB,EACTC,EAAgBH,EAAaC,EAAQC,IAErCC,EAAoBD,EAAAA,GAAAA,GAChBA,EAAK0B,WACPzB,EAAcyB,SAAW5B,EAAaC,EAAQC,EAAK0B,YAIhDC,UAACC,cAAAC,EAAD,QAAAC,EAAA,CAAMV,IAAKA,EAAKpB,KAAMC,GAAmBoB,OCvBpD,kDAAsBL,EAA6BC,EAADA,oCCO1B,SAIhBM,GAHNQ,IAIIC,EAJJD,IAAAA,SACAhC,IAAAA,OACGsB,EACGC,EAAAC,EAAAC,GAEF,IAGFQ,EAASC,EAASA,YAClB,MAAOC,IAUL,IAJCnC,GAAUiC,IACbjC,EAASiC,EAAOjC,SAGbA,EACH,MAAM,IAAIe,WAGJqB,GAIR,OACER,UAAAC,cAACQ,EAADA,aAAAN,EAAA,CAAc/B,OAAQA,GAAYsB,GAC/BU,+BHjCO,WAQZ,OAPKhB,IACHsB,QAAQC,KAAR,gSAGAvB,GAAY,GDWF,WACNiB,IAAAA,EAASC,EAAAA,YAEf,OAAOM,EAAOA,SACZ,WAAA,OAAAT,EAAA,GACKE,EADL,CAEEQ,KAAKxC,SAAAA,GACIgC,OAAAA,EAAOQ,KAAK1C,EAAaI,IAAmBF,KAErDyC,QAAQzC,SAAAA,GACCgC,OAAAA,EAAOS,QAAQ3C,EAAaI,IAAmBF,KAExD0C,SAAS1C,SAAAA,GACAgC,OAAAA,EAAOU,SAAS5C,EAAaI,IAAmBF,SAG3D,CAACgC,ICxBIW"}
|
package/dist/next-intl.esm.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from 'use-intl';
|
|
2
|
-
export { default as useLocalizedRouter } from './react-client/next-intl.
|
|
3
|
-
export { default as LocalizedLink } from './react-client/next-intl.
|
|
4
|
-
export { default as NextIntlProvider } from './client/next-intl.
|
|
2
|
+
export { default as useLocalizedRouter } from './react-client/next-intl.esm.js';
|
|
3
|
+
export { default as LocalizedLink } from './react-client/next-intl.esm2.js';
|
|
4
|
+
export { default as NextIntlProvider } from './client/next-intl.esm2.js';
|
|
5
|
+
import 'next/navigation';
|
|
6
|
+
import 'react';
|
|
5
7
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import createLocalizedLinkComponent from '../shared/next-intl.esm.js';
|
|
1
|
+
import useLocalizedRouter from '../client/next-intl.esm.js';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
// during the beta, remove for stable release
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
var hasWarned = false;
|
|
6
|
+
function useLocalizedRouterDeprecated() {
|
|
7
|
+
if (!hasWarned) {
|
|
8
|
+
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");
|
|
9
|
+
hasWarned = true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return useLocalizedRouter();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { useLocalizedRouterDeprecated as default };
|
|
7
16
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":["../../src/react-client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":["../../src/react-client/useLocalizedRouter.tsx"],"sourcesContent":["import useLocalizedRouter from '../client/useLocalizedRouter';\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 useLocalizedRouter();\n}\n"],"names":["hasWarned","useLocalizedRouterDeprecated","console","warn","useLocalizedRouter"],"mappings":";;AAGA;;AAEA,IAAIA,SAAS,GAAG,KAAhB,CAAA;AAEc,SAAUC,4BAAV,GAAsC;AAClD,EAAI,IAAA,CAACD,SAAL,EAAgB;AACdE,IAAAA,OAAO,CAACC,IAAR,CAAA,8RAAA,CAAA,CAAA;AAGAH,IAAAA,SAAS,GAAG,IAAZ,CAAA;AACD,GAAA;;AAED,EAAA,OAAOI,kBAAkB,EAAzB,CAAA;AACD;;;;"}
|
|
@@ -1,44 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
import { COOKIE_LOCALE_NAME } from '../shared/next-intl.esm3.js';
|
|
5
|
-
import localizeHref from '../shared/next-intl.esm2.js';
|
|
1
|
+
import { useLocale } from 'use-intl';
|
|
2
|
+
import createLocalizedLinkComponent from '../shared/next-intl.esm.js';
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
// https://stackoverflow.com/a/15724300/343045
|
|
9
|
-
var value = "; " + document.cookie;
|
|
10
|
-
var parts = value.split("; " + name + "=");
|
|
4
|
+
var LocalizedLink = /*#__PURE__*/createLocalizedLinkComponent(useLocale);
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
var _parts$pop;
|
|
14
|
-
|
|
15
|
-
var part = (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift();
|
|
16
|
-
if (part) return part;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
throw new Error("Unable to find next-intl cookie, have you configured the middleware?");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getCookieLocale() {
|
|
23
|
-
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function useLocalizedRouter() {
|
|
27
|
-
var router = useRouter();
|
|
28
|
-
return useMemo(function () {
|
|
29
|
-
return _extends({}, router, {
|
|
30
|
-
push: function push(href) {
|
|
31
|
-
return router.push(localizeHref(getCookieLocale(), href));
|
|
32
|
-
},
|
|
33
|
-
replace: function replace(href) {
|
|
34
|
-
return router.replace(localizeHref(getCookieLocale(), href));
|
|
35
|
-
},
|
|
36
|
-
prefetch: function prefetch(href) {
|
|
37
|
-
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}, [router]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { useLocalizedRouter as default };
|
|
6
|
+
export { LocalizedLink as default };
|
|
44
7
|
//# sourceMappingURL=next-intl.esm2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/react-client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/react-client/LocalizedLink.tsx"],"sourcesContent":["import {useLocale} from 'use-intl';\nimport createLocalizedLinkComponent from '../shared/createLocalizedLinkComponent';\n\nconst LocalizedLink = createLocalizedLinkComponent(useLocale);\n\nexport default LocalizedLink;\n"],"names":["LocalizedLink","createLocalizedLinkComponent","useLocale"],"mappings":";;;AAGA,IAAMA,aAAa,gBAAGC,4BAA4B,CAACC,SAAD;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/next-intl.esm.js';
|
|
2
2
|
import Link from 'next/link';
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
-
import localizeHref from './next-intl.
|
|
4
|
+
import localizeHref from './next-intl.esm3.js';
|
|
5
5
|
|
|
6
6
|
var _excluded = ["href", "locale"];
|
|
7
7
|
function createLocalizedLinkComponent(useLocale) {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
localizedHref += href;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return localizedHref;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { localizeHref as default };
|
|
5
|
+
export { COOKIE_LOCALE_NAME };
|
|
12
6
|
//# sourceMappingURL=next-intl.esm2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/shared/
|
|
1
|
+
{"version":3,"file":"next-intl.esm2.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,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var COOKIE_LOCALE_NAME = 'NEXT_LOCALE'; // Should take precedence over the cookie
|
|
1
|
+
function localizeHref(locale, href) {
|
|
2
|
+
var localizedHref = '/' + locale;
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
if (href !== '/') {
|
|
5
|
+
localizedHref += href;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return localizedHref;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { localizeHref as default };
|
|
6
12
|
//# sourceMappingURL=next-intl.esm3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm3.js","sources":["../../src/shared/
|
|
1
|
+
{"version":3,"file":"next-intl.esm3.js","sources":["../../src/shared/localizeHref.tsx"],"sourcesContent":["export default function localizeHref(locale: string, href: string) {\n let localizedHref = '/' + locale;\n\n if (href !== '/') {\n localizedHref += href;\n }\n\n return localizedHref;\n}\n"],"names":["localizeHref","locale","href","localizedHref"],"mappings":"AAAc,SAAUA,YAAV,CAAuBC,MAAvB,EAAuCC,IAAvC,EAAmD;AAC/D,EAAIC,IAAAA,aAAa,GAAG,GAAA,GAAMF,MAA1B,CAAA;;AAEA,EAAIC,IAAAA,IAAI,KAAK,GAAb,EAAkB;AAChBC,IAAAA,aAAa,IAAID,IAAjB,CAAA;AACD,GAAA;;AAED,EAAA,OAAOC,aAAP,CAAA;AACD;;;;"}
|
package/dist/src/client/index.js
CHANGED
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
* Client-only APIs.
|
|
3
3
|
*/
|
|
4
4
|
export { default as NextIntlClientProvider } from './NextIntlClientProvider';
|
|
5
|
+
export { default as useLocalizedRouter } from './useLocalizedRouter';
|
|
6
|
+
export { default as useUnlocalizedPathname } from './useUnlocalizedPathname';
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useRouter } from 'next/navigation';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { COOKIE_LOCALE_NAME } from '../shared/constants';
|
|
4
|
+
import localizeHref from '../shared/localizeHref';
|
|
5
|
+
function getCookieValueByName(name) {
|
|
6
|
+
// https://stackoverflow.com/a/15724300/343045
|
|
7
|
+
const value = `; ${document.cookie}`;
|
|
8
|
+
const parts = value.split(`; ${name}=`);
|
|
9
|
+
if (parts.length === 2) {
|
|
10
|
+
const part = parts.pop()?.split(';').shift();
|
|
11
|
+
if (part)
|
|
12
|
+
return part;
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Unable to find next-intl cookie, have you configured the middleware?`);
|
|
15
|
+
}
|
|
16
|
+
function getCookieLocale() {
|
|
17
|
+
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
18
|
+
}
|
|
19
|
+
export default function useLocalizedRouter() {
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
return useMemo(() => ({
|
|
22
|
+
...router,
|
|
23
|
+
push(href) {
|
|
24
|
+
return router.push(localizeHref(getCookieLocale(), href));
|
|
25
|
+
},
|
|
26
|
+
replace(href) {
|
|
27
|
+
return router.replace(localizeHref(getCookieLocale(), href));
|
|
28
|
+
},
|
|
29
|
+
prefetch(href) {
|
|
30
|
+
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
31
|
+
}
|
|
32
|
+
}), [router]);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=useLocalizedRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalizedRouter.js","sourceRoot":"","sources":["../../../src/client/useLocalizedRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AACvD,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAElD,SAAS,oBAAoB,CAAC,IAAY;IACxC,8CAA8C;IAC9C,MAAM,KAAK,GAAG,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;IACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;QACtB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;QAC7C,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;KACvB;IAED,MAAM,IAAI,KAAK,CACb,sEAAsE,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB;IACxC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,MAAM;QACT,IAAI,CAAC,IAAY;YACf,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,CAAC,IAAY;YAClB,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,QAAQ,CAAC,IAAY;YACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;QAChE,CAAC;KACF,CAAC,EACF,CAAC,MAAM,CAAC,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { usePathname } from 'next/navigation';
|
|
2
|
+
export function unlocalizePathname(pathname) {
|
|
3
|
+
return pathname == null
|
|
4
|
+
? pathname
|
|
5
|
+
: pathname.replace(/^\/[\w_-]+/, '') || '/';
|
|
6
|
+
}
|
|
7
|
+
export default function useUnlocalizedPathname() {
|
|
8
|
+
return unlocalizePathname(usePathname());
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=useUnlocalizedPathname.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnlocalizedPathname.js","sourceRoot":"","sources":["../../../src/client/useUnlocalizedPathname.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,MAAM,UAAU,kBAAkB,CAAC,QAAuB;IACxD,OAAO,QAAQ,IAAI,IAAI;QACrB,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,sBAAsB;IAC5C,OAAO,kBAAkB,CAAC,WAAW,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (parts.length === 2) {
|
|
10
|
-
const part = parts.pop()?.split(';').shift();
|
|
11
|
-
if (part)
|
|
12
|
-
return part;
|
|
1
|
+
import useLocalizedRouter from '../client/useLocalizedRouter';
|
|
2
|
+
// TODO: Only available for backwards compatibility
|
|
3
|
+
// during the beta, remove for stable release
|
|
4
|
+
let hasWarned = false;
|
|
5
|
+
export default function useLocalizedRouterDeprecated() {
|
|
6
|
+
if (!hasWarned) {
|
|
7
|
+
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`);
|
|
8
|
+
hasWarned = true;
|
|
13
9
|
}
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function getCookieLocale() {
|
|
17
|
-
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
18
|
-
}
|
|
19
|
-
export default function useLocalizedRouter() {
|
|
20
|
-
const router = useRouter();
|
|
21
|
-
return useMemo(() => ({
|
|
22
|
-
...router,
|
|
23
|
-
push(href) {
|
|
24
|
-
return router.push(localizeHref(getCookieLocale(), href));
|
|
25
|
-
},
|
|
26
|
-
replace(href) {
|
|
27
|
-
return router.replace(localizeHref(getCookieLocale(), href));
|
|
28
|
-
},
|
|
29
|
-
prefetch(href) {
|
|
30
|
-
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
31
|
-
}
|
|
32
|
-
}), [router]);
|
|
10
|
+
return useLocalizedRouter();
|
|
33
11
|
}
|
|
34
12
|
//# sourceMappingURL=useLocalizedRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalizedRouter.js","sourceRoot":"","sources":["../../../src/react-client/useLocalizedRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useLocalizedRouter.js","sourceRoot":"","sources":["../../../src/react-client/useLocalizedRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,8BAA8B,CAAC;AAE9D,mDAAmD;AACnD,6CAA6C;AAE7C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,MAAM,CAAC,OAAO,UAAU,4BAA4B;IAClD,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,CAAC,IAAI,CACV,sSAAsS,CACvS,CAAC;QACF,SAAS,GAAG,IAAI,CAAC;KAClB;IAED,OAAO,kBAAkB,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { use, useMemo } from 'react';
|
|
1
|
+
import { cache, use, useMemo } from 'react';
|
|
2
2
|
import getIntlContextValue from 'use-intl/dist/src/react/getIntlContextValue';
|
|
3
3
|
import staticConfig from '../server/staticConfig';
|
|
4
4
|
import useLocale from './useLocale';
|
|
5
|
+
const receiveMessages = cache((locale, getMessages) => getMessages?.({ locale }));
|
|
5
6
|
function isPromise(value) {
|
|
6
7
|
return value != null && typeof value.then === 'function';
|
|
7
8
|
}
|
|
@@ -10,7 +11,7 @@ export default function useConfig() {
|
|
|
10
11
|
return useMemo(() => {
|
|
11
12
|
function getStaticConfig() {
|
|
12
13
|
const { getMessages, ...rest } = staticConfig;
|
|
13
|
-
const messagesOrPromise =
|
|
14
|
+
const messagesOrPromise = receiveMessages(locale, getMessages);
|
|
14
15
|
// Only promises can be unwrapped
|
|
15
16
|
const messages = isPromise(messagesOrPromise)
|
|
16
17
|
? use(messagesOrPromise)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../../../src/react-server/useConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useConfig.js","sourceRoot":"","sources":["../../../src/react-server/useConfig.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,eAAe,GAAG,KAAK,CAC3B,CAAC,MAAc,EAAE,WAA+C,EAAE,EAAE,CAClE,WAAW,EAAE,CAAC,EAAC,MAAM,EAAC,CAAC,CAC1B,CAAC;AAEF,SAAS,SAAS,CAAC,KAAU;IAC3B,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAC3D,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,SAAS,eAAe;YACtB,MAAM,EAAC,WAAW,EAAE,GAAG,IAAI,EAAC,GAAG,YAAY,CAAC;YAC5C,MAAM,iBAAiB,GAAG,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YAE/D,iCAAiC;YACjC,MAAM,QAAQ,GAAG,SAAS,CAAC,iBAAiB,CAAC;gBAC3C,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC;gBACxB,CAAC,CAAC,iBAAiB,CAAC;YAEtB,OAAO,EAAC,QAAQ,EAAE,GAAG,IAAI,EAAC,CAAC;QAC7B,CAAC;QAED,MAAM,IAAI,GAAG,EAAC,GAAG,eAAe,EAAE,EAAE,MAAM,EAAC,CAAC;QAC5C,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "2.11.0-beta.
|
|
3
|
+
"version": "2.11.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.",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"accept-language-parser": "^1.5.0",
|
|
67
67
|
"server-only": "0.0.1",
|
|
68
|
-
"use-intl": "2.
|
|
68
|
+
"use-intl": "^2.10.2"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
package/src/client/index.tsx
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {useRouter} from 'next/navigation';
|
|
2
|
+
import {useMemo} from 'react';
|
|
3
|
+
import {COOKIE_LOCALE_NAME} from '../shared/constants';
|
|
4
|
+
import localizeHref from '../shared/localizeHref';
|
|
5
|
+
|
|
6
|
+
function getCookieValueByName(name: string) {
|
|
7
|
+
// https://stackoverflow.com/a/15724300/343045
|
|
8
|
+
const value = `; ${document.cookie}`;
|
|
9
|
+
const parts = value.split(`; ${name}=`);
|
|
10
|
+
if (parts.length === 2) {
|
|
11
|
+
const part = parts.pop()?.split(';').shift();
|
|
12
|
+
if (part) return part;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Unable to find next-intl cookie, have you configured the middleware?`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getCookieLocale() {
|
|
21
|
+
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function useLocalizedRouter() {
|
|
25
|
+
const router = useRouter();
|
|
26
|
+
|
|
27
|
+
return useMemo(
|
|
28
|
+
() => ({
|
|
29
|
+
...router,
|
|
30
|
+
push(href: string) {
|
|
31
|
+
return router.push(localizeHref(getCookieLocale(), href));
|
|
32
|
+
},
|
|
33
|
+
replace(href: string) {
|
|
34
|
+
return router.replace(localizeHref(getCookieLocale(), href));
|
|
35
|
+
},
|
|
36
|
+
prefetch(href: string) {
|
|
37
|
+
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
[router]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {usePathname} from 'next/navigation';
|
|
2
|
+
|
|
3
|
+
export function unlocalizePathname(pathname: string | null) {
|
|
4
|
+
return pathname == null
|
|
5
|
+
? pathname
|
|
6
|
+
: pathname.replace(/^\/[\w_-]+/, '') || '/';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function useUnlocalizedPathname() {
|
|
10
|
+
return unlocalizePathname(usePathname());
|
|
11
|
+
}
|
|
@@ -1,42 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {useMemo} from 'react';
|
|
3
|
-
import {COOKIE_LOCALE_NAME} from '../shared/constants';
|
|
4
|
-
import localizeHref from '../shared/localizeHref';
|
|
1
|
+
import useLocalizedRouter from '../client/useLocalizedRouter';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const value = `; ${document.cookie}`;
|
|
9
|
-
const parts = value.split(`; ${name}=`);
|
|
10
|
-
if (parts.length === 2) {
|
|
11
|
-
const part = parts.pop()?.split(';').shift();
|
|
12
|
-
if (part) return part;
|
|
13
|
-
}
|
|
3
|
+
// TODO: Only available for backwards compatibility
|
|
4
|
+
// during the beta, remove for stable release
|
|
14
5
|
|
|
15
|
-
|
|
16
|
-
`Unable to find next-intl cookie, have you configured the middleware?`
|
|
17
|
-
);
|
|
18
|
-
}
|
|
6
|
+
let hasWarned = false;
|
|
19
7
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
export default function useLocalizedRouterDeprecated() {
|
|
9
|
+
if (!hasWarned) {
|
|
10
|
+
console.warn(
|
|
11
|
+
`\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`
|
|
12
|
+
);
|
|
13
|
+
hasWarned = true;
|
|
14
|
+
}
|
|
26
15
|
|
|
27
|
-
return
|
|
28
|
-
() => ({
|
|
29
|
-
...router,
|
|
30
|
-
push(href: string) {
|
|
31
|
-
return router.push(localizeHref(getCookieLocale(), href));
|
|
32
|
-
},
|
|
33
|
-
replace(href: string) {
|
|
34
|
-
return router.replace(localizeHref(getCookieLocale(), href));
|
|
35
|
-
},
|
|
36
|
-
prefetch(href: string) {
|
|
37
|
-
return router.prefetch(localizeHref(getCookieLocale(), href));
|
|
38
|
-
}
|
|
39
|
-
}),
|
|
40
|
-
[router]
|
|
41
|
-
);
|
|
16
|
+
return useLocalizedRouter();
|
|
42
17
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {use, useMemo} from 'react';
|
|
1
|
+
import {cache, use, useMemo} from 'react';
|
|
2
2
|
import getIntlContextValue from 'use-intl/dist/src/react/getIntlContextValue';
|
|
3
3
|
import staticConfig from '../server/staticConfig';
|
|
4
4
|
import useLocale from './useLocale';
|
|
5
5
|
|
|
6
|
+
const receiveMessages = cache(
|
|
7
|
+
(locale: string, getMessages: typeof staticConfig['getMessages']) =>
|
|
8
|
+
getMessages?.({locale})
|
|
9
|
+
);
|
|
10
|
+
|
|
6
11
|
function isPromise(value: any): value is Promise<unknown> {
|
|
7
12
|
return value != null && typeof value.then === 'function';
|
|
8
13
|
}
|
|
@@ -13,7 +18,7 @@ export default function useConfig() {
|
|
|
13
18
|
return useMemo(() => {
|
|
14
19
|
function getStaticConfig() {
|
|
15
20
|
const {getMessages, ...rest} = staticConfig;
|
|
16
|
-
const messagesOrPromise =
|
|
21
|
+
const messagesOrPromise = receiveMessages(locale, getMessages);
|
|
17
22
|
|
|
18
23
|
// Only promises can be unwrapped
|
|
19
24
|
const messages = isPromise(messagesOrPromise)
|
package/withNextIntl.js
CHANGED
|
@@ -6,5 +6,8 @@
|
|
|
6
6
|
const {initPlugin} = require('./plugin');
|
|
7
7
|
|
|
8
8
|
module.exports = function withNextIntl(enhancedNextConfig) {
|
|
9
|
+
console.warn(
|
|
10
|
+
`\n\nDEPRECATION WARNING: The \`withNextIntl()\` function is deprecated and will be removed in the stable release of next-intl. Please use \`next-intl/plugin\` instead. See https://next-intl-docs.vercel.app/docs/next-13/server-components\n\n`
|
|
11
|
+
);
|
|
9
12
|
return initPlugin(enhancedNextConfig.i18nConfig, enhancedNextConfig);
|
|
10
13
|
};
|