next-intl 2.17.2 → 2.17.4-alpha.1
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/NextIntlClientProvider.d.mts +8 -0
- package/dist/client/NextIntlClientProvider.mjs +2 -0
- package/dist/client/NextIntlClientProvider.mjs.map +1 -0
- package/dist/client/index.d.mts +7 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/useClientLocale.d.mts +3 -0
- package/dist/client/useClientLocale.mjs +2 -0
- package/dist/client/useClientLocale.mjs.map +1 -0
- package/dist/client/usePathname.d.mts +16 -0
- package/dist/client/usePathname.mjs +2 -0
- package/dist/client/usePathname.mjs.map +1 -0
- package/dist/client/useRouter.d.mts +28 -0
- package/dist/client/useRouter.d.ts +5 -3
- package/dist/client/useRouter.js +1 -1
- package/dist/client/useRouter.js.map +1 -1
- package/dist/client/useRouter.mjs +2 -0
- package/dist/client/useRouter.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/link/Link.d.mts +30 -0
- package/dist/link/Link.mjs +2 -0
- package/dist/link/Link.mjs.map +1 -0
- package/dist/link/index.d.mts +4 -0
- package/dist/link/index.mjs +2 -0
- package/dist/link/index.mjs.map +1 -0
- package/dist/middleware/NextIntlMiddlewareConfig.d.mts +29 -0
- package/dist/middleware/NextIntlMiddlewareConfig.mjs +1 -0
- package/dist/middleware/NextIntlMiddlewareConfig.mjs.map +1 -0
- package/dist/middleware/getAlternateLinksHeaderValue.d.mts +9 -0
- package/dist/middleware/getAlternateLinksHeaderValue.mjs +2 -0
- package/dist/middleware/getAlternateLinksHeaderValue.mjs.map +1 -0
- package/dist/middleware/index.d.mts +3 -0
- package/dist/middleware/index.mjs +2 -0
- package/dist/middleware/index.mjs.map +1 -0
- package/dist/middleware/middleware.d.mts +6 -0
- package/dist/middleware/middleware.mjs +2 -0
- package/dist/middleware/middleware.mjs.map +1 -0
- package/dist/middleware/resolveLocale.d.mts +9 -0
- package/dist/middleware/resolveLocale.mjs +2 -0
- package/dist/middleware/resolveLocale.mjs.map +1 -0
- package/dist/middleware/utils.d.mts +8 -0
- package/dist/middleware/utils.mjs +2 -0
- package/dist/middleware/utils.mjs.map +1 -0
- package/dist/react-client/index.d.mts +3 -0
- package/dist/react-client/index.mjs +2 -0
- package/dist/react-client/index.mjs.map +1 -0
- package/dist/react-server/index.d.mts +23 -0
- package/dist/react-server/index.mjs +7 -0
- package/dist/react-server/index.mjs.map +1 -0
- package/dist/server/index.d.mts +7 -0
- package/dist/server/index.mjs +14 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/shared/BaseLink.d.mts +9 -0
- package/dist/shared/BaseLink.mjs +2 -0
- package/dist/shared/BaseLink.mjs.map +1 -0
- package/dist/shared/NextIntlClientProvider.d.mts +11 -0
- package/dist/shared/NextIntlClientProvider.mjs +2 -0
- package/dist/shared/NextIntlClientProvider.mjs.map +1 -0
- package/dist/shared/constants.d.mts +4 -0
- package/dist/shared/constants.mjs +2 -0
- package/dist/shared/constants.mjs.map +1 -0
- package/dist/shared/utils.d.mts +16 -0
- package/dist/shared/utils.mjs +2 -0
- package/dist/shared/utils.mjs.map +1 -0
- package/link.d.ts +1 -3
- package/middleware.d.ts +1 -3
- package/package.json +21 -13
- package/src/client/useRouter.tsx +6 -6
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import NextIntlClientProvider$1 from '../shared/NextIntlClientProvider.mjs';
|
|
3
|
+
import 'use-intl';
|
|
4
|
+
|
|
5
|
+
/** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */
|
|
6
|
+
declare function NextIntlClientProvider(props: ComponentProps<typeof NextIntlClientProvider$1>): JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { NextIntlClientProvider as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import r from"react";import n from"../shared/NextIntlClientProvider";let t=!1;function o(e){return t||(t=!0,console.warn("\nImporting `NextIntlClientProvider` from `next-intl/client` is deprecated. Please update the import:\n\n import {NextIntlClientProvider} from 'next-intl';\n")),r.createElement(n,{...e})}export{o as default};
|
|
2
|
+
//# sourceMappingURL=NextIntlClientProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/NextIntlClientProvider.tsx"],"sourcesContent":["import React, {ComponentProps} from 'react';\nimport NextIntlClientProvider_ from '../shared/NextIntlClientProvider';\n\nlet hasWarned = false;\n/** @deprecated Should be imported from `next-intl`, not `next-intl/client`. */\nexport default function NextIntlClientProvider(\n props: ComponentProps<typeof NextIntlClientProvider_>\n) {\n if (!hasWarned) {\n hasWarned = true;\n console.warn(`\nImporting \\`NextIntlClientProvider\\` from \\`next-intl/client\\` is deprecated. Please update the import:\n\n import {NextIntlClientProvider} from 'next-intl';\n`);\n }\n return <NextIntlClientProvider_ {...props} />;\n}\n"],"mappings":"AAAA,OAAOA,MAA6B,QACpC,OAAOC,MAA6B,mCAEpC,IAAIC,EAAY,GAED,SAARC,EACLC,EACA,CACA,OAAKF,IACHA,EAAY,GACZ,QAAQ,KAAK,gKAIhB,GAEQF,EAAA,cAACC,EAAA,CAAyB,GAAGG,EAAO,CAC7C","names":["React","NextIntlClientProvider_","hasWarned","NextIntlClientProvider","props"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as useRouter } from './useRouter.mjs';
|
|
2
|
+
export { default as usePathname } from './usePathname.mjs';
|
|
3
|
+
export { default as NextIntlClientProvider } from './NextIntlClientProvider.mjs';
|
|
4
|
+
import 'next/dist/shared/lib/app-router-context';
|
|
5
|
+
import 'react';
|
|
6
|
+
import '../shared/NextIntlClientProvider.mjs';
|
|
7
|
+
import 'use-intl';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as useRouter } from './useRouter.js';
|
|
2
2
|
export { default as usePathname } from './usePathname.js';
|
|
3
3
|
export { default as NextIntlClientProvider } from './NextIntlClientProvider.js';
|
|
4
|
+
import 'next/dist/shared/lib/app-router-context';
|
|
4
5
|
import 'react';
|
|
5
6
|
import '../shared/NextIntlClientProvider.js';
|
|
6
7
|
import 'use-intl';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/index.tsx"],"sourcesContent":["/**\n * Client-only APIs available via `next-intl/client`.\n */\n\nexport {default as useRouter} from './useRouter';\nexport {default as usePathname} from './usePathname';\n\n// Legacy export (deprecation is handled by component)\nexport {default as NextIntlClientProvider} from './NextIntlClientProvider';\n"],"mappings":"AAIA,OAAmB,WAAXA,MAA2B,cACnC,OAAmB,WAAXA,MAA6B,gBAGrC,OAAmB,WAAXA,MAAwC","names":["default"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/useClientLocale.tsx"],"sourcesContent":["import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n // The types aren't entirely correct here. Outside of Next.js\n // `useParams` can be called, but the return type is `null`.\n const params = useParams() as ReturnType<typeof useParams> | null;\n\n if (params?.[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n"],"mappings":"AAAA,OAAQ,aAAAA,MAAgB,kBACxB,OAAQ,aAAAC,MAAgB,WACxB,OAAQ,uBAAAC,MAA0B,sBAEnB,SAARC,GAA2C,CAChD,IAAIC,EAIJ,MAAMC,EAASL,EAAU,EAEzB,OAAIK,GAAA,MAAAA,EAASH,GACXE,EAASC,EAAOH,CAAmB,EAGnCE,EAASH,EAAU,EAGdG,CACT","names":["useParams","useLocale","LOCALE_SEGMENT_NAME","useClientLocale","locale","params"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the pathname without a potential locale prefix.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* 'use client';
|
|
7
|
+
*
|
|
8
|
+
* import {usePathname} from 'next-intl/client';
|
|
9
|
+
*
|
|
10
|
+
* // When the user is on `/en`, this will be `/`
|
|
11
|
+
* const pathname = usePathname();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function usePathname(): string;
|
|
15
|
+
|
|
16
|
+
export { usePathname as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{usePathname as a}from"next/navigation";import{useMemo as n}from"react";import{hasPathnamePrefixed as o,unlocalizePathname as m}from"../shared/utils";import r from"./useClientLocale";function s(){const e=a(),t=r();return n(()=>e&&(o(t,e)?m(e,t):e),[t,e])}export{s as default};
|
|
2
|
+
//# sourceMappingURL=usePathname.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/usePathname.tsx"],"sourcesContent":["'use client';\n\nimport {usePathname as useNextPathname} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {hasPathnamePrefixed, unlocalizePathname} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns the pathname without a potential locale prefix.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {usePathname} from 'next-intl/client';\n *\n * // When the user is on `/en`, this will be `/`\n * const pathname = usePathname();\n * ```\n */\nexport default function usePathname(): string {\n // The types aren't entirely correct here. Outside of Next.js\n // `useParams` can be called, but the return type is `null`.\n const pathname = useNextPathname() as ReturnType<\n typeof useNextPathname\n > | null;\n\n const locale = useClientLocale();\n\n return useMemo(() => {\n if (!pathname) return pathname as ReturnType<typeof useNextPathname>;\n\n const isPathnamePrefixed = hasPathnamePrefixed(locale, pathname);\n const unlocalizedPathname = isPathnamePrefixed\n ? unlocalizePathname(pathname, locale)\n : pathname;\n\n return unlocalizedPathname;\n }, [locale, pathname]);\n}\n"],"mappings":"aAEA,OAAQ,eAAeA,MAAsB,kBAC7C,OAAQ,WAAAC,MAAc,QACtB,OAAQ,uBAAAC,EAAqB,sBAAAC,MAAyB,kBACtD,OAAOC,MAAqB,oBAeb,SAARC,GAAuC,CAG5C,MAAMC,EAAWN,EAAgB,EAI3BO,EAASH,EAAgB,EAE/B,OAAOH,EAAQ,IACRK,IAEsBJ,EAAoBK,EAAQD,CAAQ,EAE3DH,EAAmBG,EAAUC,CAAM,EACnCD,GAGH,CAACC,EAAQD,CAAQ,CAAC,CACvB","names":["useNextPathname","useMemo","hasPathnamePrefixed","unlocalizePathname","useClientLocale","usePathname","pathname","locale"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as next_dist_shared_lib_app_router_context from 'next/dist/shared/lib/app-router-context';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
5
|
+
* will automatically localize the `href` parameters it receives.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* 'use client';
|
|
10
|
+
*
|
|
11
|
+
* import {useRouter} from 'next-intl/client';
|
|
12
|
+
*
|
|
13
|
+
* const router = useRouter();
|
|
14
|
+
*
|
|
15
|
+
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
16
|
+
* router.push('/about');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function useRouter(): {
|
|
20
|
+
push(href: string, options?: next_dist_shared_lib_app_router_context.NavigateOptions | undefined): void;
|
|
21
|
+
replace(href: string, options?: next_dist_shared_lib_app_router_context.NavigateOptions | undefined): void;
|
|
22
|
+
prefetch(href: string, options?: next_dist_shared_lib_app_router_context.PrefetchOptions | undefined): void;
|
|
23
|
+
back(): void;
|
|
24
|
+
forward(): void;
|
|
25
|
+
refresh(): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useRouter as default };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as next_dist_shared_lib_app_router_context from 'next/dist/shared/lib/app-router-context';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
3
5
|
* will automatically localize the `href` parameters it receives.
|
|
@@ -15,9 +17,9 @@
|
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
19
|
declare function useRouter(): {
|
|
18
|
-
push(href: string): void;
|
|
19
|
-
replace(href: string): void;
|
|
20
|
-
prefetch(href: string): void;
|
|
20
|
+
push(href: string, options?: next_dist_shared_lib_app_router_context.NavigateOptions | undefined): void;
|
|
21
|
+
replace(href: string, options?: next_dist_shared_lib_app_router_context.NavigateOptions | undefined): void;
|
|
22
|
+
prefetch(href: string, options?: next_dist_shared_lib_app_router_context.PrefetchOptions | undefined): void;
|
|
21
23
|
back(): void;
|
|
22
24
|
forward(): void;
|
|
23
25
|
refresh(): void;
|
package/dist/client/useRouter.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.create;var a=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},p=(e,r,t,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of h(r))!P.call(e,o)&&o!==t&&a(e,o,{get:()=>r[o],enumerable:!(u=i(r,o))||u.enumerable});return e};var d=(e,r,t)=>(t=e!=null?m(y(e)):{},p(r||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),w=e=>p(a({},"__esModule",{value:!0}),e);var x={};R(x,{default:()=>l});module.exports=w(x);var n=require("next/navigation"),c=require("react"),s=require("../shared/utils"),f=d(require("./useClientLocale"));function l(){const e=(0,n.useRouter)(),r=(0,f.default)();return(0,c.useMemo)(()=>{function t(u){return(0,s.localizeHref)(u,r,r,window.location.pathname)}return{...e,push(...[u,...o]){return e.push(t(u),...o)},replace(...[u,...o]){return e.replace(t(u),...o)},prefetch(...[u,...o]){return e.prefetch(t(u),...o)}}},[r,e])}
|
|
2
2
|
//# sourceMappingURL=useRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(href:
|
|
1
|
+
{"version":3,"sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(...[href, ...args]: Parameters<typeof router.push>) {\n return router.push(localize(href), ...args);\n },\n replace(...[href, ...args]: Parameters<typeof router.replace>) {\n return router.replace(localize(href), ...args);\n },\n prefetch(...[href, ...args]: Parameters<typeof router.prefetch>) {\n return router.prefetch(localize(href), ...args);\n }\n };\n }, [locale, router]);\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2BACzCC,EAAsB,iBACtBC,EAA2B,2BAC3BC,EAA4B,gCAkBb,SAARL,GAA6B,CAClC,MAAMM,KAAS,EAAAC,WAAc,EACvBC,KAAS,EAAAC,SAAgB,EAE/B,SAAO,WAAQ,IAAM,CACnB,SAASC,EAASC,EAAc,CAC9B,SAAO,gBAAaA,EAAMH,EAAQA,EAAQ,OAAO,SAAS,QAAQ,CACpE,CAEA,MAAO,CACL,GAAGF,EACH,QAAQ,CAACK,EAAM,GAAGC,CAAI,EAAmC,CACvD,OAAON,EAAO,KAAKI,EAASC,CAAI,EAAG,GAAGC,CAAI,CAC5C,EACA,WAAW,CAACD,EAAM,GAAGC,CAAI,EAAsC,CAC7D,OAAON,EAAO,QAAQI,EAASC,CAAI,EAAG,GAAGC,CAAI,CAC/C,EACA,YAAY,CAACD,EAAM,GAAGC,CAAI,EAAuC,CAC/D,OAAON,EAAO,SAASI,EAASC,CAAI,EAAG,GAAGC,CAAI,CAChD,CACF,CACF,EAAG,CAACJ,EAAQF,CAAM,CAAC,CACrB","names":["useRouter_exports","__export","useRouter","__toCommonJS","import_navigation","import_react","import_utils","import_useClientLocale","router","useNextRouter","locale","useClientLocale","localize","href","args"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useRouter as a}from"next/navigation";import{useMemo as p}from"react";import{localizeHref as n}from"../shared/utils";import c from"./useClientLocale";function s(){const r=a(),o=c();return p(()=>{function u(e){return n(e,o,o,window.location.pathname)}return{...r,push(...[e,...t]){return r.push(u(e),...t)},replace(...[e,...t]){return r.replace(u(e),...t)},prefetch(...[e,...t]){return r.prefetch(u(e),...t)}}},[o,r])}export{s as default};
|
|
2
|
+
//# sourceMappingURL=useRouter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport {localizeHref} from '../shared/utils';\nimport useClientLocale from './useClientLocale';\n\n/**\n * Returns a wrapped instance of `useRouter` from `next/navigation` that\n * will automatically localize the `href` parameters it receives.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import {useRouter} from 'next-intl/client';\n *\n * const router = useRouter();\n *\n * // When the user is on `/en`, the router will navigate to `/en/about`\n * router.push('/about');\n * ```\n */\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(() => {\n function localize(href: string) {\n return localizeHref(href, locale, locale, window.location.pathname);\n }\n\n return {\n ...router,\n push(...[href, ...args]: Parameters<typeof router.push>) {\n return router.push(localize(href), ...args);\n },\n replace(...[href, ...args]: Parameters<typeof router.replace>) {\n return router.replace(localize(href), ...args);\n },\n prefetch(...[href, ...args]: Parameters<typeof router.prefetch>) {\n return router.prefetch(localize(href), ...args);\n }\n };\n }, [locale, router]);\n}\n"],"mappings":"AAAA,OAAQ,aAAaA,MAAoB,kBACzC,OAAQ,WAAAC,MAAc,QACtB,OAAQ,gBAAAC,MAAmB,kBAC3B,OAAOC,MAAqB,oBAkBb,SAARC,GAA6B,CAClC,MAAMC,EAASL,EAAc,EACvBM,EAASH,EAAgB,EAE/B,OAAOF,EAAQ,IAAM,CACnB,SAASM,EAASC,EAAc,CAC9B,OAAON,EAAaM,EAAMF,EAAQA,EAAQ,OAAO,SAAS,QAAQ,CACpE,CAEA,MAAO,CACL,GAAGD,EACH,QAAQ,CAACG,EAAM,GAAGC,CAAI,EAAmC,CACvD,OAAOJ,EAAO,KAAKE,EAASC,CAAI,EAAG,GAAGC,CAAI,CAC5C,EACA,WAAW,CAACD,EAAM,GAAGC,CAAI,EAAsC,CAC7D,OAAOJ,EAAO,QAAQE,EAASC,CAAI,EAAG,GAAGC,CAAI,CAC/C,EACA,YAAY,CAACD,EAAM,GAAGC,CAAI,EAAuC,CAC/D,OAAOJ,EAAO,SAASE,EAASC,CAAI,EAAG,GAAGC,CAAI,CAChD,CACF,CACF,EAAG,CAACH,EAAQD,CAAM,CAAC,CACrB","names":["useNextRouter","useMemo","localizeHref","useClientLocale","useRouter","router","locale","localize","href","args"]}
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"sourcesContent":["/**\n * This is the default entry file when consumers import from\n * 'next-intl'. We use the client APIs in this case.\n *\n * Note that the `react-server` environment (i.e. RSC) imports\n * from `./react-server` instead.\n */\n\nexport * from './react-client';\n"],"mappings":"AAQA,WAAc","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import _default$1 from '../shared/BaseLink.mjs';
|
|
3
|
+
import 'next/link';
|
|
4
|
+
|
|
5
|
+
type Props = Omit<ComponentProps<typeof _default$1>, 'locale'> & {
|
|
6
|
+
locale?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Wraps `next/link` and prefixes the `href` with the current locale if
|
|
10
|
+
* necessary.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import {Link} from 'next-intl';
|
|
15
|
+
*
|
|
16
|
+
* // When the user is on `/en`, the link will point to `/en/about`
|
|
17
|
+
* <Link href="/about">About</Link>
|
|
18
|
+
*
|
|
19
|
+
* // You can override the `locale` to switch to another language
|
|
20
|
+
* <Link href="/" locale="de">Switch to German</Link>
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Note that when a `locale` prop is passed to switch the locale, the `prefetch`
|
|
24
|
+
* prop is not supported. This is because Next.js would prefetch the page and
|
|
25
|
+
* the `set-cookie` response header would cause the locale cookie on the current
|
|
26
|
+
* page to be overwritten before the user even decides to change the locale.
|
|
27
|
+
*/
|
|
28
|
+
declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
29
|
+
|
|
30
|
+
export { _default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/link/Link.tsx"],"sourcesContent":["import React, {ComponentProps, forwardRef} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport BaseLink from '../shared/BaseLink';\n\ntype Props = Omit<ComponentProps<typeof BaseLink>, 'locale'> & {\n locale?: string;\n};\n\nfunction Link({locale, ...rest}: Props, ref: Props['ref']) {\n const defaultLocale = useClientLocale();\n return <BaseLink ref={ref} locale={locale || defaultLocale} {...rest} />;\n}\n\n/**\n * Wraps `next/link` and prefixes the `href` with the current locale if\n * necessary.\n *\n * @example\n * ```tsx\n * import {Link} from 'next-intl';\n *\n * // When the user is on `/en`, the link will point to `/en/about`\n * <Link href=\"/about\">About</Link>\n *\n * // You can override the `locale` to switch to another language\n * <Link href=\"/\" locale=\"de\">Switch to German</Link>\n * ```\n *\n * Note that when a `locale` prop is passed to switch the locale, the `prefetch`\n * prop is not supported. This is because Next.js would prefetch the page and\n * the `set-cookie` response header would cause the locale cookie on the current\n * page to be overwritten before the user even decides to change the locale.\n */\nexport default forwardRef(Link);\n"],"mappings":"AAAA,OAAOA,GAAwB,cAAAC,MAAiB,QAChD,OAAOC,MAAqB,4BAC5B,OAAOC,MAAc,qBAMrB,SAASC,EAAK,CAAC,OAAAC,EAAQ,GAAGC,CAAI,EAAUC,EAAmB,CACzD,MAAMC,EAAgBN,EAAgB,EACtC,OAAOF,EAAA,cAACG,EAAA,CAAS,IAAKI,EAAK,OAAQF,GAAUG,EAAgB,GAAGF,EAAM,CACxE,CAsBA,IAAOG,EAAQR,EAAWG,CAAI","names":["React","forwardRef","useClientLocale","BaseLink","Link","locale","rest","ref","defaultLocale","Link_default"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/link/index.tsx"],"sourcesContent":["export {default} from './Link';\n"],"mappings":"AAAA,OAAQ,WAAAA,MAAc","names":["default"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type LocalePrefix = 'as-needed' | 'always';
|
|
2
|
+
type RoutingBaseConfig = {
|
|
3
|
+
/** A list of all locales that are supported. */
|
|
4
|
+
locales: Array<string>;
|
|
5
|
+
defaultLocale: string;
|
|
6
|
+
/** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
|
|
7
|
+
*/
|
|
8
|
+
localePrefix?: LocalePrefix;
|
|
9
|
+
};
|
|
10
|
+
type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> & {
|
|
11
|
+
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
12
|
+
domain: string;
|
|
13
|
+
locales?: RoutingBaseConfig['locales'];
|
|
14
|
+
};
|
|
15
|
+
type MiddlewareConfig = RoutingBaseConfig & {
|
|
16
|
+
/** Can be used to change the locale handling per domain. */
|
|
17
|
+
domains?: Array<DomainConfig>;
|
|
18
|
+
/** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
|
|
19
|
+
localeDetection?: boolean;
|
|
20
|
+
/** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
|
|
21
|
+
alternateLinks?: boolean;
|
|
22
|
+
};
|
|
23
|
+
type MiddlewareConfigWithDefaults = MiddlewareConfig & {
|
|
24
|
+
alternateLinks: boolean;
|
|
25
|
+
localePrefix: LocalePrefix;
|
|
26
|
+
localeDetection: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { DomainConfig, MiddlewareConfigWithDefaults, MiddlewareConfig as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=NextIntlMiddlewareConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* See https://developers.google.com/search/docs/specialty/international/localized-versions
|
|
6
|
+
*/
|
|
7
|
+
declare function getAlternateLinksHeaderValue(config: MiddlewareConfigWithDefaults, request: NextRequest): string;
|
|
8
|
+
|
|
9
|
+
export { getAlternateLinksHeaderValue as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isLocaleSupportedOnDomain as m}from"./utils";function p(e,i){const t=new URL(i.url);return t.pathname.endsWith("/")||(t.pathname+="/"),t.pathname=t.pathname.replace(new RegExp(`^/(${e.locales.join("|")})/`),"/"),t.pathname!=="/"&&(t.pathname=t.pathname.slice(0,-1)),t.toString()}function s(e,i){return`<${e}>; rel="alternate"; hreflang="${i}"`}function u(e,i){const t=p(e,i),l=e.locales.flatMap(n=>{function f(r){return r.pathname==="/"?r.pathname=`/${n}`:r.pathname=`/${n}${r.pathname}`,r}let a;return e.domains?(e.domains.filter(o=>m(n,o))||[]).map(o=>(a=new URL(t),a.port="",a.host=o.domain,(n!==o.defaultLocale||e.localePrefix==="always")&&f(a),s(a.toString(),n))):(a=new URL(t),(n!==e.defaultLocale||e.localePrefix==="always")&&f(a),s(a.toString(),n))});if(!e.domains){const n=new URL(t);l.push(s(n.toString(),"x-default"))}return l.join(", ")}export{u as default};
|
|
2
|
+
//# sourceMappingURL=getAlternateLinksHeaderValue.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/getAlternateLinksHeaderValue.tsx"],"sourcesContent":["import {NextRequest} from 'next/server';\nimport MiddlewareConfig, {\n MiddlewareConfigWithDefaults\n} from './NextIntlMiddlewareConfig';\nimport {isLocaleSupportedOnDomain} from './utils';\n\nfunction getUnprefixedUrl(config: MiddlewareConfig, request: NextRequest) {\n const url = new URL(request.url);\n if (!url.pathname.endsWith('/')) {\n url.pathname += '/';\n }\n\n url.pathname = url.pathname.replace(\n new RegExp(`^/(${config.locales.join('|')})/`),\n '/'\n );\n\n // Remove trailing slash\n if (url.pathname !== '/') {\n url.pathname = url.pathname.slice(0, -1);\n }\n\n return url.toString();\n}\n\nfunction getAlternateEntry(url: string, locale: string) {\n return `<${url}>; rel=\"alternate\"; hreflang=\"${locale}\"`;\n}\n\n/**\n * See https://developers.google.com/search/docs/specialty/international/localized-versions\n */\nexport default function getAlternateLinksHeaderValue(\n config: MiddlewareConfigWithDefaults,\n request: NextRequest\n) {\n const unprefixedUrl = getUnprefixedUrl(config, request);\n\n const links = config.locales.flatMap((locale) => {\n function localizePathname(url: URL) {\n if (url.pathname === '/') {\n url.pathname = `/${locale}`;\n } else {\n url.pathname = `/${locale}${url.pathname}`;\n }\n return url;\n }\n\n let url;\n\n if (config.domains) {\n const domainConfigs =\n config.domains.filter((cur) =>\n isLocaleSupportedOnDomain(locale, cur)\n ) || [];\n\n return domainConfigs.map((domainConfig) => {\n url = new URL(unprefixedUrl);\n url.port = '';\n url.host = domainConfig.domain;\n\n if (\n locale !== domainConfig.defaultLocale ||\n config.localePrefix === 'always'\n ) {\n localizePathname(url);\n }\n\n return getAlternateEntry(url.toString(), locale);\n });\n } else {\n url = new URL(unprefixedUrl);\n if (locale !== config.defaultLocale || config.localePrefix === 'always') {\n localizePathname(url);\n }\n }\n\n return getAlternateEntry(url.toString(), locale);\n });\n\n // Add x-default entry\n if (!config.domains) {\n const url = new URL(unprefixedUrl);\n links.push(getAlternateEntry(url.toString(), 'x-default'));\n } else {\n // For `type: domain` there is no reasonable x-default\n }\n\n return links.join(', ');\n}\n"],"mappings":"AAIA,OAAQ,6BAAAA,MAAgC,UAExC,SAASC,EAAiBC,EAA0BC,EAAsB,CACxE,MAAMC,EAAM,IAAI,IAAID,EAAQ,GAAG,EAC/B,OAAKC,EAAI,SAAS,SAAS,GAAG,IAC5BA,EAAI,UAAY,KAGlBA,EAAI,SAAWA,EAAI,SAAS,QAC1B,IAAI,OAAO,MAAMF,EAAO,QAAQ,KAAK,GAAG,CAAC,IAAI,EAC7C,GACF,EAGIE,EAAI,WAAa,MACnBA,EAAI,SAAWA,EAAI,SAAS,MAAM,EAAG,EAAE,GAGlCA,EAAI,SAAS,CACtB,CAEA,SAASC,EAAkBD,EAAaE,EAAgB,CACtD,MAAO,IAAIF,CAAG,iCAAiCE,CAAM,GACvD,CAKe,SAARC,EACLL,EACAC,EACA,CACA,MAAMK,EAAgBP,EAAiBC,EAAQC,CAAO,EAEhDM,EAAQP,EAAO,QAAQ,QAASI,GAAW,CAC/C,SAASI,EAAiBN,EAAU,CAClC,OAAIA,EAAI,WAAa,IACnBA,EAAI,SAAW,IAAIE,CAAM,GAEzBF,EAAI,SAAW,IAAIE,CAAM,GAAGF,EAAI,QAAQ,GAEnCA,CACT,CAEA,IAAIA,EAEJ,OAAIF,EAAO,SAEPA,EAAO,QAAQ,OAAQS,GACrBX,EAA0BM,EAAQK,CAAG,CACvC,GAAK,CAAC,GAEa,IAAKC,IACxBR,EAAM,IAAI,IAAII,CAAa,EAC3BJ,EAAI,KAAO,GACXA,EAAI,KAAOQ,EAAa,QAGtBN,IAAWM,EAAa,eACxBV,EAAO,eAAiB,WAExBQ,EAAiBN,CAAG,EAGfC,EAAkBD,EAAI,SAAS,EAAGE,CAAM,EAChD,GAEDF,EAAM,IAAI,IAAII,CAAa,GACvBF,IAAWJ,EAAO,eAAiBA,EAAO,eAAiB,WAC7DQ,EAAiBN,CAAG,EAIjBC,EAAkBD,EAAI,SAAS,EAAGE,CAAM,EACjD,CAAC,EAGD,GAAI,CAACJ,EAAO,QAAS,CACnB,MAAME,EAAM,IAAI,IAAII,CAAa,EACjCC,EAAM,KAAKJ,EAAkBD,EAAI,SAAS,EAAG,WAAW,CAAC,CAC3D,CAIA,OAAOK,EAAM,KAAK,IAAI,CACxB","names":["isLocaleSupportedOnDomain","getUnprefixedUrl","config","request","url","getAlternateEntry","locale","getAlternateLinksHeaderValue","unprefixedUrl","links","localizePathname","cur","domainConfig"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/index.tsx"],"sourcesContent":["/**\n * The middleware, available as `next-intl/middleware`.\n */\n\nexport {default} from './middleware';\n"],"mappings":"AAIA,OAAQ,WAAAA,MAAc","names":["default"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import MiddlewareConfig from './NextIntlMiddlewareConfig.mjs';
|
|
3
|
+
|
|
4
|
+
declare function createMiddleware(config: MiddlewareConfig): (request: NextRequest) => NextResponse<unknown>;
|
|
5
|
+
|
|
6
|
+
export { createMiddleware as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{NextResponse as m}from"next/server";import{COOKIE_LOCALE_NAME as M}from"../shared/constants";import D from"./getAlternateLinksHeaderValue";import S from"./resolveLocale";import{getBestMatchingDomain as P,getLocaleFromPathname as W,isLocaleSupportedOnDomain as A}from"./utils";const I="/";function N(s){var f,u,e;return{...s,alternateLinks:(f=s.alternateLinks)!=null?f:!0,localePrefix:(u=s.localePrefix)!=null?u:"as-needed",localeDetection:(e=s.localeDetection)!=null?e:!0}}function _(s){const t=N(s),f=s._matcher;return function(e){var C,k;if(!(!f||f.some(n=>e.nextUrl.pathname.match(n))))return m.next();const{domain:l,locale:a}=S(t,e.headers,e.cookies,e.nextUrl.pathname),R=e.nextUrl.pathname===I,$=((C=e.cookies.get(M))==null?void 0:C.value)!==a,p=l?l.defaultLocale===a:a===t.defaultLocale,x=((k=t.domains)==null?void 0:k.filter(n=>A(a,n)))||[],O=t.domains!=null&&!l;function g(){return{request:{headers:e.headers}}}function U(n){return m.rewrite(new URL(n,e.url),g())}function w(){return m.next(g())}function h(n,o){const c=new URL(n,e.url);if(x.length>0&&!o){const r=P(l,a,x);r&&(o=r.domain,r.defaultLocale===a&&t.localePrefix==="as-needed"&&(c.pathname=c.pathname.replace(`/${a}`,"")))}return o&&(c.host=o),m.redirect(c.toString())}let i;if(R){let n=`/${a}`;e.nextUrl.search&&(n+=e.nextUrl.search),p&&t.localePrefix==="as-needed"?i=U(n):i=h(n)}else{const n=W(e.nextUrl.pathname),o=t.locales.includes(n)?n:void 0,c=o!=null;let r=e.nextUrl.pathname;if(e.nextUrl.search&&(r+=e.nextUrl.search),c){const L=r.replace(`/${o}`,"")||"/";if(o===a)if(p&&t.localePrefix==="as-needed")i=h(L);else if(t.domains){const d=P(l,o,x);(l==null?void 0:l.domain)!==(d==null?void 0:d.domain)&&!O?i=h(L,d==null?void 0:d.domain):i=w()}else i=w();else i=h(`/${a}${L}`)}else p&&(t.localePrefix==="as-needed"||t.domains)?i=U(`/${a}${r}`):i=h(`/${a}${r}`)}return $&&i.cookies.set(M,a,{sameSite:"strict"}),t.alternateLinks&&t.locales.length>1&&i.headers.set("Link",D(t,e)),i}}export{_ as default};
|
|
2
|
+
//# sourceMappingURL=middleware.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/middleware.tsx"],"sourcesContent":["import {NextRequest, NextResponse} from 'next/server';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport MiddlewareConfig, {\n MiddlewareConfigWithDefaults\n} from './NextIntlMiddlewareConfig';\nimport getAlternateLinksHeaderValue from './getAlternateLinksHeaderValue';\nimport resolveLocale from './resolveLocale';\nimport {\n getBestMatchingDomain,\n getLocaleFromPathname,\n isLocaleSupportedOnDomain\n} from './utils';\n\nconst ROOT_URL = '/';\n\nfunction receiveConfig(config: MiddlewareConfig) {\n const result: MiddlewareConfigWithDefaults = {\n ...config,\n alternateLinks: config.alternateLinks ?? true,\n localePrefix: config.localePrefix ?? 'as-needed',\n localeDetection: config.localeDetection ?? true\n };\n\n return result;\n}\n\nexport default function createMiddleware(config: MiddlewareConfig) {\n const configWithDefaults = receiveConfig(config);\n\n // Currently only in use to enable a seamless upgrade path from the\n // `{createIntlMiddleware} from 'next-intl/server'` API.\n const matcher: Array<string> | undefined = (config as any)._matcher;\n\n return function middleware(request: NextRequest) {\n const matches =\n !matcher ||\n matcher.some((pattern) => request.nextUrl.pathname.match(pattern));\n if (!matches) return NextResponse.next();\n\n const {domain, locale} = resolveLocale(\n configWithDefaults,\n request.headers,\n request.cookies,\n request.nextUrl.pathname\n );\n\n const isRoot = request.nextUrl.pathname === ROOT_URL;\n const hasOutdatedCookie =\n request.cookies.get(COOKIE_LOCALE_NAME)?.value !== locale;\n const hasMatchedDefaultLocale = domain\n ? domain.defaultLocale === locale\n : locale === configWithDefaults.defaultLocale;\n\n const domainConfigs =\n configWithDefaults.domains?.filter((curDomain) =>\n isLocaleSupportedOnDomain(locale, curDomain)\n ) || [];\n const hasUnknownHost = configWithDefaults.domains != null && !domain;\n\n function getResponseInit() {\n const responseInit = {\n request: {\n headers: request.headers\n }\n };\n\n return responseInit;\n }\n\n function rewrite(url: string) {\n return NextResponse.rewrite(new URL(url, request.url), getResponseInit());\n }\n\n function next() {\n return NextResponse.next(getResponseInit());\n }\n\n function redirect(url: string, host?: string) {\n const urlObj = new URL(url, request.url);\n\n if (domainConfigs.length > 0) {\n if (!host) {\n const bestMatchingDomain = getBestMatchingDomain(\n domain,\n locale,\n domainConfigs\n );\n\n if (bestMatchingDomain) {\n host = bestMatchingDomain.domain;\n\n if (\n bestMatchingDomain.defaultLocale === locale &&\n configWithDefaults.localePrefix === 'as-needed'\n ) {\n urlObj.pathname = urlObj.pathname.replace(`/${locale}`, '');\n }\n }\n }\n }\n\n if (host) {\n urlObj.host = host;\n }\n\n return NextResponse.redirect(urlObj.toString());\n }\n\n let response;\n if (isRoot) {\n let pathWithSearch = `/${locale}`;\n if (request.nextUrl.search) {\n pathWithSearch += request.nextUrl.search;\n }\n\n if (\n hasMatchedDefaultLocale &&\n configWithDefaults.localePrefix === 'as-needed'\n ) {\n response = rewrite(pathWithSearch);\n } else {\n response = redirect(pathWithSearch);\n }\n } else {\n const pathLocaleCandidate = getLocaleFromPathname(\n request.nextUrl.pathname\n );\n const pathLocale = configWithDefaults.locales.includes(\n pathLocaleCandidate\n )\n ? pathLocaleCandidate\n : undefined;\n const hasLocalePrefix = pathLocale != null;\n\n let pathWithSearch = request.nextUrl.pathname;\n if (request.nextUrl.search) {\n pathWithSearch += request.nextUrl.search;\n }\n\n if (hasLocalePrefix) {\n const basePath = pathWithSearch.replace(`/${pathLocale}`, '') || '/';\n\n if (pathLocale === locale) {\n if (\n hasMatchedDefaultLocale &&\n configWithDefaults.localePrefix === 'as-needed'\n ) {\n response = redirect(basePath);\n } else {\n if (configWithDefaults.domains) {\n const pathDomain = getBestMatchingDomain(\n domain,\n pathLocale,\n domainConfigs\n );\n\n if (domain?.domain !== pathDomain?.domain && !hasUnknownHost) {\n response = redirect(basePath, pathDomain?.domain);\n } else {\n response = next();\n }\n } else {\n response = next();\n }\n }\n } else {\n response = redirect(`/${locale}${basePath}`);\n }\n } else {\n if (\n hasMatchedDefaultLocale &&\n (configWithDefaults.localePrefix === 'as-needed' ||\n configWithDefaults.domains)\n ) {\n response = rewrite(`/${locale}${pathWithSearch}`);\n } else {\n response = redirect(`/${locale}${pathWithSearch}`);\n }\n }\n }\n\n if (hasOutdatedCookie) {\n response.cookies.set(COOKIE_LOCALE_NAME, locale, {\n sameSite: 'strict'\n });\n }\n\n if (\n configWithDefaults.alternateLinks &&\n configWithDefaults.locales.length > 1\n ) {\n response.headers.set(\n 'Link',\n getAlternateLinksHeaderValue(configWithDefaults, request)\n );\n }\n\n return response;\n };\n}\n"],"mappings":"AAAA,OAAqB,gBAAAA,MAAmB,cACxC,OAAQ,sBAAAC,MAAyB,sBAIjC,OAAOC,MAAkC,iCACzC,OAAOC,MAAmB,kBAC1B,OACE,yBAAAC,EACA,yBAAAC,EACA,6BAAAC,MACK,UAEP,MAAMC,EAAW,IAEjB,SAASC,EAAcC,EAA0B,CAfjD,IAAAC,EAAAC,EAAAC,EAuBE,MAP6C,CAC3C,GAAGH,EACH,gBAAgBC,EAAAD,EAAO,iBAAP,KAAAC,EAAyB,GACzC,cAAcC,EAAAF,EAAO,eAAP,KAAAE,EAAuB,YACrC,iBAAiBC,EAAAH,EAAO,kBAAP,KAAAG,EAA0B,EAC7C,CAGF,CAEe,SAARC,EAAkCJ,EAA0B,CACjE,MAAMK,EAAqBN,EAAcC,CAAM,EAIzCM,EAAsCN,EAAe,SAE3D,OAAO,SAAoBO,EAAsB,CAjCnD,IAAAN,EAAAC,EAqCI,GAAI,EAFF,CAACI,GACDA,EAAQ,KAAME,GAAYD,EAAQ,QAAQ,SAAS,MAAMC,CAAO,CAAC,GACrD,OAAOjB,EAAa,KAAK,EAEvC,KAAM,CAAC,OAAAkB,EAAQ,OAAAC,CAAM,EAAIhB,EACvBW,EACAE,EAAQ,QACRA,EAAQ,QACRA,EAAQ,QAAQ,QAClB,EAEMI,EAASJ,EAAQ,QAAQ,WAAaT,EACtCc,IACJX,EAAAM,EAAQ,QAAQ,IAAIf,CAAkB,IAAtC,YAAAS,EAAyC,SAAUS,EAC/CG,EAA0BJ,EAC5BA,EAAO,gBAAkBC,EACzBA,IAAWL,EAAmB,cAE5BS,IACJZ,EAAAG,EAAmB,UAAnB,YAAAH,EAA4B,OAAQa,GAClClB,EAA0Ba,EAAQK,CAAS,KACxC,CAAC,EACFC,EAAiBX,EAAmB,SAAW,MAAQ,CAACI,EAE9D,SAASQ,GAAkB,CAOzB,MANqB,CACnB,QAAS,CACP,QAASV,EAAQ,OACnB,CACF,CAGF,CAEA,SAASW,EAAQC,EAAa,CAC5B,OAAO5B,EAAa,QAAQ,IAAI,IAAI4B,EAAKZ,EAAQ,GAAG,EAAGU,EAAgB,CAAC,CAC1E,CAEA,SAASG,GAAO,CACd,OAAO7B,EAAa,KAAK0B,EAAgB,CAAC,CAC5C,CAEA,SAASI,EAASF,EAAaG,EAAe,CAC5C,MAAMC,EAAS,IAAI,IAAIJ,EAAKZ,EAAQ,GAAG,EAEvC,GAAIO,EAAc,OAAS,GACrB,CAACQ,EAAM,CACT,MAAME,EAAqB7B,EACzBc,EACAC,EACAI,CACF,EAEIU,IACFF,EAAOE,EAAmB,OAGxBA,EAAmB,gBAAkBd,GACrCL,EAAmB,eAAiB,cAEpCkB,EAAO,SAAWA,EAAO,SAAS,QAAQ,IAAIb,CAAM,GAAI,EAAE,GAGhE,CAGF,OAAIY,IACFC,EAAO,KAAOD,GAGT/B,EAAa,SAASgC,EAAO,SAAS,CAAC,CAChD,CAEA,IAAIE,EACJ,GAAId,EAAQ,CACV,IAAIe,EAAiB,IAAIhB,CAAM,GAC3BH,EAAQ,QAAQ,SAClBmB,GAAkBnB,EAAQ,QAAQ,QAIlCM,GACAR,EAAmB,eAAiB,YAEpCoB,EAAWP,EAAQQ,CAAc,EAEjCD,EAAWJ,EAASK,CAAc,CAEtC,KAAO,CACL,MAAMC,EAAsB/B,EAC1BW,EAAQ,QAAQ,QAClB,EACMqB,EAAavB,EAAmB,QAAQ,SAC5CsB,CACF,EACIA,EACA,OACEE,EAAkBD,GAAc,KAEtC,IAAIF,EAAiBnB,EAAQ,QAAQ,SAKrC,GAJIA,EAAQ,QAAQ,SAClBmB,GAAkBnB,EAAQ,QAAQ,QAGhCsB,EAAiB,CACnB,MAAMC,EAAWJ,EAAe,QAAQ,IAAIE,CAAU,GAAI,EAAE,GAAK,IAEjE,GAAIA,IAAelB,EACjB,GACEG,GACAR,EAAmB,eAAiB,YAEpCoB,EAAWJ,EAASS,CAAQ,UAExBzB,EAAmB,QAAS,CAC9B,MAAM0B,EAAapC,EACjBc,EACAmB,EACAd,CACF,GAEIL,GAAA,YAAAA,EAAQ,WAAWsB,GAAA,YAAAA,EAAY,SAAU,CAACf,EAC5CS,EAAWJ,EAASS,EAAUC,GAAA,YAAAA,EAAY,MAAM,EAEhDN,EAAWL,EAAK,CAEpB,MACEK,EAAWL,EAAK,OAIpBK,EAAWJ,EAAS,IAAIX,CAAM,GAAGoB,CAAQ,EAAE,CAE/C,MAEIjB,IACCR,EAAmB,eAAiB,aACnCA,EAAmB,SAErBoB,EAAWP,EAAQ,IAAIR,CAAM,GAAGgB,CAAc,EAAE,EAEhDD,EAAWJ,EAAS,IAAIX,CAAM,GAAGgB,CAAc,EAAE,CAGvD,CAEA,OAAId,GACFa,EAAS,QAAQ,IAAIjC,EAAoBkB,EAAQ,CAC/C,SAAU,QACZ,CAAC,EAIDL,EAAmB,gBACnBA,EAAmB,QAAQ,OAAS,GAEpCoB,EAAS,QAAQ,IACf,OACAhC,EAA6BY,EAAoBE,CAAO,CAC1D,EAGKkB,CACT,CACF","names":["NextResponse","COOKIE_LOCALE_NAME","getAlternateLinksHeaderValue","resolveLocale","getBestMatchingDomain","getLocaleFromPathname","isLocaleSupportedOnDomain","ROOT_URL","receiveConfig","config","_a","_b","_c","createMiddleware","configWithDefaults","matcher","request","pattern","domain","locale","isRoot","hasOutdatedCookie","hasMatchedDefaultLocale","domainConfigs","curDomain","hasUnknownHost","getResponseInit","rewrite","url","next","redirect","host","urlObj","bestMatchingDomain","response","pathWithSearch","pathLocaleCandidate","pathLocale","hasLocalePrefix","basePath","pathDomain"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
2
|
+
import { MiddlewareConfigWithDefaults, DomainConfig } from './NextIntlMiddlewareConfig.mjs';
|
|
3
|
+
|
|
4
|
+
declare function resolveLocale(config: MiddlewareConfigWithDefaults, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
|
|
5
|
+
locale: string;
|
|
6
|
+
domain?: DomainConfig;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { resolveLocale as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{match as u}from"@formatjs/intl-localematcher";import g from"negotiator";import{COOKIE_LOCALE_NAME as c}from"../shared/constants";import{getLocaleFromPathname as d,getHost as m,isLocaleSupportedOnDomain as L}from"./utils";function p(i,t){let e=m(i);if(e=e==null?void 0:e.replace(/:\d+$/,""),e&&t)return t.find(o=>o.domain===e)}function C(i,t,e){let o;const n=new g({headers:{"accept-language":i.get("accept-language")||void 0}}).languages();try{o=u(n,t,e)}catch{}return o}function s({defaultLocale:i,localeDetection:t,locales:e},o,n,a){var f;let r;if(a){const l=d(a);e.includes(l)&&(r=l)}if(!r&&t&&n&&n.has(c)){const l=(f=n.get(c))==null?void 0:f.value;l&&e.includes(l)&&(r=l)}return!r&&t&&o&&(r=C(o,e,i)),r||(r=i),r}function D(i,t,e,o){const{domains:n}=i,a=s(i,t,e,o);if(n){const r=p(t,n),f=o&&o.startsWith(`/${a}`);if(r)return{locale:L(a,r)||f?a:r.defaultLocale,domain:r}}return{locale:a}}function h(i,t,e,o){return i.domains?D(i,t,e,o):{locale:s(i,t,e,o)}}export{h as default};
|
|
2
|
+
//# sourceMappingURL=resolveLocale.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/resolveLocale.tsx"],"sourcesContent":["import {match} from '@formatjs/intl-localematcher';\nimport Negotiator from 'negotiator';\nimport {RequestCookies} from 'next/dist/server/web/spec-extension/cookies';\nimport {COOKIE_LOCALE_NAME} from '../shared/constants';\nimport {\n DomainConfig,\n MiddlewareConfigWithDefaults\n} from './NextIntlMiddlewareConfig';\nimport {\n getLocaleFromPathname,\n getHost,\n isLocaleSupportedOnDomain\n} from './utils';\n\nfunction findDomainFromHost(\n requestHeaders: Headers,\n domains: Array<DomainConfig>\n) {\n let host = getHost(requestHeaders);\n\n // Remove port (easier for local development)\n host = host?.replace(/:\\d+$/, '');\n\n if (host && domains) {\n return domains.find((cur) => cur.domain === host);\n }\n\n return undefined;\n}\n\nfunction getAcceptLanguageLocale(\n requestHeaders: Headers,\n locales: Array<string>,\n defaultLocale: string\n) {\n let locale;\n\n const languages = new Negotiator({\n headers: {\n 'accept-language': requestHeaders.get('accept-language') || undefined\n }\n }).languages();\n try {\n locale = match(languages, locales, defaultLocale);\n } catch (e) {\n // Invalid language\n }\n\n return locale;\n}\n\nfunction resolveLocaleFromPrefix(\n {defaultLocale, localeDetection, locales}: MiddlewareConfigWithDefaults,\n requestHeaders: Headers,\n requestCookies: RequestCookies,\n pathname: string\n) {\n let locale;\n\n // Prio 1: Use route prefix\n if (pathname) {\n const pathLocale = getLocaleFromPathname(pathname);\n if (locales.includes(pathLocale)) {\n locale = pathLocale;\n }\n }\n\n // Prio 2: Use existing cookie\n if (!locale && localeDetection && requestCookies) {\n if (requestCookies.has(COOKIE_LOCALE_NAME)) {\n const value = requestCookies.get(COOKIE_LOCALE_NAME)?.value;\n if (value && locales.includes(value)) {\n locale = value;\n }\n }\n }\n\n // Prio 3: Use the `accept-language` header\n if (!locale && localeDetection && requestHeaders) {\n locale = getAcceptLanguageLocale(requestHeaders, locales, defaultLocale);\n }\n\n // Prio 4: Use default locale\n if (!locale) {\n locale = defaultLocale;\n }\n\n return locale;\n}\n\nfunction resolveLocaleFromDomain(\n config: MiddlewareConfigWithDefaults,\n requestHeaders: Headers,\n requestCookies: RequestCookies,\n pathname: string\n) {\n const {domains} = config;\n\n const localeFromPrefixStrategy = resolveLocaleFromPrefix(\n config,\n requestHeaders,\n requestCookies,\n pathname\n );\n\n // Prio 1: Use a domain\n if (domains) {\n const domain = findDomainFromHost(requestHeaders, domains);\n const hasLocalePrefix =\n pathname && pathname.startsWith(`/${localeFromPrefixStrategy}`);\n\n if (domain) {\n return {\n locale:\n isLocaleSupportedOnDomain(localeFromPrefixStrategy, domain) ||\n hasLocalePrefix\n ? localeFromPrefixStrategy\n : domain.defaultLocale,\n domain\n };\n }\n }\n\n // Prio 2: Use prefix strategy\n return {locale: localeFromPrefixStrategy};\n}\n\nexport default function resolveLocale(\n config: MiddlewareConfigWithDefaults,\n requestHeaders: Headers,\n requestCookies: RequestCookies,\n pathname: string\n): {locale: string; domain?: DomainConfig} {\n if (config.domains) {\n return resolveLocaleFromDomain(\n config,\n requestHeaders,\n requestCookies,\n pathname\n );\n } else {\n return {\n locale: resolveLocaleFromPrefix(\n config,\n requestHeaders,\n requestCookies,\n pathname\n )\n };\n }\n}\n"],"mappings":"AAAA,OAAQ,SAAAA,MAAY,+BACpB,OAAOC,MAAgB,aAEvB,OAAQ,sBAAAC,MAAyB,sBAKjC,OACE,yBAAAC,EACA,WAAAC,EACA,6BAAAC,MACK,UAEP,SAASC,EACPC,EACAC,EACA,CACA,IAAIC,EAAOL,EAAQG,CAAc,EAKjC,GAFAE,EAAOA,GAAA,YAAAA,EAAM,QAAQ,QAAS,IAE1BA,GAAQD,EACV,OAAOA,EAAQ,KAAME,GAAQA,EAAI,SAAWD,CAAI,CAIpD,CAEA,SAASE,EACPJ,EACAK,EACAC,EACA,CACA,IAAIC,EAEJ,MAAMC,EAAY,IAAId,EAAW,CAC/B,QAAS,CACP,kBAAmBM,EAAe,IAAI,iBAAiB,GAAK,MAC9D,CACF,CAAC,EAAE,UAAU,EACb,GAAI,CACFO,EAASd,EAAMe,EAAWH,EAASC,CAAa,CAClD,MAAY,CAEZ,CAEA,OAAOC,CACT,CAEA,SAASE,EACP,CAAC,cAAAH,EAAe,gBAAAI,EAAiB,QAAAL,CAAO,EACxCL,EACAW,EACAC,EACA,CAxDF,IAAAC,EAyDE,IAAIN,EAGJ,GAAIK,EAAU,CACZ,MAAME,EAAalB,EAAsBgB,CAAQ,EAC7CP,EAAQ,SAASS,CAAU,IAC7BP,EAASO,EAEb,CAGA,GAAI,CAACP,GAAUG,GAAmBC,GAC5BA,EAAe,IAAIhB,CAAkB,EAAG,CAC1C,MAAMoB,GAAQF,EAAAF,EAAe,IAAIhB,CAAkB,IAArC,YAAAkB,EAAwC,MAClDE,GAASV,EAAQ,SAASU,CAAK,IACjCR,EAASQ,EAEb,CAIF,MAAI,CAACR,GAAUG,GAAmBV,IAChCO,EAASH,EAAwBJ,EAAgBK,EAASC,CAAa,GAIpEC,IACHA,EAASD,GAGJC,CACT,CAEA,SAASS,EACPC,EACAjB,EACAW,EACAC,EACA,CACA,KAAM,CAAC,QAAAX,CAAO,EAAIgB,EAEZC,EAA2BT,EAC/BQ,EACAjB,EACAW,EACAC,CACF,EAGA,GAAIX,EAAS,CACX,MAAMkB,EAASpB,EAAmBC,EAAgBC,CAAO,EACnDmB,EACJR,GAAYA,EAAS,WAAW,IAAIM,CAAwB,EAAE,EAEhE,GAAIC,EACF,MAAO,CACL,OACErB,EAA0BoB,EAA0BC,CAAM,GAC1DC,EACIF,EACAC,EAAO,cACb,OAAAA,CACF,CAEJ,CAGA,MAAO,CAAC,OAAQD,CAAwB,CAC1C,CAEe,SAARG,EACLJ,EACAjB,EACAW,EACAC,EACyC,CACzC,OAAIK,EAAO,QACFD,EACLC,EACAjB,EACAW,EACAC,CACF,EAEO,CACL,OAAQH,EACNQ,EACAjB,EACAW,EACAC,CACF,CACF,CAEJ","names":["match","Negotiator","COOKIE_LOCALE_NAME","getLocaleFromPathname","getHost","isLocaleSupportedOnDomain","findDomainFromHost","requestHeaders","domains","host","cur","getAcceptLanguageLocale","locales","defaultLocale","locale","languages","resolveLocaleFromPrefix","localeDetection","requestCookies","pathname","_a","pathLocale","value","resolveLocaleFromDomain","config","localeFromPrefixStrategy","domain","hasLocalePrefix","resolveLocale"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DomainConfig } from './NextIntlMiddlewareConfig.mjs';
|
|
2
|
+
|
|
3
|
+
declare function getLocaleFromPathname(pathname: string): string;
|
|
4
|
+
declare function getHost(requestHeaders: Headers): string | undefined;
|
|
5
|
+
declare function isLocaleSupportedOnDomain(locale: string, domain: DomainConfig): boolean;
|
|
6
|
+
declare function getBestMatchingDomain(curHostDomain: DomainConfig | undefined, locale: string, domainConfigs: Array<DomainConfig>): DomainConfig | undefined;
|
|
7
|
+
|
|
8
|
+
export { getBestMatchingDomain, getHost, getLocaleFromPathname, isLocaleSupportedOnDomain };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function g(e){return e.split("/")[1]}function d(e){var n,f;return(f=(n=e.get("x-forwarded-host"))!=null?n:e.get("host"))!=null?f:void 0}function l(e,n){return n.defaultLocale===e||!n.locales||n.locales.includes(e)}function a(e,n,f){let t;return e&&l(n,e)&&(t=e),t||(t=f.find(i=>i.defaultLocale===n)),t||(t=f.find(i=>i.locales!=null&&i.locales.includes(n))),!t&&(e==null?void 0:e.locales)==null&&(t=e),t||(t=f.find(i=>!i.locales)),t}export{a as getBestMatchingDomain,d as getHost,g as getLocaleFromPathname,l as isLocaleSupportedOnDomain};
|
|
2
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/utils.tsx"],"sourcesContent":["import {DomainConfig} from './NextIntlMiddlewareConfig';\n\nexport function getLocaleFromPathname(pathname: string) {\n return pathname.split('/')[1];\n}\n\nexport function getHost(requestHeaders: Headers) {\n return (\n requestHeaders.get('x-forwarded-host') ??\n requestHeaders.get('host') ??\n undefined\n );\n}\n\nexport function isLocaleSupportedOnDomain(\n locale: string,\n domain: DomainConfig\n) {\n return (\n domain.defaultLocale === locale ||\n !domain.locales ||\n domain.locales.includes(locale)\n );\n}\n\nexport function getBestMatchingDomain(\n curHostDomain: DomainConfig | undefined,\n locale: string,\n domainConfigs: Array<DomainConfig>\n) {\n let domainConfig;\n\n // Prio 1: Stay on current domain\n if (curHostDomain && isLocaleSupportedOnDomain(locale, curHostDomain)) {\n domainConfig = curHostDomain;\n }\n\n // Prio 2: Use alternative domain with matching default locale\n if (!domainConfig) {\n domainConfig = domainConfigs.find((cur) => cur.defaultLocale === locale);\n }\n\n // Prio 3: Use alternative domain with restricted matching locale\n if (!domainConfig) {\n domainConfig = domainConfigs.find(\n (cur) => cur.locales != null && cur.locales.includes(locale)\n );\n }\n\n // Prio 4: Stay on the current domain if it supports all locales\n if (!domainConfig && curHostDomain?.locales == null) {\n domainConfig = curHostDomain;\n }\n\n // Prio 5: Use alternative domain that supports all locales\n if (!domainConfig) {\n domainConfig = domainConfigs.find((cur) => !cur.locales);\n }\n\n return domainConfig;\n}\n"],"mappings":"AAEO,SAASA,EAAsBC,EAAkB,CACtD,OAAOA,EAAS,MAAM,GAAG,EAAE,CAAC,CAC9B,CAEO,SAASC,EAAQC,EAAyB,CANjD,IAAAC,EAAAC,EAOE,OACEA,GAAAD,EAAAD,EAAe,IAAI,kBAAkB,IAArC,KAAAC,EACAD,EAAe,IAAI,MAAM,IADzB,KAAAE,EAEA,MAEJ,CAEO,SAASC,EACdC,EACAC,EACA,CACA,OACEA,EAAO,gBAAkBD,GACzB,CAACC,EAAO,SACRA,EAAO,QAAQ,SAASD,CAAM,CAElC,CAEO,SAASE,EACdC,EACAH,EACAI,EACA,CACA,IAAIC,EAGJ,OAAIF,GAAiBJ,EAA0BC,EAAQG,CAAa,IAClEE,EAAeF,GAIZE,IACHA,EAAeD,EAAc,KAAME,GAAQA,EAAI,gBAAkBN,CAAM,GAIpEK,IACHA,EAAeD,EAAc,KAC1BE,GAAQA,EAAI,SAAW,MAAQA,EAAI,QAAQ,SAASN,CAAM,CAC7D,GAIE,CAACK,IAAgBF,GAAA,YAAAA,EAAe,UAAW,OAC7CE,EAAeF,GAIZE,IACHA,EAAeD,EAAc,KAAME,GAAQ,CAACA,EAAI,OAAO,GAGlDD,CACT","names":["getLocaleFromPathname","pathname","getHost","requestHeaders","_a","_b","isLocaleSupportedOnDomain","locale","domain","getBestMatchingDomain","curHostDomain","domainConfigs","domainConfig","cur"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react-client/index.tsx"],"sourcesContent":["/**\n * This is the main entry file when non-'react-server'\n * environments import from 'next-intl'.\n *\n * Maintainer notes:\n * - Make sure this mirrors the API from 'react-server'.\n * - Make sure everything exported from this module is\n * supported in all Next.js versions that are supported.\n */\n\nexport * from 'use-intl';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\n// Legacy export (TBD if we'll deprecate this in favour of `NextIntlClientProvider`)\nexport {default as NextIntlProvider} from '../shared/NextIntlClientProvider';\n"],"mappings":"AAUA,WAAc,WACd,OAAmB,WAAXA,MAAwC,mCAGhD,OAAmB,WAAXA,MAAkC","names":["default"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from 'use-intl/dist/src/core';
|
|
2
|
+
export { default as NextIntlClientProvider } from '../shared/NextIntlClientProvider.mjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'use-intl';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is the main entry file when 'react-server' environments
|
|
8
|
+
* (i.e. RSC) import from 'next-intl'. Currently we export everything
|
|
9
|
+
* from `use-intl` core, but React-APIs are stubbed out.
|
|
10
|
+
*
|
|
11
|
+
* Make sure this mirrors the API from '../react-client'.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare function notSupported(): void;
|
|
15
|
+
declare const IntlProvider: typeof notSupported;
|
|
16
|
+
declare const useTranslations: typeof notSupported;
|
|
17
|
+
declare const useIntl: typeof notSupported;
|
|
18
|
+
declare const useLocale: typeof notSupported;
|
|
19
|
+
declare const useNow: typeof notSupported;
|
|
20
|
+
declare const useTimeZone: typeof notSupported;
|
|
21
|
+
declare const Link: typeof notSupported;
|
|
22
|
+
|
|
23
|
+
export { IntlProvider, Link, useIntl, useLocale, useNow, useTimeZone, useTranslations };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export*from"use-intl/dist/src/core";import{default as x}from"../shared/NextIntlClientProvider";function e(){throw new Error(`The React APIs of next-intl are currently not available in Server Components.
|
|
2
|
+
|
|
3
|
+
You can try one of these options:
|
|
4
|
+
1. Try out the Server Components beta, see https://next-intl-docs.vercel.app/docs/next-13/server-components
|
|
5
|
+
2. Use the core library as a stopgap solution, see https://next-intl-docs.vercel.app/docs/usage/core-library
|
|
6
|
+
`)}const t=e,o=e,r=e,n=e,s=e,p=e,c=e;export{t as IntlProvider,c as Link,x as NextIntlClientProvider,r as useIntl,n as useLocale,s as useNow,p as useTimeZone,o as useTranslations};
|
|
7
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/react-server/index.tsx"],"sourcesContent":["/**\n * This is the main entry file when 'react-server' environments\n * (i.e. RSC) import from 'next-intl'. Currently we export everything\n * from `use-intl` core, but React-APIs are stubbed out.\n *\n * Make sure this mirrors the API from '../react-client'.\n */\n\nexport * from 'use-intl/dist/src/core';\nexport {default as NextIntlClientProvider} from '../shared/NextIntlClientProvider';\n\nfunction notSupported() {\n throw new Error(\n `The React APIs of next-intl are currently not available in Server Components.\n\nYou can try one of these options:\n1. Try out the Server Components beta, see https://next-intl-docs.vercel.app/docs/next-13/server-components\n2. Use the core library as a stopgap solution, see https://next-intl-docs.vercel.app/docs/usage/core-library\n`\n );\n}\n\nexport const IntlProvider = notSupported;\nexport const useTranslations = notSupported;\nexport const useIntl = notSupported;\nexport const useLocale = notSupported;\nexport const useNow = notSupported;\nexport const useTimeZone = notSupported;\nexport const Link = notSupported;\n"],"mappings":"AAQA,WAAc,yBACd,OAAmB,WAAXA,MAAwC,mCAEhD,SAASC,GAAe,CACtB,MAAM,IAAI,MACR;AAAA;AAAA;AAAA;AAAA;AAAA,CAMF,CACF,CAEO,MAAMC,EAAeD,EACfE,EAAkBF,EAClBG,EAAUH,EACVI,EAAYJ,EACZK,EAASL,EACTM,EAAcN,EACdO,EAAOP","names":["default","notSupported","IntlProvider","useTranslations","useIntl","useLocale","useNow","useTimeZone","Link"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import MiddlewareConfig from '../middleware/NextIntlMiddlewareConfig.mjs';
|
|
3
|
+
|
|
4
|
+
/** @deprecated Should be imported as `import createMiddleware from 'next-intl/middleware', not from `next-intl/server`. */
|
|
5
|
+
declare function createIntlMiddleware(config: MiddlewareConfig): (request: next_server.NextRequest) => next_server.NextResponse<unknown>;
|
|
6
|
+
|
|
7
|
+
export { createIntlMiddleware };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import r from"../middleware";let e=!1;function n(t){return e||(e=!0,console.warn(`
|
|
2
|
+
Importing \`createMiddleware\` from \`next-intl/server\` is deprecated. Please update the import and add a \`matcher\`:
|
|
3
|
+
|
|
4
|
+
// middleware.ts
|
|
5
|
+
import createMiddleware from 'next-intl/middleware';
|
|
6
|
+
|
|
7
|
+
// ...
|
|
8
|
+
|
|
9
|
+
export const config = {
|
|
10
|
+
// Skip all paths that should not be internationalized
|
|
11
|
+
matcher: ['/((?!api|_next|.*\\\\..*).*)']
|
|
12
|
+
};
|
|
13
|
+
`)),r({...t,_matcher:["/((?!api|_next|.*\\..*).*)"]})}export{n as createIntlMiddleware};
|
|
14
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/server/index.tsx"],"sourcesContent":["/**\n * Server-only APIs available via `next-intl/server`.\n */\n\nimport createMiddleware_ from '../middleware';\nimport MiddlewareConfig from '../middleware/NextIntlMiddlewareConfig';\n\nlet hasWarned = false;\n/** @deprecated Should be imported as `import createMiddleware from 'next-intl/middleware', not from `next-intl/server`. */\nexport function createIntlMiddleware(config: MiddlewareConfig) {\n if (!hasWarned) {\n hasWarned = true;\n console.warn(\n `\nImporting \\`createMiddleware\\` from \\`next-intl/server\\` is deprecated. Please update the import and add a \\`matcher\\`:\n\n // middleware.ts\n import createMiddleware from 'next-intl/middleware';\n\n // ...\n\n export const config = {\n // Skip all paths that should not be internationalized\n matcher: ['/((?!api|_next|.*\\\\\\\\..*).*)']\n };\n`\n );\n }\n return createMiddleware_({\n ...config,\n // @ts-expect-error\n _matcher: ['/((?!api|_next|.*\\\\..*).*)']\n });\n}\n"],"mappings":"AAIA,OAAOA,MAAuB,gBAG9B,IAAIC,EAAY,GAET,SAASC,EAAqBC,EAA0B,CAC7D,OAAKF,IACHA,EAAY,GACZ,QAAQ,KACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAaF,GAEKD,EAAkB,CACvB,GAAGG,EAEH,SAAU,CAAC,4BAA4B,CACzC,CAAC,CACH","names":["createMiddleware_","hasWarned","createIntlMiddleware","config"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import NextLink from 'next/link';
|
|
2
|
+
import React, { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
type Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {
|
|
5
|
+
locale: string;
|
|
6
|
+
};
|
|
7
|
+
declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
8
|
+
|
|
9
|
+
export { _default as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import l from"next/link";import{usePathname as u}from"next/navigation";import a,{forwardRef as m,useEffect as d,useState as L}from"react";import P from"../client/useClientLocale";import{isLocalHref as y,localizeHref as h,prefixHref as H}from"./utils";function g({href:e,locale:o,prefetch:r,...i},s){const t=u(),n=P(),f=o!==n,[p,c]=L(()=>y(e)&&o?H(e,o):e);return d(()=>{t&&c(h(e,o,n,t!=null?t:void 0))},[n,e,o,t]),f&&(r&&process.env.NODE_ENV!=="production"&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),r=!1),a.createElement(l,{ref:s,href:p,prefetch:r,...i})}var E=m(g);export{E as default};
|
|
2
|
+
//# sourceMappingURL=BaseLink.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/BaseLink.tsx"],"sourcesContent":["'use client';\n\nimport NextLink from 'next/link';\nimport {usePathname} from 'next/navigation';\nimport React, {ComponentProps, forwardRef, useEffect, useState} from 'react';\nimport useClientLocale from '../client/useClientLocale';\nimport {isLocalHref, localizeHref, prefixHref} from './utils';\n\ntype Props = Omit<ComponentProps<typeof NextLink>, 'locale'> & {\n locale: string;\n};\n\nfunction BaseLink({href, locale, prefetch, ...rest}: Props, ref: Props['ref']) {\n // The types aren't entirely correct here. Outside of Next.js\n // `useParams` can be called, but the return type is `null`.\n const pathname = usePathname() as ReturnType<typeof usePathname> | null;\n\n const defaultLocale = useClientLocale();\n const isChangingLocale = locale !== defaultLocale;\n\n const [localizedHref, setLocalizedHref] = useState<typeof href>(() =>\n isLocalHref(href) && locale\n ? // Potentially the href shouldn't be prefixed, but to determine this we\n // need a) the default locale and b) the information if we use prefixed\n // routing. During the server side render (both in RSC as well as SSR),\n // we don't have this information. Therefore we always prefix the href\n // since this will always result in a valid URL, even if it might cause\n // a redirect. This is better than pointing to a non-localized href\n // during the server render, which would potentially be wrong. The final\n // href is determined in the effect below.\n prefixHref(href, locale)\n : href\n );\n\n useEffect(() => {\n if (!pathname) return;\n\n setLocalizedHref(\n localizeHref(href, locale, defaultLocale, pathname ?? undefined)\n );\n }, [defaultLocale, href, locale, pathname]);\n\n if (isChangingLocale) {\n if (prefetch && process.env.NODE_ENV !== 'production') {\n console.error(\n 'The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`'\n );\n }\n prefetch = false;\n }\n\n return (\n <NextLink ref={ref} href={localizedHref} prefetch={prefetch} {...rest} />\n );\n}\n\nexport default forwardRef(BaseLink);\n"],"mappings":"aAEA,OAAOA,MAAc,YACrB,OAAQ,eAAAC,MAAkB,kBAC1B,OAAOC,GAAwB,cAAAC,EAAY,aAAAC,EAAW,YAAAC,MAAe,QACrE,OAAOC,MAAqB,4BAC5B,OAAQ,eAAAC,EAAa,gBAAAC,EAAc,cAAAC,MAAiB,UAMpD,SAASC,EAAS,CAAC,KAAAC,EAAM,OAAAC,EAAQ,SAAAC,EAAU,GAAGC,CAAI,EAAUC,EAAmB,CAG7E,MAAMC,EAAWf,EAAY,EAEvBgB,EAAgBX,EAAgB,EAChCY,EAAmBN,IAAWK,EAE9B,CAACE,EAAeC,CAAgB,EAAIf,EAAsB,IAC9DE,EAAYI,CAAI,GAAKC,EASjBH,EAAWE,EAAMC,CAAM,EACvBD,CACN,EAEA,OAAAP,EAAU,IAAM,CACTY,GAELI,EACEZ,EAAaG,EAAMC,EAAQK,EAAeD,GAAA,KAAAA,EAAY,MAAS,CACjE,CACF,EAAG,CAACC,EAAeN,EAAMC,EAAQI,CAAQ,CAAC,EAEtCE,IACEL,GAAY,QAAQ,IAAI,WAAa,cACvC,QAAQ,MACN,8GACF,EAEFA,EAAW,IAIXX,EAAA,cAACF,EAAA,CAAS,IAAKe,EAAK,KAAMI,EAAe,SAAUN,EAAW,GAAGC,EAAM,CAE3E,CAEA,IAAOO,EAAQlB,EAAWO,CAAQ","names":["NextLink","usePathname","React","forwardRef","useEffect","useState","useClientLocale","isLocalHref","localizeHref","prefixHref","BaseLink","href","locale","prefetch","rest","ref","pathname","defaultLocale","isChangingLocale","localizedHref","setLocalizedHref","BaseLink_default"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import { IntlProvider } from 'use-intl';
|
|
3
|
+
|
|
4
|
+
type Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */
|
|
7
|
+
now?: Date | string;
|
|
8
|
+
};
|
|
9
|
+
declare function NextIntlClientProvider({ children, locale, now, ...rest }: Props): JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { NextIntlClientProvider as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useRouter as i}from"next/router";import p from"react";import{IntlProvider as s}from"use-intl";function l({children:o,locale:e,now:r,...n}){let t;try{t=i()}catch{}if(!e&&t&&(e=t.locale),typeof r=="string"&&(r=new Date(r)),!e)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).":void 0);return p.createElement(s,{locale:e,now:r,...n},o)}export{l as default};
|
|
2
|
+
//# sourceMappingURL=NextIntlClientProvider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/NextIntlClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport {useRouter} from 'next/router';\nimport React, {ComponentProps} from 'react';\nimport {IntlProvider} from 'use-intl';\n\ntype Props = Omit<ComponentProps<typeof IntlProvider>, 'locale' | 'now'> & {\n locale?: string;\n /** If a string is supplied, make sure this conforms to the ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ */\n now?: Date | string;\n};\n\nexport default function NextIntlClientProvider({\n children,\n locale,\n now,\n ...rest\n}: Props) {\n let router;\n try {\n // Reading from context is practically ok to do conditionally\n // eslint-disable-next-line react-hooks/rules-of-hooks\n router = useRouter();\n } catch (error) {\n // Calling `useRouter` is not supported in the app folder\n }\n\n // The router can be undefined if used in a context outside\n // of Next.js (e.g. unit tests, Storybook, ...)\n if (!locale && router) {\n locale = router.locale;\n }\n\n // Currently RSC serialize dates to strings, therefore make sure we have\n // a date object. We might be able to remove this once more types have\n // first-class serialization support (https://github.com/facebook/react/issues/25687)\n if (typeof now === 'string') {\n now = new Date(now);\n }\n\n if (!locale) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? \"Couldn't determine locale. Please pass an explicit `locale` prop the provider, or if you're using the `pages` folder, use internationalized routing (https://nextjs.org/docs/advanced-features/i18n-routing).\"\n : undefined\n );\n }\n\n return (\n <IntlProvider locale={locale} now={now} {...rest}>\n {children}\n </IntlProvider>\n );\n}\n"],"mappings":"aAEA,OAAQ,aAAAA,MAAgB,cACxB,OAAOC,MAA6B,QACpC,OAAQ,gBAAAC,MAAmB,WAQZ,SAARC,EAAwC,CAC7C,SAAAC,EACA,OAAAC,EACA,IAAAC,EACA,GAAGC,CACL,EAAU,CACR,IAAIC,EACJ,GAAI,CAGFA,EAASR,EAAU,CACrB,MAAgB,CAEhB,CAeA,GAXI,CAACK,GAAUG,IACbH,EAASG,EAAO,QAMd,OAAOF,GAAQ,WACjBA,EAAM,IAAI,KAAKA,CAAG,GAGhB,CAACD,EACH,MAAM,IAAI,MACR,QAAQ,IAAI,WAAa,aACrB,gNACA,MACN,EAGF,OACEJ,EAAA,cAACC,EAAA,CAAa,OAAQG,EAAQ,IAAKC,EAAM,GAAGC,GACzCH,CACH,CAEJ","names":["useRouter","React","IntlProvider","NextIntlClientProvider","children","locale","now","rest","router"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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// In a URL like \"/en-US/about\", the locale segment is \"en-US\"\nexport const LOCALE_SEGMENT_NAME = 'locale';\n"],"mappings":"AAEO,MAAMA,EAAqB,cAGrBC,EAAsB","names":["COOKIE_LOCALE_NAME","LOCALE_SEGMENT_NAME"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UrlObject } from 'url';
|
|
2
|
+
import NextLink from 'next/link';
|
|
3
|
+
import { ComponentProps } from 'react';
|
|
4
|
+
|
|
5
|
+
type Href = ComponentProps<typeof NextLink>['href'];
|
|
6
|
+
declare function isRelativeHref(href: Href): boolean;
|
|
7
|
+
declare function isLocalHref(href: Href): boolean;
|
|
8
|
+
declare function localizeHref(href: string, locale: string, defaultLocale: string, pathname: string): string;
|
|
9
|
+
declare function localizeHref(href: UrlObject | string, locale: string, defaultLocale: string, pathname: string): UrlObject | string;
|
|
10
|
+
declare function prefixHref(href: string, locale: string): string;
|
|
11
|
+
declare function prefixHref(href: UrlObject | string, locale: string): UrlObject | string;
|
|
12
|
+
declare function unlocalizePathname(pathname: string, locale: string): string;
|
|
13
|
+
declare function localizePathname(locale: string, pathname: string): string;
|
|
14
|
+
declare function hasPathnamePrefixed(locale: string, pathname: string): boolean;
|
|
15
|
+
|
|
16
|
+
export { hasPathnamePrefixed, isLocalHref, isRelativeHref, localizeHref, localizePathname, prefixHref, unlocalizePathname };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function s(t){const r=typeof t=="object"?t.pathname:t;return r!=null&&!r.startsWith("/")}function f(t){return typeof t=="object"?t.host==null&&t.hostname==null:!/^[a-z]+:/i.test(t)}function h(t,r,n=r,i){if(!f(t)||s(t))return t;const o=r!==n;return(r==null||a(r,i)||o)&&r!=null?l(t,r):t}function l(t,r){let n;return typeof t=="string"?n=e(r,t):(n={...t},t.pathname&&(n.pathname=e(r,t.pathname))),n}function b(t,r){return t.replace(new RegExp(`^/${r}`),"")||"/"}function e(t,r){let n="/"+t;return r!=="/"&&(n+=r),n}function a(t,r){const n=`/${t}`;return r===n||r.startsWith(`${n}/`)}export{a as hasPathnamePrefixed,f as isLocalHref,s as isRelativeHref,h as localizeHref,e as localizePathname,l as prefixHref,b as unlocalizePathname};
|
|
2
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shared/utils.tsx"],"sourcesContent":["import {UrlObject} from 'url';\nimport NextLink from 'next/link';\nimport {ComponentProps} from 'react';\n\ntype Href = ComponentProps<typeof NextLink>['href'];\n\nexport function isRelativeHref(href: Href) {\n const pathname = typeof href === 'object' ? href.pathname : href;\n return pathname != null && !pathname.startsWith('/');\n}\n\nexport function isLocalHref(href: Href) {\n if (typeof href === 'object') {\n return href.host == null && href.hostname == null;\n } else {\n const hasProtocol = /^[a-z]+:/i.test(href);\n return !hasProtocol;\n }\n}\n\nexport function localizeHref(\n href: string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string,\n pathname: string\n): UrlObject | string;\nexport function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname: string\n) {\n if (!isLocalHref(href) || isRelativeHref(href)) {\n return href;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n\nexport function prefixHref(href: string, locale: string): string;\nexport function prefixHref(\n href: UrlObject | string,\n locale: string\n): UrlObject | string;\nexport function prefixHref(href: UrlObject | string, locale: string) {\n let prefixedHref;\n if (typeof href === 'string') {\n prefixedHref = localizePathname(locale, href);\n } else {\n prefixedHref = {...href};\n if (href.pathname) {\n prefixedHref.pathname = localizePathname(locale, href.pathname);\n }\n }\n\n return prefixedHref;\n}\n\nexport function unlocalizePathname(pathname: string, locale: string) {\n return pathname.replace(new RegExp(`^/${locale}`), '') || '/';\n}\n\nexport function localizePathname(locale: string, pathname: string) {\n let localizedHref = '/' + locale;\n\n if (pathname !== '/') {\n localizedHref += pathname;\n }\n\n return localizedHref;\n}\n\nexport function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return pathname === prefix || pathname.startsWith(`${prefix}/`);\n}\n"],"mappings":"AAMO,SAASA,EAAeC,EAAY,CACzC,MAAMC,EAAW,OAAOD,GAAS,SAAWA,EAAK,SAAWA,EAC5D,OAAOC,GAAY,MAAQ,CAACA,EAAS,WAAW,GAAG,CACrD,CAEO,SAASC,EAAYF,EAAY,CACtC,OAAI,OAAOA,GAAS,SACXA,EAAK,MAAQ,MAAQA,EAAK,UAAY,KAGtC,CADa,YAAY,KAAKA,CAAI,CAG7C,CAcO,SAASG,EACdH,EACAI,EACAC,EAAwBD,EACxBH,EACA,CACA,GAAI,CAACC,EAAYF,CAAI,GAAKD,EAAeC,CAAI,EAC3C,OAAOA,EAGT,MAAMM,EAAoBF,IAAWC,EAKrC,OAHED,GAAU,MAAQG,EAAoBH,EAAQH,CAAQ,GACbK,IAEvBF,GAAU,KACrBI,EAAWR,EAAMI,CAAM,EAGzBJ,CACT,CAOO,SAASQ,EAAWR,EAA0BI,EAAgB,CACnE,IAAIK,EACJ,OAAI,OAAOT,GAAS,SAClBS,EAAeC,EAAiBN,EAAQJ,CAAI,GAE5CS,EAAe,CAAC,GAAGT,CAAI,EACnBA,EAAK,WACPS,EAAa,SAAWC,EAAiBN,EAAQJ,EAAK,QAAQ,IAI3DS,CACT,CAEO,SAASE,EAAmBV,EAAkBG,EAAgB,CACnE,OAAOH,EAAS,QAAQ,IAAI,OAAO,KAAKG,CAAM,EAAE,EAAG,EAAE,GAAK,GAC5D,CAEO,SAASM,EAAiBN,EAAgBH,EAAkB,CACjE,IAAIW,EAAgB,IAAMR,EAE1B,OAAIH,IAAa,MACfW,GAAiBX,GAGZW,CACT,CAEO,SAASL,EAAoBH,EAAgBH,EAAkB,CACpE,MAAMY,EAAS,IAAIT,CAAM,GACzB,OAAOH,IAAaY,GAAUZ,EAAS,WAAW,GAAGY,CAAM,GAAG,CAChE","names":["isRelativeHref","href","pathname","isLocalHref","localizeHref","locale","defaultLocale","isSwitchingLocale","hasPathnamePrefixed","prefixHref","prefixedHref","localizePathname","unlocalizePathname","localizedHref","prefix"]}
|
package/link.d.ts
CHANGED
package/middleware.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.4-alpha.1",
|
|
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.",
|
|
@@ -10,34 +10,38 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/amannn/next-intl"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsup",
|
|
15
|
-
"test": "TZ=Europe/Berlin vitest",
|
|
16
|
-
"lint": "eslint src test && tsc --noEmit",
|
|
17
|
-
"prepublishOnly": "CI=true turbo test && turbo lint && turbo build && cp ../../README.md .",
|
|
18
|
-
"postpublish": "git checkout . && rm ./README.md"
|
|
19
|
-
},
|
|
20
13
|
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.mjs",
|
|
21
15
|
"typings": "dist/index.d.ts",
|
|
22
16
|
"exports": {
|
|
23
17
|
".": {
|
|
24
18
|
"react-server": {
|
|
19
|
+
"import": "./dist/react-server/index.mjs",
|
|
20
|
+
"node": "./dist/react-server/index.js",
|
|
25
21
|
"default": "./dist/react-server/index.js"
|
|
26
22
|
},
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"node": "./dist/index.js",
|
|
27
25
|
"default": "./dist/index.js"
|
|
28
26
|
},
|
|
29
27
|
"./server": {
|
|
28
|
+
"import": "./dist/server/index.mjs",
|
|
29
|
+
"node": "./dist/server/index.js",
|
|
30
30
|
"default": "./dist/server/index.js"
|
|
31
31
|
},
|
|
32
32
|
"./client": {
|
|
33
|
+
"import": "./dist/client/index.mjs",
|
|
34
|
+
"node": "./dist/client/index.js",
|
|
33
35
|
"default": "./dist/client/index.js"
|
|
34
36
|
},
|
|
35
37
|
"./link": {
|
|
36
|
-
"
|
|
38
|
+
"import": "./dist/link/index.mjs",
|
|
39
|
+
"node": "./dist/link/index.js",
|
|
37
40
|
"default": "./dist/link/index.js"
|
|
38
41
|
},
|
|
39
42
|
"./middleware": {
|
|
40
|
-
"
|
|
43
|
+
"import": "./dist/middleware/index.mjs",
|
|
44
|
+
"node": "./dist/middleware/index.js",
|
|
41
45
|
"default": "./dist/middleware/index.js"
|
|
42
46
|
}
|
|
43
47
|
},
|
|
@@ -65,7 +69,7 @@
|
|
|
65
69
|
"dependencies": {
|
|
66
70
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
67
71
|
"negotiator": "^0.6.3",
|
|
68
|
-
"use-intl": "
|
|
72
|
+
"use-intl": "2.17.4-alpha.1"
|
|
69
73
|
},
|
|
70
74
|
"peerDependencies": {
|
|
71
75
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
@@ -89,5 +93,9 @@
|
|
|
89
93
|
"engines": {
|
|
90
94
|
"node": ">=10"
|
|
91
95
|
},
|
|
92
|
-
"
|
|
93
|
-
|
|
96
|
+
"scripts": {
|
|
97
|
+
"build": "tsup",
|
|
98
|
+
"test": "TZ=Europe/Berlin vitest",
|
|
99
|
+
"lint": "eslint src test && tsc --noEmit"
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/client/useRouter.tsx
CHANGED
|
@@ -30,14 +30,14 @@ export default function useRouter() {
|
|
|
30
30
|
|
|
31
31
|
return {
|
|
32
32
|
...router,
|
|
33
|
-
push(href:
|
|
34
|
-
return router.push(localize(href));
|
|
33
|
+
push(...[href, ...args]: Parameters<typeof router.push>) {
|
|
34
|
+
return router.push(localize(href), ...args);
|
|
35
35
|
},
|
|
36
|
-
replace(href:
|
|
37
|
-
return router.replace(localize(href));
|
|
36
|
+
replace(...[href, ...args]: Parameters<typeof router.replace>) {
|
|
37
|
+
return router.replace(localize(href), ...args);
|
|
38
38
|
},
|
|
39
|
-
prefetch(href:
|
|
40
|
-
return router.prefetch(localize(href));
|
|
39
|
+
prefetch(...[href, ...args]: Parameters<typeof router.prefetch>) {
|
|
40
|
+
return router.prefetch(localize(href), ...args);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
}, [locale, router]);
|