next-intlayer 8.1.2 → 8.1.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/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerClientProvider.cjs +1 -36
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -9
- package/dist/cjs/client/index.cjs +1 -16
- package/dist/cjs/client/useLocale.cjs +1 -68
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs +1 -45
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -12
- package/dist/cjs/generateStaticParams.cjs +1 -29
- package/dist/cjs/generateStaticParams.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -132
- package/dist/cjs/proxy/index.cjs +1 -8
- package/dist/cjs/proxy/intlayerProxy.cjs +1 -246
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/proxy/localeDetector.cjs +1 -20
- package/dist/cjs/proxy/localeDetector.cjs.map +1 -1
- package/dist/cjs/proxy/middleware.cjs +1 -37
- package/dist/cjs/proxy/middleware.cjs.map +1 -1
- package/dist/cjs/proxy/multipleProxies.cjs +1 -57
- package/dist/cjs/proxy/multipleProxies.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +1 -9
- package/dist/cjs/server/getLocale.cjs +1 -47
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -75
- package/dist/cjs/server/withIntlayer.cjs +1 -210
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +1 -34
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -1
- package/dist/esm/client/index.mjs +1 -6
- package/dist/esm/client/useLocale.mjs +1 -66
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocalePageRouter.mjs +1 -43
- package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -5
- package/dist/esm/generateStaticParams.mjs +1 -26
- package/dist/esm/generateStaticParams.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -8
- package/dist/esm/proxy/index.mjs +1 -5
- package/dist/esm/proxy/intlayerProxy.mjs +1 -243
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/proxy/localeDetector.mjs +1 -18
- package/dist/esm/proxy/localeDetector.mjs.map +1 -1
- package/dist/esm/proxy/middleware.mjs +1 -35
- package/dist/esm/proxy/middleware.mjs.map +1 -1
- package/dist/esm/proxy/multipleProxies.mjs +1 -55
- package/dist/esm/proxy/multipleProxies.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -1
- package/dist/esm/server/getLocale.mjs +1 -44
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -5
- package/dist/esm/server/withIntlayer.mjs +1 -206
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocalePageRouter.d.ts.map +1 -1
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/dist/types/server/getLocale.d.ts.map +1 -1
- package/dist/types/server/withIntlayer.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
|
|
29
|
-
exports.__toESM = __toESM;
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
|
|
@@ -1,37 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
|
|
8
|
-
//#region src/client/IntlayerClientProvider.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Provider for client-side components in Next.js.
|
|
11
|
-
*
|
|
12
|
-
* This component wraps the `IntlayerProvider` from `react-intlayer` and is intended
|
|
13
|
-
* to be used within Next.js App Router client components.
|
|
14
|
-
*
|
|
15
|
-
* @param props - The provider props.
|
|
16
|
-
* @returns The provider component.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* 'use client';
|
|
21
|
-
*
|
|
22
|
-
* import { IntlayerClientProvider } from 'next-intlayer';
|
|
23
|
-
*
|
|
24
|
-
* export default function ClientLayout({ children, locale }) {
|
|
25
|
-
* return (
|
|
26
|
-
* <IntlayerClientProvider locale={locale}>
|
|
27
|
-
* {children}
|
|
28
|
-
* </IntlayerClientProvider>
|
|
29
|
-
* );
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
const IntlayerClientProvider = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_intlayer.IntlayerProvider, { ...props });
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
exports.IntlayerClientProvider = IntlayerClientProvider;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react-intlayer`),t=require(`react/jsx-runtime`);const n=n=>(0,t.jsx)(e.IntlayerProvider,{...n});exports.IntlayerClientProvider=n;
|
|
37
2
|
//# sourceMappingURL=IntlayerClientProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"4LAgCA,MAAa,EAAqD,IAChE,EAAA,EAAA,KAACA,EAAAA,iBAAAA,CAAiB,GAAI,EAAA,CAAS"}
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react_intlayer_format = require("react-intlayer/format");
|
|
4
|
-
Object.keys(react_intlayer_format).forEach(function (k) {
|
|
5
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function () { return react_intlayer_format[k]; }
|
|
8
|
-
});
|
|
9
|
-
});
|
|
1
|
+
var e=require(`react-intlayer/format`);Object.keys(e).forEach(function(t){t!==`default`&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_client_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
4
|
-
const require_client_useLocale = require('./useLocale.cjs');
|
|
5
|
-
const require_client_useLocalePageRouter = require('./useLocalePageRouter.cjs');
|
|
6
|
-
let react_intlayer = require("react-intlayer");
|
|
7
|
-
|
|
8
|
-
exports.IntlayerClientProvider = require_client_IntlayerClientProvider.IntlayerClientProvider;
|
|
9
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
10
|
-
exports.useLocalePageRouter = require_client_useLocalePageRouter.useLocalePageRouter;
|
|
11
|
-
Object.defineProperty(exports, 'useRewriteURL', {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return react_intlayer.useRewriteURL;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./IntlayerClientProvider.cjs`),t=require(`./useLocale.cjs`),n=require(`./useLocalePageRouter.cjs`);let r=require(`react-intlayer`);exports.IntlayerClientProvider=e.IntlayerClientProvider,exports.useLocale=t.useLocale,exports.useLocalePageRouter=n.useLocalePageRouter,Object.defineProperty(exports,`useRewriteURL`,{enumerable:!0,get:function(){return r.useRewriteURL}});
|
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let next_navigation_js = require("next/navigation.js");
|
|
8
|
-
let react = require("react");
|
|
9
|
-
|
|
10
|
-
//#region src/client/useLocale.ts
|
|
11
|
-
const usePathWithoutLocale = () => {
|
|
12
|
-
const pathname = (0, next_navigation_js.usePathname)();
|
|
13
|
-
const [fullPath, setFullPath] = (0, react.useState)(pathname);
|
|
14
|
-
(0, react.useEffect)(() => {
|
|
15
|
-
const search = typeof window !== "undefined" ? window.location.search : "";
|
|
16
|
-
setFullPath(search ? `${pathname}${search}` : pathname);
|
|
17
|
-
}, [pathname]);
|
|
18
|
-
return (0, react.useMemo)(() => (0, _intlayer_core.getPathWithoutLocale)(fullPath), [fullPath]);
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Hook to manage the current locale in Next.js App Router.
|
|
22
|
-
*
|
|
23
|
-
* This hook extends the base `useLocale` from `react-intlayer` by adding
|
|
24
|
-
* Next.js-specific navigation logic for locale changes.
|
|
25
|
-
*
|
|
26
|
-
* @param props - Optional properties to configure locale change behavior.
|
|
27
|
-
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* 'use client';
|
|
32
|
-
*
|
|
33
|
-
* import { useLocale } from 'next-intlayer';
|
|
34
|
-
*
|
|
35
|
-
* const LocaleSwitcher = () => {
|
|
36
|
-
* const { setLocale } = useLocale({ onChange: 'push' });
|
|
37
|
-
*
|
|
38
|
-
* return (
|
|
39
|
-
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
40
|
-
* );
|
|
41
|
-
* };
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
const useLocale = ({ onChange = "replace" } = {}) => {
|
|
45
|
-
const { replace, push } = (0, next_navigation_js.useRouter)();
|
|
46
|
-
const pathWithoutLocale = usePathWithoutLocale();
|
|
47
|
-
return {
|
|
48
|
-
...(0, react_intlayer.useLocale)({ onLocaleChange: (0, react.useCallback)((locale) => {
|
|
49
|
-
if (!onChange) return;
|
|
50
|
-
if (typeof onChange === "function") {
|
|
51
|
-
onChange(locale);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const pathWithLocale = (0, _intlayer_core.getLocalizedUrl)(pathWithoutLocale, locale);
|
|
55
|
-
if (onChange === "replace") replace(pathWithLocale);
|
|
56
|
-
if (onChange === "push") push(pathWithLocale);
|
|
57
|
-
}, [
|
|
58
|
-
replace,
|
|
59
|
-
push,
|
|
60
|
-
pathWithoutLocale,
|
|
61
|
-
onChange
|
|
62
|
-
]) }),
|
|
63
|
-
pathWithoutLocale
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
exports.useLocale = useLocale;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react-intlayer`),t=require(`@intlayer/core/localization`),n=require(`next/navigation.js`),r=require(`react`);const i=()=>{let e=(0,n.usePathname)(),[i,a]=(0,r.useState)(e);return(0,r.useEffect)(()=>{let t=typeof window<`u`?window.location.search:``;a(t?`${e}${t}`:e)},[e]),(0,r.useMemo)(()=>(0,t.getPathWithoutLocale)(i),[i])},a=({onChange:a=`replace`}={})=>{let{replace:o,push:s}=(0,n.useRouter)(),c=i();return{...(0,e.useLocale)({onLocaleChange:(0,r.useCallback)(e=>{if(!a)return;if(typeof a==`function`){a(e);return}let n=(0,t.getLocalizedUrl)(c,e);a===`replace`&&o(n),a===`push`&&s(n)},[o,s,c,a])}),pathWithoutLocale:c}};exports.useLocale=a;
|
|
69
2
|
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | 'none' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\n/**\n * Hook to manage the current locale in Next.js App Router.\n *\n * This hook extends the base `useLocale` from `react-intlayer` by adding\n * Next.js-specific navigation logic for locale changes.\n *\n * @param props - Optional properties to configure locale change behavior.\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useLocale } from 'next-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { setLocale } = useLocale({ onChange: 'push' });\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocale = ({ onChange = 'replace' }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"yPAeA,MAAM,MAA6B,CACjC,IAAM,GAAA,EAAA,EAAA,cAAwB,CACxB,CAAC,EAAU,IAAA,EAAA,EAAA,UAAwB,EAAS,CASlD,OAPA,EAAA,EAAA,eAAgB,CAEd,IAAM,EAAS,OAAO,OAAW,IAAc,OAAO,SAAS,OAAS,GACxE,EAAY,EAAS,GAAG,IAAW,IAAW,EAAS,EACtD,CAAC,EAAS,CAAC,EAGd,EAAA,EAAA,cAAA,EAAA,EAAA,sBAA0C,EAAS,CAAE,CAAC,EAAS,CAAC,EA2BrD,GAAa,CAAE,WAAW,WAA8B,EAAE,GAAK,CAC1E,GAAM,CAAE,UAAS,SAAA,EAAA,EAAA,YAAoB,CAC/B,EAAoB,GAAsB,CA2BhD,MAAO,CACL,IAAA,EAAA,EAAA,WALqC,CACrC,gBAAA,EAAA,EAAA,aArBC,GAA0B,CACzB,GAAI,CAAC,EAAU,OAEf,GAAI,OAAO,GAAa,WAAY,CAClC,EAAS,EAAO,CAChB,OAGF,IAAM,GAAA,EAAA,EAAA,iBAAiC,EAAmB,EAAO,CAE7D,IAAa,WACf,EAAQ,EAAe,CAErB,IAAa,QACf,EAAK,EAAe,EAGxB,CAAC,EAAS,EAAM,EAAmB,EAAS,CAC7C,CAIA,CAAC,CAIA,oBACD"}
|
|
@@ -1,46 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
let _intlayer_core = require("@intlayer/core");
|
|
7
|
-
let react = require("react");
|
|
8
|
-
let next_router_js = require("next/router.js");
|
|
9
|
-
|
|
10
|
-
//#region src/client/useLocalePageRouter.ts
|
|
11
|
-
/**
|
|
12
|
-
* Hook to manage the current locale in Next.js Page Router.
|
|
13
|
-
*
|
|
14
|
-
* This hook provides locale management functionality tailored for the Next.js Page Router,
|
|
15
|
-
* handling redirections and page reloads upon locale changes.
|
|
16
|
-
*
|
|
17
|
-
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* import { useLocalePageRouter } from 'next-intlayer';
|
|
22
|
-
*
|
|
23
|
-
* const MyComponent = () => {
|
|
24
|
-
* const { setLocale } = useLocalePageRouter();
|
|
25
|
-
*
|
|
26
|
-
* return (
|
|
27
|
-
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
28
|
-
* );
|
|
29
|
-
* };
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const useLocalePageRouter = () => {
|
|
33
|
-
const { push, pathname, reload } = (0, next_router_js.useRouter)();
|
|
34
|
-
const pathWithoutLocale = (0, react.useMemo)(() => (0, _intlayer_core.getPathWithoutLocale)(pathname), [pathname]);
|
|
35
|
-
return {
|
|
36
|
-
...(0, react_intlayer.useLocale)({ onLocaleChange: (0, react.useCallback)((locale) => {
|
|
37
|
-
push((0, _intlayer_core.getLocalizedUrl)(pathWithoutLocale, locale));
|
|
38
|
-
return reload();
|
|
39
|
-
}, [pathWithoutLocale]) }),
|
|
40
|
-
pathWithoutLocale
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
//#endregion
|
|
45
|
-
exports.useLocalePageRouter = useLocalePageRouter;
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react-intlayer`),t=require(`@intlayer/core/localization`),n=require(`react`),r=require(`next/router.js`);const i=()=>{let{push:i,pathname:a,reload:o}=(0,r.useRouter)(),s=(0,n.useMemo)(()=>(0,t.getPathWithoutLocale)(a),[a]);return{...(0,e.useLocale)({onLocaleChange:(0,n.useCallback)(e=>(i((0,t.getLocalizedUrl)(s,e)),o()),[s])}),pathWithoutLocale:s}};exports.useLocalePageRouter=i;
|
|
46
2
|
//# sourceMappingURL=useLocalePageRouter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\n/**\n * Hook to manage the current locale in Next.js Page Router.\n *\n * This hook provides locale management functionality tailored for the Next.js Page Router,\n * handling redirections and page reloads upon locale changes.\n *\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocalePageRouter } from 'next-intlayer';\n *\n * const MyComponent = () => {\n * const { setLocale } = useLocalePageRouter();\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"qPAgCA,MAAa,MAA4B,CACvC,GAAM,CAAE,OAAM,WAAU,WAAA,EAAA,EAAA,YAAsB,CACxC,GAAA,EAAA,EAAA,cAAA,EAAA,EAAA,sBACuB,EAAS,CACpC,CAAC,EAAS,CACX,CAiBD,MAAO,CACL,IAAA,EAAA,EAAA,WALqC,CACrC,gBAAA,EAAA,EAAA,aAXC,IAGC,GAAA,EAAA,EAAA,iBAFuC,EAAmB,EAAO,CAE7C,CAEb,GAAQ,EAEjB,CAAC,EAAkB,CACpB,CAIA,CAAC,CAIA,oBACD"}
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
-
let react_intlayer = require("react-intlayer");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, 'useRewriteURL', {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return react_intlayer.useRewriteURL;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
1
|
+
"use client";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`react-intlayer`);Object.defineProperty(exports,`useRewriteURL`,{enumerable:!0,get:function(){return e.useRewriteURL}});
|
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
-
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
5
|
-
|
|
6
|
-
//#region src/generateStaticParams.ts
|
|
7
|
-
const { locales } = _intlayer_config_built.default.internationalization;
|
|
8
|
-
/**
|
|
9
|
-
* Generates static parameters for Next.js's dynamic routes based on the configured locales.
|
|
10
|
-
*
|
|
11
|
-
* This function is typically used in Next.js App Router for `generateStaticParams`
|
|
12
|
-
* to ensure all supported locales are pre-rendered at build time.
|
|
13
|
-
*
|
|
14
|
-
* @returns An array of objects containing the `locale` parameter for each configured locale.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* // app/[locale]/layout.tsx
|
|
19
|
-
* export { generateStaticParams } from 'next-intlayer';
|
|
20
|
-
*
|
|
21
|
-
* export default async function RootLayout({ children, params }) {
|
|
22
|
-
* // ...
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
exports.generateStaticParams = generateStaticParams;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/config/built`);t=e.__toESM(t);const{locales:n}=t.default.internationalization,r=()=>n.map(e=>({locale:e}));exports.generateStaticParams=r;
|
|
30
2
|
//# sourceMappingURL=generateStaticParams.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.cjs","names":["configuration"],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateStaticParams.cjs","names":["configuration"],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"8KAEA,KAAM,CAAE,WAAYA,EAAAA,QAAc,qBAoBrB,MAA6B,EAAQ,IAAK,IAAY,CAAE,SAAQ,EAAE"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,132 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_generateStaticParams = require('./generateStaticParams.cjs');
|
|
4
|
-
const require_client_IntlayerClientProvider = require('./client/IntlayerClientProvider.cjs');
|
|
5
|
-
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
6
|
-
const require_client_useLocalePageRouter = require('./client/useLocalePageRouter.cjs');
|
|
7
|
-
let react_intlayer = require("react-intlayer");
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, 'IntlayerClientContext', {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return react_intlayer.IntlayerClientContext;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
exports.IntlayerClientProvider = require_client_IntlayerClientProvider.IntlayerClientProvider;
|
|
16
|
-
Object.defineProperty(exports, 'MarkdownProvider', {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return react_intlayer.MarkdownProvider;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(exports, 'MarkdownRenderer', {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () {
|
|
25
|
-
return react_intlayer.MarkdownRenderer;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
exports.generateStaticParams = require_generateStaticParams.generateStaticParams;
|
|
29
|
-
Object.defineProperty(exports, 'getDictionary', {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return react_intlayer.getDictionary;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(exports, 'getIntlayer', {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () {
|
|
38
|
-
return react_intlayer.getIntlayer;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
Object.defineProperty(exports, 'localeCookie', {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
get: function () {
|
|
44
|
-
return react_intlayer.localeCookie;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(exports, 'localeInStorage', {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function () {
|
|
50
|
-
return react_intlayer.localeInStorage;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
Object.defineProperty(exports, 'setLocaleCookie', {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function () {
|
|
56
|
-
return react_intlayer.setLocaleCookie;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(exports, 'setLocaleInStorage', {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () {
|
|
62
|
-
return react_intlayer.setLocaleInStorage;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(exports, 't', {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return react_intlayer.t;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(exports, 'useDictionary', {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () {
|
|
74
|
-
return react_intlayer.useDictionary;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(exports, 'useDictionaryAsync', {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
get: function () {
|
|
80
|
-
return react_intlayer.useDictionaryAsync;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(exports, 'useDictionaryDynamic', {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: function () {
|
|
86
|
-
return react_intlayer.useDictionaryDynamic;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(exports, 'useI18n', {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
get: function () {
|
|
92
|
-
return react_intlayer.useI18n;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(exports, 'useIntl', {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
get: function () {
|
|
98
|
-
return react_intlayer.useIntl;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(exports, 'useIntlayer', {
|
|
102
|
-
enumerable: true,
|
|
103
|
-
get: function () {
|
|
104
|
-
return react_intlayer.useIntlayer;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(exports, 'useLoadDynamic', {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () {
|
|
110
|
-
return react_intlayer.useLoadDynamic;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
114
|
-
Object.defineProperty(exports, 'useLocaleCookie', {
|
|
115
|
-
enumerable: true,
|
|
116
|
-
get: function () {
|
|
117
|
-
return react_intlayer.useLocaleCookie;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
exports.useLocalePageRouter = require_client_useLocalePageRouter.useLocalePageRouter;
|
|
121
|
-
Object.defineProperty(exports, 'useLocaleStorage', {
|
|
122
|
-
enumerable: true,
|
|
123
|
-
get: function () {
|
|
124
|
-
return react_intlayer.useLocaleStorage;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
Object.defineProperty(exports, 'useRewriteURL', {
|
|
128
|
-
enumerable: true,
|
|
129
|
-
get: function () {
|
|
130
|
-
return react_intlayer.useRewriteURL;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./generateStaticParams.cjs`),t=require(`./client/IntlayerClientProvider.cjs`),n=require(`./client/useLocale.cjs`),r=require(`./client/useLocalePageRouter.cjs`);let i=require(`react-intlayer`);Object.defineProperty(exports,`IntlayerClientContext`,{enumerable:!0,get:function(){return i.IntlayerClientContext}}),exports.IntlayerClientProvider=t.IntlayerClientProvider,Object.defineProperty(exports,`MarkdownProvider`,{enumerable:!0,get:function(){return i.MarkdownProvider}}),Object.defineProperty(exports,`MarkdownRenderer`,{enumerable:!0,get:function(){return i.MarkdownRenderer}}),exports.generateStaticParams=e.generateStaticParams,Object.defineProperty(exports,`getDictionary`,{enumerable:!0,get:function(){return i.getDictionary}}),Object.defineProperty(exports,`getIntlayer`,{enumerable:!0,get:function(){return i.getIntlayer}}),Object.defineProperty(exports,`localeCookie`,{enumerable:!0,get:function(){return i.localeCookie}}),Object.defineProperty(exports,`localeInStorage`,{enumerable:!0,get:function(){return i.localeInStorage}}),Object.defineProperty(exports,`setLocaleCookie`,{enumerable:!0,get:function(){return i.setLocaleCookie}}),Object.defineProperty(exports,`setLocaleInStorage`,{enumerable:!0,get:function(){return i.setLocaleInStorage}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i.t}}),Object.defineProperty(exports,`useDictionary`,{enumerable:!0,get:function(){return i.useDictionary}}),Object.defineProperty(exports,`useDictionaryAsync`,{enumerable:!0,get:function(){return i.useDictionaryAsync}}),Object.defineProperty(exports,`useDictionaryDynamic`,{enumerable:!0,get:function(){return i.useDictionaryDynamic}}),Object.defineProperty(exports,`useI18n`,{enumerable:!0,get:function(){return i.useI18n}}),Object.defineProperty(exports,`useIntl`,{enumerable:!0,get:function(){return i.useIntl}}),Object.defineProperty(exports,`useIntlayer`,{enumerable:!0,get:function(){return i.useIntlayer}}),Object.defineProperty(exports,`useLoadDynamic`,{enumerable:!0,get:function(){return i.useLoadDynamic}}),exports.useLocale=n.useLocale,Object.defineProperty(exports,`useLocaleCookie`,{enumerable:!0,get:function(){return i.useLocaleCookie}}),exports.useLocalePageRouter=r.useLocalePageRouter,Object.defineProperty(exports,`useLocaleStorage`,{enumerable:!0,get:function(){return i.useLocaleStorage}}),Object.defineProperty(exports,`useRewriteURL`,{enumerable:!0,get:function(){return i.useRewriteURL}});
|
package/dist/cjs/proxy/index.cjs
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_proxy_localeDetector = require('./localeDetector.cjs');
|
|
3
|
-
const require_proxy_intlayerProxy = require('./intlayerProxy.cjs');
|
|
4
|
-
const require_proxy_multipleProxies = require('./multipleProxies.cjs');
|
|
5
|
-
|
|
6
|
-
exports.intlayerProxy = require_proxy_intlayerProxy.intlayerProxy;
|
|
7
|
-
exports.localeDetector = require_proxy_localeDetector.localeDetector;
|
|
8
|
-
exports.multipleProxies = require_proxy_multipleProxies.multipleProxies;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./localeDetector.cjs`),t=require(`./intlayerProxy.cjs`),n=require(`./multipleProxies.cjs`);exports.intlayerProxy=t.intlayerProxy,exports.localeDetector=e.localeDetector,exports.multipleProxies=n.multipleProxies;
|