next-intl 3.25.1 → 3.25.2
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/development/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/development/navigation/react-client/createNavigation.js +1 -1
- package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +4 -1
- package/dist/development/navigation/react-client/useBasePathname.js +13 -4
- package/dist/development/shared/utils.js +5 -1
- package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/createNavigation.js +1 -1
- package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/useBasePathname.js +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/createNavigation.js +1 -1
- package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/useBasePathname.js +1 -1
- package/dist/production/shared/utils.js +1 -1
- package/dist/types/src/navigation/react-client/useBasePathname.d.ts +4 -1
- package/dist/types/src/shared/utils.d.ts +1 -0
- package/package.json +3 -3
|
@@ -126,7 +126,7 @@ function createLocalizedPathnamesNavigation(routing) {
|
|
|
126
126
|
}), [baseRouter, defaultLocale]);
|
|
127
127
|
}
|
|
128
128
|
function usePathname() {
|
|
129
|
-
const pathname = useBasePathname.default(config$1
|
|
129
|
+
const pathname = useBasePathname.default(config$1);
|
|
130
130
|
const locale = useTypedLocale();
|
|
131
131
|
|
|
132
132
|
// @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
|
|
@@ -23,7 +23,7 @@ function createNavigation(routing) {
|
|
|
23
23
|
|
|
24
24
|
/** @see https://next-intl-docs.vercel.app/docs/routing/navigation#usepathname */
|
|
25
25
|
function usePathname() {
|
|
26
|
-
const pathname = useBasePathname.default(config
|
|
26
|
+
const pathname = useBasePathname.default(config);
|
|
27
27
|
const locale = useTypedLocale();
|
|
28
28
|
|
|
29
29
|
// @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
|
|
@@ -48,7 +48,10 @@ function createSharedPathnamesNavigation(routing) {
|
|
|
48
48
|
}, ...args);
|
|
49
49
|
}
|
|
50
50
|
function usePathname() {
|
|
51
|
-
const result = useBasePathname.default(
|
|
51
|
+
const result = useBasePathname.default({
|
|
52
|
+
localePrefix,
|
|
53
|
+
defaultLocale: routing === null || routing === void 0 ? void 0 : routing.defaultLocale
|
|
54
|
+
});
|
|
52
55
|
// @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
|
|
53
56
|
return result;
|
|
54
57
|
}
|
|
@@ -7,7 +7,7 @@ var React = require('react');
|
|
|
7
7
|
var useLocale = require('../../react-client/useLocale.js');
|
|
8
8
|
var utils = require('../../shared/utils.js');
|
|
9
9
|
|
|
10
|
-
function useBasePathname(
|
|
10
|
+
function useBasePathname(config) {
|
|
11
11
|
// The types aren't entirely correct here. Outside of Next.js
|
|
12
12
|
// `useParams` can be called, but the return type is `null`.
|
|
13
13
|
|
|
@@ -21,11 +21,20 @@ function useBasePathname(localePrefix) {
|
|
|
21
21
|
const locale = useLocale.default();
|
|
22
22
|
return React.useMemo(() => {
|
|
23
23
|
if (!pathname) return pathname;
|
|
24
|
-
|
|
24
|
+
let unlocalizedPathname = pathname;
|
|
25
|
+
const prefix = utils.getLocalePrefix(locale, config.localePrefix);
|
|
25
26
|
const isPathnamePrefixed = utils.hasPathnamePrefixed(prefix, pathname);
|
|
26
|
-
|
|
27
|
+
if (isPathnamePrefixed) {
|
|
28
|
+
unlocalizedPathname = utils.unprefixPathname(pathname, prefix);
|
|
29
|
+
} else if (config.localePrefix.mode === 'as-needed' && config.defaultLocale === locale && config.localePrefix.prefixes) {
|
|
30
|
+
// Workaround for https://github.com/vercel/next.js/issues/73085
|
|
31
|
+
const localeAsPrefix = utils.getLocaleAsPrefix(locale);
|
|
32
|
+
if (utils.hasPathnamePrefixed(localeAsPrefix, pathname)) {
|
|
33
|
+
unlocalizedPathname = utils.unprefixPathname(pathname, localeAsPrefix);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
return unlocalizedPathname;
|
|
28
|
-
}, [
|
|
37
|
+
}, [config.defaultLocale, config.localePrefix, locale, pathname]);
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
exports.default = useBasePathname;
|
|
@@ -95,7 +95,10 @@ function getLocalePrefix(locale, localePrefix) {
|
|
|
95
95
|
return localePrefix.mode !== 'never' && ((_localePrefix$prefixe = localePrefix.prefixes) === null || _localePrefix$prefixe === void 0 ? void 0 : _localePrefix$prefixe[locale]) ||
|
|
96
96
|
// We return a prefix even if `mode: 'never'`. It's up to the consumer
|
|
97
97
|
// to decide to use it or not.
|
|
98
|
-
|
|
98
|
+
getLocaleAsPrefix(locale);
|
|
99
|
+
}
|
|
100
|
+
function getLocaleAsPrefix(locale) {
|
|
101
|
+
return '/' + locale;
|
|
99
102
|
}
|
|
100
103
|
function templateToRegex(template) {
|
|
101
104
|
const regexPattern = template
|
|
@@ -154,6 +157,7 @@ function getSortedPathnames(pathnames) {
|
|
|
154
157
|
return pathnames.sort(comparePathnamePairs);
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
exports.getLocaleAsPrefix = getLocaleAsPrefix;
|
|
157
161
|
exports.getLocalePrefix = getLocalePrefix;
|
|
158
162
|
exports.getSortedPathnames = getSortedPathnames;
|
|
159
163
|
exports.hasPathnamePrefixed = hasPathnamePrefixed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a,receiveLocaleCookie as l}from"../../routing/config.js";import{getRoute as c,compileLocalizedPathname as i,normalizeNameOrNameWithParams as s}from"../shared/utils.js";import f from"./ClientLink.js";import{clientRedirect as u,clientPermanentRedirect as m}from"./redirects.js";import h from"./useBasePathname.js";import p from"./useBaseRouter.js";function d(d){const v=a(d),P=l(d.localeCookie);function
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a,receiveLocaleCookie as l}from"../../routing/config.js";import{getRoute as c,compileLocalizedPathname as i,normalizeNameOrNameWithParams as s}from"../shared/utils.js";import f from"./ClientLink.js";import{clientRedirect as u,clientPermanentRedirect as m}from"./redirects.js";import h from"./useBasePathname.js";import p from"./useBaseRouter.js";function d(d){const v=a(d),P=l(d.localeCookie);function g(){const e=n();if(!v.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function j(o,t){let{href:n,locale:a,...l}=o;const c=g(),s=a||c;return r.createElement(f,e({ref:t,href:i({locale:s,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:v.pathnames}),locale:a,localeCookie:P,localePrefix:v.localePrefix},l))}const x=o(j);function w(e){let{href:r,locale:o}=e;return i({...s(r),locale:o,pathnames:v.pathnames})}return x.displayName="Link",{Link:x,redirect:function(e){const r=w({href:e,locale:g()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:v.localePrefix},...t)},permanentRedirect:function(e){const r=w({href:e,locale:g()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return m({pathname:r,localePrefix:v.localePrefix},...t)},usePathname:function(){const e=h(v),r=g();return t((()=>e?c(r,e,v.pathnames):e),[r,e])},useRouter:function(){const e=p(v.localePrefix,P),r=g();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:w}}export{d as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as o}from"react";import n from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as
|
|
1
|
+
import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as o}from"react";import n from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as s}from"../shared/utils.js";import c from"./useBasePathname.js";function i(i){function u(){return n()}const{Link:m,config:f,getPathname:h,...p}=r(u,i);return{...p,Link:m,usePathname:function(){const e=c(f),t=u();return o((()=>e&&f.pathnames?s(t,e,f.pathnames):e),[t,e])},useRouter:function(){const n=e(),r=u(),s=t();return o((()=>{function e(e){return function(t,o){const{locale:n,...c}=o||{},i=[h({href:t,locale:n||r,domain:window.location.host})];Object.keys(c).length>0&&i.push(c),e(...i),a(f.localeCookie,s,r,n)}}return{...n,push:e(n.push),replace:e(n.replace),prefetch:e(n.prefetch)}}),[r,s,n])},getPathname:h}}export{i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import{receiveLocalePrefixConfig as t,receiveLocaleCookie as n}from"../../routing/config.js";import
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import{receiveLocalePrefixConfig as t,receiveLocaleCookie as n}from"../../routing/config.js";import l from"./ClientLink.js";import{clientRedirect as a,clientPermanentRedirect as i}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function c(c){const m=t(null==c?void 0:c.localePrefix),s=n(null==c?void 0:c.localeCookie);function p(o,t){return r.createElement(l,e({ref:t,localeCookie:s,localePrefix:m},o))}const d=o(p);return d.displayName="Link",{Link:d,redirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return a({pathname:e,localePrefix:m},...o)},permanentRedirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return i({pathname:e,localePrefix:m},...o)},usePathname:function(){return u({localePrefix:m,defaultLocale:null==c?void 0:c.defaultLocale})},useRouter:function(){return f(m,s)}}}export{c as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{usePathname as
|
|
1
|
+
import{usePathname as e}from"next/navigation";import{useMemo as r}from"react";import o from"../../react-client/useLocale.js";import{hasPathnamePrefixed as t,unprefixPathname as l,getLocalePrefix as a,getLocaleAsPrefix as i}from"../../shared/utils.js";function f(f){const c=e(),n=o();return r((()=>{if(!c)return c;let e=c;const r=a(n,f.localePrefix);if(t(r,c))e=l(c,r);else if("as-needed"===f.localePrefix.mode&&f.defaultLocale===n&&f.localePrefix.prefixes){const r=i(n);t(r,c)&&(e=l(c,r))}return e}),[f.defaultLocale,f.localePrefix,n,c])}export{f as default};
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,c=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(o,c);return(f||l)&&null!=o?e(t,o):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function c(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(n){return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function o(n,t){const e=c(n),r=c(t);return
|
|
1
|
+
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,c=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(o,c);return(f||l)&&null!=o?e(t,o):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function c(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(n){return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function o(n,t){const e=c(n),r=c(t);return s(e).test(r)}function f(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||l(n)}function l(n){return"/"+n}function s(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function a(n){return n.includes("[[...")}function p(n){return n.includes("[...")}function h(n){return n.includes("[")}function g(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!h(t)&&h(u))return-1;if(h(t)&&!h(u))return 1;if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1}}return 0}function d(n){return n.sort(g)}export{l as getLocaleAsPrefix,f as getLocalePrefix,d as getSortedPathnames,i as hasPathnamePrefixed,n as isLocalizableHref,t as localizeHref,o as matchesPathname,c as normalizeTrailingSlash,e as prefixHref,u as prefixPathname,s as templateToRegex,r as unprefixPathname};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../../routing/config.js"),l=require("../shared/utils.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../../routing/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveRoutingConfig(u),h=t.receiveLocaleCookie(u.localeCookie);function d(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function m(r,a){let{href:t,locale:o,...c}=r;const i=d(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localeCookie:h,localePrefix:f.localePrefix},c))}const p=r.forwardRef(m);function v(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=v({href:e,locale:d()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=v({href:e,locale:d()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f),a=d();return r.useMemo((()=>e?l.getRoute(a,e,f.pathnames):e),[a,e])},useRouter:function(){const e=i.default(f.localePrefix,h),a=d();return r.useMemo((()=>({...e,push(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.push(c,...n)},replace(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.replace(c,...n)},prefetch(r){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.prefetch(c,...n)}})),[e,a])},getPathname:v}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),r=require("../../react-client/useLocale.js"),n=require("../shared/createSharedNavigationFns.js"),a=require("../shared/syncLocaleCookie.js"),u=require("../shared/utils.js"),o=require("./useBasePathname.js");exports.default=function(s){function c(){return r.default()}const{Link:i,config:l,getPathname:h,...f}=n.default(c,s);return{...f,Link:i,usePathname:function(){const e=o.default(l
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),r=require("../../react-client/useLocale.js"),n=require("../shared/createSharedNavigationFns.js"),a=require("../shared/syncLocaleCookie.js"),u=require("../shared/utils.js"),o=require("./useBasePathname.js");exports.default=function(s){function c(){return r.default()}const{Link:i,config:l,getPathname:h,...f}=n.default(c,s);return{...f,Link:i,usePathname:function(){const e=o.default(l),r=c();return t.useMemo((()=>e&&l.pathnames?u.getRoute(r,e,l.pathnames):e),[r,e])},useRouter:function(){const r=e.useRouter(),n=c(),u=e.usePathname();return t.useMemo((()=>{function e(e){return function(t,r){const{locale:o,...s}=r||{},c=[h({href:t,locale:o||n,domain:window.location.host})];Object.keys(s).length>0&&c.push(s),e(...c),a.default(l.localeCookie,u,n,o)}}return{...r,push:e(r.push),replace:e(r.replace),prefetch:e(r.prefetch)}}),[n,u,r])},getPathname:h}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ClientLink.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ClientLink.js"),l=require("./redirects.js"),i=require("./useBasePathname.js"),u=require("./useBaseRouter.js");function a(e){return e&&e.__esModule?e:{default:e}}var o=a(r);exports.default=function(a){const c=t.receiveLocalePrefixConfig(null==a?void 0:a.localePrefix),f=t.receiveLocaleCookie(null==a?void 0:a.localeCookie);function s(r,t){return o.default.createElement(n.default,e.extends({ref:t,localeCookie:f,localePrefix:c},r))}const d=r.forwardRef(s);return d.displayName="Link",{Link:d,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return l.clientRedirect({pathname:e,localePrefix:c},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return l.clientPermanentRedirect({pathname:e,localePrefix:c},...t)},usePathname:function(){return i.default({localePrefix:c,defaultLocale:null==a?void 0:a.defaultLocale})},useRouter:function(){return u.default(c,f)}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../../shared/utils.js");exports.default=function(i){const l=e.usePathname(),n=a.default();return r.useMemo((()=>{if(!l)return l;let e=l;const r=t.getLocalePrefix(n,i.localePrefix);if(t.hasPathnamePrefixed(r,l))e=t.unprefixPathname(l,r);else if("as-needed"===i.localePrefix.mode&&i.defaultLocale===n&&i.localePrefix.prefixes){const r=t.getLocaleAsPrefix(n);t.hasPathnamePrefixed(r,l)&&(e=t.unprefixPathname(l,r))}return e}),[i.defaultLocale,i.localePrefix,n,l])};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t){return function(t){return"object"==typeof t?null==t.host&&null==t.hostname:!/^[a-z]+:/i.test(t)}(t)&&!function(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}(t)}function e(t,e){let r;return"string"==typeof t?r=n(e,t):(r={...t},t.pathname&&(r.pathname=n(e,t.pathname))),r}function n(t,e){let n=t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function r(t,e){return e===t||e.startsWith("".concat(t,"/"))}function o(t){const e=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(t){return!1}}();if("/"!==t){const n=t.endsWith("/");e&&!n?t+="/":!e&&n&&(t=t.slice(0,-1))}return t}function i(t){const e=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(e,"$"))}function
|
|
1
|
+
"use strict";function t(t){return function(t){return"object"==typeof t?null==t.host&&null==t.hostname:!/^[a-z]+:/i.test(t)}(t)&&!function(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}(t)}function e(t,e){let r;return"string"==typeof t?r=n(e,t):(r={...t},t.pathname&&(r.pathname=n(e,t.pathname))),r}function n(t,e){let n=t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function r(t,e){return e===t||e.startsWith("".concat(t,"/"))}function o(t){const e=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(t){return!1}}();if("/"!==t){const n=t.endsWith("/");e&&!n?t+="/":!e&&n&&(t=t.slice(0,-1))}return t}function i(t){return"/"+t}function u(t){const e=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(e,"$"))}function c(t){return t.includes("[[...")}function s(t){return t.includes("[...")}function a(t){return t.includes("[")}function f(t,e){const n=t.split("/"),r=e.split("/"),o=Math.max(n.length,r.length);for(let t=0;t<o;t++){const e=n[t],o=r[t];if(!e&&o)return-1;if(e&&!o)return 1;if(e||o){if(!a(e)&&a(o))return-1;if(a(e)&&!a(o))return 1;if(!s(e)&&s(o))return-1;if(s(e)&&!s(o))return 1;if(!c(e)&&c(o))return-1;if(c(e)&&!c(o))return 1}}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocaleAsPrefix=i,exports.getLocalePrefix=function(t,e){var n;return"never"!==e.mode&&(null===(n=e.prefixes)||void 0===n?void 0:n[t])||i(t)},exports.getSortedPathnames=function(t){return t.sort(f)},exports.hasPathnamePrefixed=r,exports.isLocalizableHref=t,exports.localizeHref=function(n,o){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,u=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!t(n))return n;const s=o!==i,a=r(c,u);return(s||a)&&null!=c?e(n,c):n},exports.matchesPathname=function(t,e){const n=o(t),r=o(e);return u(n).test(r)},exports.normalizeTrailingSlash=o,exports.prefixHref=e,exports.prefixPathname=n,exports.templateToRegex=u,exports.unprefixPathname=function(t,e){return t.replace(new RegExp("^".concat(e)),"")||"/"};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { LocalePrefixConfigVerbose, LocalePrefixMode, Locales } from '../../routing/types';
|
|
2
|
-
export default function useBasePathname<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(
|
|
2
|
+
export default function useBasePathname<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(config: {
|
|
3
|
+
localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>;
|
|
4
|
+
defaultLocale?: AppLocales[number];
|
|
5
|
+
}): string | null;
|
|
@@ -18,6 +18,7 @@ template: string,
|
|
|
18
18
|
/** E.g. `/users/23-jane` */
|
|
19
19
|
pathname: string): boolean;
|
|
20
20
|
export declare function getLocalePrefix<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>): string;
|
|
21
|
+
export declare function getLocaleAsPrefix(locale: string): string;
|
|
21
22
|
export declare function templateToRegex(template: string): RegExp;
|
|
22
23
|
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
23
24
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.25.
|
|
3
|
+
"version": "3.25.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -88,11 +88,11 @@
|
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@formatjs/intl-localematcher": "^0.5.4",
|
|
90
90
|
"negotiator": "^1.0.0",
|
|
91
|
-
"use-intl": "^3.25.
|
|
91
|
+
"use-intl": "^3.25.2"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
|
|
95
95
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "cdcff43e0a606bc9990623d819de9c37fea895a4"
|
|
98
98
|
}
|