next-intl 3.9.2 → 3.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,8 +28,8 @@ function BaseLink(_ref, ref) {
28
28
  // The types aren't entirely correct here. Outside of Next.js
29
29
  // `useParams` can be called, but the return type is `null`.
30
30
  const pathname = navigation.usePathname();
31
- const defaultLocale = useLocale.default();
32
- const isChangingLocale = locale !== defaultLocale;
31
+ const curLocale = useLocale.default();
32
+ const isChangingLocale = locale !== curLocale;
33
33
  const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) && (localePrefix !== 'never' || isChangingLocale) ?
34
34
  // For the `localePrefix: 'as-needed' strategy, the href shouldn't
35
35
  // be prefixed if the locale is the default locale. To determine this, we
@@ -43,13 +43,13 @@ function BaseLink(_ref, ref) {
43
43
  // determined in the effect below.
44
44
  utils.prefixHref(href, locale) : href);
45
45
  function onLinkClick(event) {
46
- syncLocaleCookie.default(pathname, defaultLocale, locale);
46
+ syncLocaleCookie.default(pathname, curLocale, locale);
47
47
  if (onClick) onClick(event);
48
48
  }
49
49
  React.useEffect(() => {
50
- if (!pathname || localePrefix === 'never') return;
51
- setLocalizedHref(utils.localizeHref(href, locale, defaultLocale, pathname !== null && pathname !== void 0 ? pathname : undefined));
52
- }, [defaultLocale, href, locale, localePrefix, pathname]);
50
+ if (!pathname) return;
51
+ setLocalizedHref(utils.localizeHref(href, locale, curLocale, pathname));
52
+ }, [curLocale, href, locale, pathname]);
53
53
  if (isChangingLocale) {
54
54
  if (prefetch && "development" !== 'production') {
55
55
  console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
@@ -66,13 +66,13 @@ pathname) {
66
66
  return regex.test(pathname);
67
67
  }
68
68
  function templateToRegex(template) {
69
- const regexPattern = template.replace(/\[([^\]]+)\]/g, match => {
70
- if (match.startsWith('[...')) return '(.*)';
71
- if (match.startsWith('[[...')) return '(.*)';
72
- return '([^/]+)';
73
- })
74
- // Clean up regex match remainders from optional catchall ('[[...slug]]')
75
- .replaceAll('(.*)]', '(.*)');
69
+ const regexPattern = template
70
+ // Replace optional catchall ('[[...slug]]')
71
+ .replaceAll(/\[\[(\.\.\.[^\]]+)\]\]/g, '?(.*)')
72
+ // Replace catchall ('[...slug]')
73
+ .replaceAll(/\[(\.\.\.[^\]]+)\]/g, '(.+)')
74
+ // Replace regular parameter ('[slug]')
75
+ .replaceAll(/\[([^\]]+)\]/g, '([^/]+)');
76
76
  return new RegExp("^".concat(regexPattern, "$"));
77
77
  }
