next-intl 3.11.1 → 3.11.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.
@@ -109,3 +109,4 @@ function resolveLocale(config, requestHeaders, requestCookies, pathname) {
109
109
  }
110
110
 
111
111
  exports.default = resolveLocale;
112
+ exports.getAcceptLanguageLocale = getAcceptLanguageLocale;
@@ -104,7 +104,12 @@ function getRoute(_ref3) {
104
104
  return template;
105
105
  }
106
106
  function getBasePath(pathname) {
107
- return window.location.pathname.replace(pathname, '');
107
+ let windowPathname = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.pathname;
108
+ if (pathname === '/') {
109
+ return windowPathname;
110
+ } else {
111
+ return windowPathname.replace(pathname, '');
112
+ }
108
113
  }
109
114
 
110
115
  exports.compileLocalizedPathname = compileLocalizedPathname;
@@ -1 +1 @@
1
- import{match as t}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as e}from"../shared/constants.js";import{getFirstPathnameSegment as n,findCaseInsensitiveLocale as a,isLocaleSupportedOnDomain as l,getHost as c}from"./utils.js";function r(l,c,r,i){let s,{defaultLocale:u,localeDetection:f,locales:d}=l;if(i){const t=n(i),o=a(t,d);o&&(s=o)}if(!s&&f&&r&&r.has(e)){var m;const t=null===(m=r.get(e))||void 0===m?void 0:m.value;t&&d.includes(t)&&(s=t)}return!s&&f&&c&&(s=function(e,n,a){let l;const c=new o({headers:{"accept-language":e.get("accept-language")||void 0}}).languages();try{l=t(c,n,a)}catch(t){}return l}(c,d,u)),s||(s=u),s}function i(t,o,e,n){const{domains:a}=t,i=r(t,o,e,n);if(a){const t=function(t,o){var e;let n=c(t);if(n=null===(e=n)||void 0===e?void 0:e.replace(/:\d+$/,""),n&&o)return o.find((t=>t.domain===n))}(o,a),e=n&&n.startsWith("/".concat(i));if(t)return{locale:l(i,t)||e?i:t.defaultLocale,domain:t}}return{locale:i}}function s(t,o,e,n){return t.domains?i(t,o,e,n):{locale:r(t,o,e,n)}}export{s as default};
1
+ import{match as t}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as e}from"../shared/constants.js";import{getFirstPathnameSegment as n,findCaseInsensitiveLocale as a,isLocaleSupportedOnDomain as l,getHost as c}from"./utils.js";function r(e,n,a){let l;const c=new o({headers:{"accept-language":e.get("accept-language")||void 0}}).languages();try{l=t(c,n,a)}catch(t){}return l}function i(t,o,l,c){let i,{defaultLocale:s,localeDetection:u,locales:f}=t;if(c){const t=n(c),o=a(t,f);o&&(i=o)}if(!i&&u&&l&&l.has(e)){var d;const t=null===(d=l.get(e))||void 0===d?void 0:d.value;t&&f.includes(t)&&(i=t)}return!i&&u&&o&&(i=r(o,f,s)),i||(i=s),i}function s(t,o,e,n){const{domains:a}=t,r=i(t,o,e,n);if(a){const t=function(t,o){var e;let n=c(t);if(n=null===(e=n)||void 0===e?void 0:e.replace(/:\d+$/,""),n&&o)return o.find((t=>t.domain===n))}(o,a),e=n&&n.startsWith("/".concat(r));if(t)return{locale:l(r,t)||e?r:t.defaultLocale,domain:t}}return{locale:r}}function u(t,o,e,n){return t.domains?s(t,o,e,n):{locale:i(t,o,e,n)}}export{u as default,r as getAcceptLanguageLocale};
@@ -1 +1 @@
1
- import{unlocalizePathname as t,matchesPathname as n}from"../../shared/utils.js";function e(t){return"string"==typeof t?{pathname:t}:t}function r(t){function n(t){return String(t)}const e=new URLSearchParams;for(const[r,a]of Object.entries(t))Array.isArray(a)?a.forEach((t=>{e.append(r,n(t))})):e.set(r,n(a));return"?"+e.toString()}function a(t){let{pathname:n,locale:e,params:a,pathnames:o,query:c}=t;function i(t){let n=o[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[e];let o=n;if(a&&Object.entries(a).forEach((t=>{let[n,e]=t;o=Array.isArray(e)?o.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),e.map((t=>String(t))).join("/")):o.replace("[".concat(n,"]"),String(e))})),o.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(a)));return c&&(o+=r(c)),o}if("string"==typeof n){return s(i(n))}{const{pathname:t,...e}=n;return{...e,pathname:s(i(t))}}}function o(e){var r;let{locale:a,pathname:o,pathnames:c}=e;const i=t(decodeURI(o),a);let s=null===(r=Object.entries(c).find((t=>{let[,e]=t;const r="string"!=typeof e?e[a]:e;return n(r,i)})))||void 0===r?void 0:r[0];return s||(s=o),s}function c(t){return window.location.pathname.replace(t,"")}export{a as compileLocalizedPathname,c as getBasePath,o as getRoute,e as normalizeNameOrNameWithParams,r as serializeSearchParams};
1
+ import{unlocalizePathname as t,matchesPathname as n}from"../../shared/utils.js";function e(t){return"string"==typeof t?{pathname:t}:t}function r(t){function n(t){return String(t)}const e=new URLSearchParams;for(const[r,a]of Object.entries(t))Array.isArray(a)?a.forEach((t=>{e.append(r,n(t))})):e.set(r,n(a));return"?"+e.toString()}function a(t){let{pathname:n,locale:e,params:a,pathnames:o,query:i}=t;function c(t){let n=o[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[e];let o=n;if(a&&Object.entries(a).forEach((t=>{let[n,e]=t;o=Array.isArray(e)?o.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),e.map((t=>String(t))).join("/")):o.replace("[".concat(n,"]"),String(e))})),o.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(a)));return i&&(o+=r(i)),o}if("string"==typeof n){return s(c(n))}{const{pathname:t,...e}=n;return{...e,pathname:s(c(t))}}}function o(e){var r;let{locale:a,pathname:o,pathnames:i}=e;const c=t(decodeURI(o),a);let s=null===(r=Object.entries(i).find((t=>{let[,e]=t;const r="string"!=typeof e?e[a]:e;return n(r,c)})))||void 0===r?void 0:r[0];return s||(s=o),s}function i(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===t?n:n.replace(t,"")}export{a as compileLocalizedPathname,i as getBasePath,o as getRoute,e as normalizeNameOrNameWithParams,r as serializeSearchParams};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),n=require("../shared/constants.js"),a=require("./utils.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(t);function i(t,o,i,l){let c,{defaultLocale:u,localeDetection:s,locales:d}=t;if(l){const e=a.getFirstPathnameSegment(l),t=a.findCaseInsensitiveLocale(e,d);t&&(c=t)}if(!c&&s&&i&&i.has(n.COOKIE_LOCALE_NAME)){var f;const e=null===(f=i.get(n.COOKIE_LOCALE_NAME))||void 0===f?void 0:f.value;e&&d.includes(e)&&(c=e)}return!c&&s&&o&&(c=function(t,n,a){let o;const i=new r.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{o=e.match(i,n,a)}catch(e){}return o}(o,d,u)),c||(c=u),c}function l(e,t,n,o){const{domains:r}=e,l=i(e,t,n,o);if(r){const e=function(e,t){var n;let o=a.getHost(e);if(o=null===(n=o)||void 0===n?void 0:n.replace(/:\d+$/,""),o&&t)return t.find((e=>e.domain===o))}(t,r),n=o&&o.startsWith("/".concat(l));if(e)return{locale:a.isLocaleSupportedOnDomain(l,e)||n?l:e.defaultLocale,domain:e}}return{locale:l}}exports.default=function(e,t,n,a){return e.domains?l(e,t,n,a):{locale:i(e,t,n,a)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),a=require("../shared/constants.js"),n=require("./utils.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(t);function c(t,a,n){let o;const c=new r.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{o=e.match(c,a,n)}catch(e){}return o}function l(e,t,o,r){let l,{defaultLocale:i,localeDetection:u,locales:s}=e;if(r){const e=n.getFirstPathnameSegment(r),t=n.findCaseInsensitiveLocale(e,s);t&&(l=t)}if(!l&&u&&o&&o.has(a.COOKIE_LOCALE_NAME)){var d;const e=null===(d=o.get(a.COOKIE_LOCALE_NAME))||void 0===d?void 0:d.value;e&&s.includes(e)&&(l=e)}return!l&&u&&t&&(l=c(t,s,i)),l||(l=i),l}function i(e,t,a,o){const{domains:r}=e,c=l(e,t,a,o);if(r){const e=function(e,t){var a;let o=n.getHost(e);if(o=null===(a=o)||void 0===a?void 0:a.replace(/:\d+$/,""),o&&t)return t.find((e=>e.domain===o))}(t,r),a=o&&o.startsWith("/".concat(c));if(e)return{locale:n.isLocaleSupportedOnDomain(c,e)||a?c:e.defaultLocale,domain:e}}return{locale:c}}exports.default=function(e,t,a,n){return e.domains?i(e,t,a,n):{locale:l(e,t,a,n)}},exports.getAcceptLanguageLocale=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:i}=e;function c(e){let t=o[e];return t||(t=e),t}function s(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),i&&(r+=t(i)),r}if("string"==typeof r){return s(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:s(c(e))}}},exports.getBasePath=function(e){return window.location.pathname.replace(e,"")},exports.getRoute=function(t){var r;let{locale:n,pathname:a,pathnames:o}=t;const i=e.unlocalizePathname(decodeURI(a),n);let c=null===(r=Object.entries(o).find((t=>{let[,r]=t;const a="string"!=typeof r?r[n]:r;return e.matchesPathname(a,i)})))||void 0===r?void 0:r[0];return c||(c=a),c},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:i}=e;function c(e){let t=o[e];return t||(t=e),t}function s(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),i&&(r+=t(i)),r}if("string"==typeof r){return s(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:s(c(e))}}},exports.getBasePath=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===e?t:t.replace(e,"")},exports.getRoute=function(t){var r;let{locale:n,pathname:a,pathnames:o}=t;const i=e.unlocalizePathname(decodeURI(a),n);let c=null===(r=Object.entries(o).find((t=>{let[,r]=t;const a="string"!=typeof r?r[n]:r;return e.matchesPathname(a,i)})))||void 0===r?void 0:r[0];return c||(c=a),c},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
@@ -1,6 +1,7 @@
1
1
  import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