78
78
 
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as o}from"next/navigation";import t,{forwardRef as n,useState as l,useEffect as i}from"react";import c from"../../react-client/useLocale.js";import{isLocalHref as a,prefixHref as p,localizeHref as s}from"../../shared/utils.js";import f from"./syncLocaleCookie.js";function m(n,m){let{href:u,locale:h,localePrefix:d,onClick:v,prefetch:k,...x}=n;const L=o(),g=c(),j=h!==g,[C,y]=l((()=>a(u)&&("never"!==d||j)?p(u,h):u));return i((()=>{L&&"never"!==d&&y(s(u,h,g,null!=L?L:void 0))}),[g,u,h,d,L]),j&&(k&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),k=!1),t.createElement(r,e({ref:m,href:C,hrefLang:j?h:void 0,onClick:function(e){f(L,g,h),v&&v(e)},prefetch:k},x))}const u=n(m);u.displayName="ClientLink";var h=u;export{h as default};
2
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as o}from"next/navigation";import t,{forwardRef as n,useState as i,useEffect as l}from"react";import c from"../../react-client/useLocale.js";import{isLocalHref as a,prefixHref as p,localizeHref as s}from"../../shared/utils.js";import f from"./syncLocaleCookie.js";function m(n,m){let{href:h,locale:u,localePrefix:d,onClick:k,prefetch:v,...x}=n;const L=o(),g=c(),j=u!==g,[C,y]=i((()=>a(h)&&("never"!==d||j)?p(h,u):h));return l((()=>{L&&y(s(h,u,g,L))}),[g,h,u,L]),j&&(v&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),v=!1),t.createElement(r,e({ref:m,href:C,hrefLang:j?u:void 0,onClick:function(e){f(L,g,u),k&&k(e)},prefetch:v},x))}const h=n(m);h.displayName="ClientLink";var u=h;export{u as default};
@@ -1 +1 @@
1
- function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o,i=null==c||u(c,a);return(l||i)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function u(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function a(t,n){return l(t).test(n)}function l(t){const n=t.replace(/\[([^\]]+)\]/g,(t=>t.startsWith("[...")||t.startsWith("[[...")?"(.*)":"([^/]+)")).replaceAll("(.*)]","(.*)");return new RegExp("^".concat(n,"$"))}export{u as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,a as matchesPathname,r as prefixHref,o as prefixPathname,l as templateToRegex,c as unlocalizePathname};
1
+ function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,u=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const a=c!==o,i=null==c||l(c,u);return(a||i)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function l(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function u(t,n){return a(t).test(n)}function a(t){const n=t.replaceAll(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replaceAll(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replaceAll(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(n,"$"))}export{l as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,u as matchesPathname,r as prefixHref,o as prefixPathname,a as templateToRegex,c as unlocalizePathname};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("next/link"),t=require("next/navigation"),l=require("react"),a=require("../../react-client/useLocale.js"),i=require("../../shared/utils.js"),u=require("./syncLocaleCookie.js");function n(e){return e&&e.__esModule?e:{default:e}}var f=n(r),o=n(l);function c(r,n){let{href:c,locale:s,localePrefix:d,onClick:v,prefetch:p,...h}=r;const q=t.usePathname(),x=a.default(),_=s!==x,[j,k]=l.useState((()=>i.isLocalHref(c)&&("never"!==d||_)?i.prefixHref(c,s):c));return l.useEffect((()=>{q&&"never"!==d&&k(i.localizeHref(c,s,x,null!=q?q:void 0))}),[x,c,s,d,q]),_&&(p=!1),o.default.createElement(f.default,e.extends({ref:n,href:j,hrefLang:_?s:void 0,onClick:function(e){u.default(q,x,s),v&&v(e)},prefetch:p},h))}const s=l.forwardRef(c);s.displayName="ClientLink";var d=s;exports.default=d;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("next/link"),t=require("next/navigation"),l=require("react"),a=require("../../react-client/useLocale.js"),i=require("../../shared/utils.js"),u=require("./syncLocaleCookie.js");function n(e){return e&&e.__esModule?e:{default:e}}var f=n(r),o=n(l);function c(r,n){let{href:c,locale:s,localePrefix:d,onClick:p,prefetch:v,...h}=r;const q=t.usePathname(),x=a.default(),_=s!==x,[j,k]=l.useState((()=>i.isLocalHref(c)&&("never"!==d||_)?i.prefixHref(c,s):c));return l.useEffect((()=>{q&&k(i.localizeHref(c,s,x,q))}),[x,c,s,q]),_&&(v=!1),o.default.createElement(f.default,e.extends({ref:n,href:j,hrefLang:_?s:void 0,onClick:function(e){u.default(q,x,s),p&&p(e)},prefetch:v},h))}const s=l.forwardRef(c);s.displayName="ClientLink";var d=s;exports.default=d;
@@ -1 +1 @@
1
- "use strict";function t(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}function e(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function n(t,e){let n;return"string"==typeof t?n=r(e,t):(n={...t},t.pathname&&(n.pathname=r(e,t.pathname))),n}function r(t,e){let n="/"+t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function o(t,e){const n="/".concat(t);return e===n||e.startsWith("".concat(n,"/"))}function a(t){const e=t.replace(/\[([^\]]+)\]/g,(t=>t.startsWith("[...")||t.startsWith("[[...")?"(.*)":"([^/]+)")).replaceAll("(.*)]","(.*)");return new RegExp("^".concat(e,"$"))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasPathnamePrefixed=o,exports.isLocalHref=e,exports.isRelativeHref=t,exports.localizeHref=function(r,a){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a,c=arguments.length>3?arguments[3]:void 0;if(!e(r)||t(r))return r;const i=a!==s,l=null==a||o(a,c);return(i||l)&&null!=a?n(r,a):r},exports.matchesPathname=function(t,e){return a(t).test(e)},exports.prefixHref=n,exports.prefixPathname=r,exports.templateToRegex=a,exports.unlocalizePathname=function(t,e){return t.replace(new RegExp("^/".concat(e)),"")||"/"};
1
+ "use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(e,t){let n;return"string"==typeof e?n=r(t,e):(n={...e},e.pathname&&(n.pathname=r(t,e.pathname))),n}function r(e,t){let n="/"+e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function o(e,t){const n="/".concat(e);return t===n||t.startsWith("".concat(n,"/"))}function a(e){const t=e.replaceAll(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replaceAll(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replaceAll(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasPathnamePrefixed=o,exports.isLocalHref=t,exports.isRelativeHref=e,exports.localizeHref=function(r,a){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a,c=arguments.length>3?arguments[3]:void 0;if(!t(r)||e(r))return r;const s=a!==l,u=null==a||o(a,c);return(s||u)&&null!=a?n(r,a):r},exports.matchesPathname=function(e,t){return a(e).test(t)},exports.prefixHref=n,exports.prefixPathname=r,exports.templateToRegex=a,exports.unlocalizePathname=function(e,t){return e.replace(new RegExp("^/".concat(t)),"")||"/"};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.9.2",
3
+ "version": "3.9.4",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -82,7 +82,7 @@
82
82
  "dependencies": {
83
83
  "@formatjs/intl-localematcher": "^0.2.32",
84
84
  "negotiator": "^0.6.3",
85
- "use-intl": "^3.9.2"
85
+ "use-intl": "^3.9.4"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -141,5 +141,5 @@
141
141
  "limit": "5.855 KB"
142
142
  }
143
143
  ],
144
- "gitHead": "2a6199609c0a77f897d994c8d52796f5615bcfff"
144
+ "gitHead": "18031134e28cbef05ad4477b0639809c739ae457"
145
145
  }