2
  import { AllLocales } from '../shared/types';
3
3
  import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
4
+ export declare function getAcceptLanguageLocale<Locales extends AllLocales>(requestHeaders: Headers, locales: Locales, defaultLocale: string): string | undefined;
4
5
  export default function resolveLocale<Locales extends AllLocales>(config: MiddlewareConfigWithDefaults<Locales>, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
5
6
  locale: Locales[number];
6
7
  domain?: DomainConfig<Locales>;
@@ -48,5 +48,5 @@ export declare function getRoute<Locales extends AllLocales>({ locale, pathname,
48
48
  pathname: string;
49
49
  pathnames: Pathnames<Locales>;
50
50
  }): string;
51
- export declare function getBasePath(pathname: string): string;
51
+ export declare function getBasePath(pathname: string, windowPathname?: string): string;
52
52
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.11.1",
3
+ "version": "3.11.2",
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.11.1"
85
+ "use-intl": "^3.11.2"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -122,11 +122,11 @@
122
122
  },
123
123
  {
124
124
  "path": "dist/production/navigation.react-client.js",
125
- "limit": "2.94 KB"
125
+ "limit": "2.96 KB"
126
126
  },
127
127
  {
128
128
  "path": "dist/production/navigation.react-server.js",
129
- "limit": "3.03 KB"
129
+ "limit": "3.06 KB"
130
130
  },
131
131
  {
132
132
  "path": "dist/production/server.react-client.js",
@@ -141,5 +141,5 @@
141
141
  "limit": "5.95 KB"
142
142
  }
143
143
  ],
144
- "gitHead": "78f88d1493eb796498b7fb2c986536ac49cffda0"
144
+ "gitHead": "672eccf549b25116a161f21ebad075fe4ae81bc8"
145
145
  }