next-intl 3.17.3 → 3.17.5

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.
@@ -22,6 +22,10 @@ function findDomainFromHost(requestHeaders, domains) {
22
22
  }
23
23
  return undefined;
24
24
  }
25
+ function orderLocales(locales) {
26
+ // Workaround for https://github.com/formatjs/formatjs/issues/4469
27
+ return locales.slice().sort((a, b) => b.length - a.length);
28
+ }
25
29
  function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
26
30
  let locale;
27
31
  const languages = new Negotiator__default.default({
@@ -30,7 +34,8 @@ function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
30
34
  }
31
35
  }).languages();
32
36
  try {
33
- locale = intlLocalematcher.match(languages, locales, defaultLocale);
37
+ const orderedLocales = orderLocales(locales);
38
+ locale = intlLocalematcher.match(languages, orderedLocales, defaultLocale);
34
39
  } catch (e) {
35
40
  // Invalid language
36
41
  }
@@ -50,12 +50,13 @@ async function receiveRuntimeConfigImpl(getConfig, localeOverride) {
50
50
  };
51
51
  }
52
52
  const receiveRuntimeConfig = React.cache(receiveRuntimeConfigImpl);
53
- const getFormatters = React.cache(core._createFormatters);
53
+ const getFormatters = React.cache(core._createIntlFormatters);
54
+ const getCache = React.cache(core._createCache);
54
55
  async function getConfigImpl(localeOverride) {
55
56
  const runtimeConfig = await receiveRuntimeConfig(getRuntimeConfig__default.default, localeOverride);
56
57
  return {
57
58
  ...core.initializeConfig(runtimeConfig),
58
- _formatters: getFormatters()
59
+ _formatters: getFormatters(getCache())
59
60
  };
60
61
  }
61
62
  const getConfig = React.cache(getConfigImpl);
@@ -1 +1 @@
1
- import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as l}from"../shared/constants.js";import{getPathnameMatch as t,isLocaleSupportedOnDomain as a,getHost as n}from"./utils.js";function c(l,t,a){let n;const c=new o({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{n=e(c,t,a)}catch(e){}return n}function i(e,o){if(e.has(l)){var t;const a=null===(t=e.get(l))||void 0===t?void 0:t.value;if(a&&o.includes(a))return a}}function r(e,o,l,a){let n,{defaultLocale:r,localeDetection:u,localePrefix:f,locales:s}=e;var d;a&&(n=null===(d=t(a,s,f))||void 0===d?void 0:d.locale);return!n&&u&&l&&(n=i(l,s)),!n&&u&&o&&(n=c(o,s,r)),n||(n=r),n}function u(e,o,l,u){const f=function(e,o){var l;let t=n(e);if(t=null===(l=t)||void 0===l?void 0:l.replace(/:\d+$/,""),t&&o)return o.find((e=>e.domain===t))}(o,e.domains);if(!f)return{locale:r(e,o,l,u)};let s;if(u){var d;const o=null===(d=t(u,e.locales,e.localePrefix))||void 0===d?void 0:d.locale;if(o){if(!a(o,f))return{locale:o,domain:f};s=o}}if(!s&&e.localeDetection&&l){const o=i(l,e.locales);o&&a(o,f)&&(s=o)}if(!s&&e.localeDetection&&o){const l=c(o,f.locales||e.locales,f.defaultLocale);l&&(s=l)}return s||(s=f.defaultLocale),{locale:s,domain:f}}function f(e,o,l,t){return e.domains?u(e,o,l,t):{locale:r(e,o,l,t)}}export{f as default,c as getAcceptLanguageLocale};
1
+ import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as l}from"../shared/constants.js";import{getPathnameMatch as t,isLocaleSupportedOnDomain as n,getHost as a}from"./utils.js";function c(l,t,n){let a;const c=new o({headers:{"accept-language":l.get("accept-language")||void 0}}).languages();try{const o=function(e){return e.slice().sort(((e,o)=>o.length-e.length))}(t);a=e(c,o,n)}catch(e){}return a}function i(e,o){if(e.has(l)){var t;const n=null===(t=e.get(l))||void 0===t?void 0:t.value;if(n&&o.includes(n))return n}}function r(e,o,l,n){let a,{defaultLocale:r,localeDetection:u,localePrefix:f,locales:s}=e;var d;n&&(a=null===(d=t(n,s,f))||void 0===d?void 0:d.locale);return!a&&u&&l&&(a=i(l,s)),!a&&u&&o&&(a=c(o,s,r)),a||(a=r),a}function u(e,o,l,u){const f=function(e,o){var l;let t=a(e);if(t=null===(l=t)||void 0===l?void 0:l.replace(/:\d+$/,""),t&&o)return o.find((e=>e.domain===t))}(o,e.domains);if(!f)return{locale:r(e,o,l,u)};let s;if(u){var d;const o=null===(d=t(u,e.locales,e.localePrefix))||void 0===d?void 0:d.locale;if(o){if(!n(o,f))return{locale:o,domain:f};s=o}}if(!s&&e.localeDetection&&l){const o=i(l,e.locales);o&&n(o,f)&&(s=o)}if(!s&&e.localeDetection&&o){const l=c(o,f.locales||e.locales,f.defaultLocale);l&&(s=l)}return s||(s=f.defaultLocale),{locale:s,domain:f}}function f(e,o,l,t){return e.domains?u(e,o,l,t):{locale:r(e,o,l,t)}}export{f as default,c as getAcceptLanguageLocale};
@@ -1 +1 @@
1
- import{cache as t}from"react";import{_createFormatters as e,initializeConfig as o}from"use-intl/core";import{getRequestLocale as n}from"./RequestLocale.js";import r from"next-intl/config";const a=t((function(){return new Date}));const s=t((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const i=t((async function(t,e){let o=!1;const r={get locale(){return o=!0,e||n()}};let i=t(r);return i instanceof Promise&&(i=await i),i.locale&&o&&console.error("\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"),{...i,locale:i.locale||r.locale,now:i.now||a(),timeZone:i.timeZone||s()}})),c=t(e);const l=t((async function(t){const e=await i(r,t);return{...o(e),_formatters:c()}}));export{l as default};
1
+ import{cache as t}from"react";import{_createIntlFormatters as e,_createCache as o,initializeConfig as n}from"use-intl/core";import{getRequestLocale as r}from"./RequestLocale.js";import a from"next-intl/config";const s=t((function(){return new Date}));const i=t((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const c=t((async function(t,e){let o=!1;const n={get locale(){return o=!0,e||r()}};let a=t(n);return a instanceof Promise&&(a=await a),a.locale&&o&&console.error("\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"),{...a,locale:a.locale||n.locale,now:a.now||s(),timeZone:a.timeZone||i()}})),l=t(e),u=t(o);const m=t((async function(t){const e=await c(a,t);return{...n(e),_formatters:l(u())}}));export{m as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),a=require("../shared/constants.js"),l=require("./utils.js");function o(e){return e&&e.__esModule?e:{default:e}}var n=o(t);function c(t,a,l){let o;const c=new n.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{o=e.match(c,a,l)}catch(e){}return o}function i(e,t){if(e.has(a.COOKIE_LOCALE_NAME)){var l;const o=null===(l=e.get(a.COOKIE_LOCALE_NAME))||void 0===l?void 0:l.value;if(o&&t.includes(o))return o}}function r(e,t,a,o){let n,{defaultLocale:r,localeDetection:u,localePrefix:s,locales:d}=e;var f;o&&(n=null===(f=l.getPathnameMatch(o,d,s))||void 0===f?void 0:f.locale);return!n&&u&&a&&(n=i(a,d)),!n&&u&&t&&(n=c(t,d,r)),n||(n=r),n}function u(e,t,a,o){const n=function(e,t){var a;let o=l.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,e.domains);if(!n)return{locale:r(e,t,a,o)};let u;if(o){var s;const t=null===(s=l.getPathnameMatch(o,e.locales,e.localePrefix))||void 0===s?void 0:s.locale;if(t){if(!l.isLocaleSupportedOnDomain(t,n))return{locale:t,domain:n};u=t}}if(!u&&e.localeDetection&&a){const t=i(a,e.locales);t&&l.isLocaleSupportedOnDomain(t,n)&&(u=t)}if(!u&&e.localeDetection&&t){const a=c(t,n.locales||e.locales,n.defaultLocale);a&&(u=a)}return u||(u=n.defaultLocale),{locale:u,domain:n}}exports.default=function(e,t,a,l){return e.domains?u(e,t,a,l):{locale:r(e,t,a,l)}},exports.getAcceptLanguageLocale=c;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),l=require("../shared/constants.js"),o=require("./utils.js");function a(e){return e&&e.__esModule?e:{default:e}}var n=a(t);function c(t,l,o){let a;const c=new n.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{const t=function(e){return e.slice().sort(((e,t)=>t.length-e.length))}(l);a=e.match(c,t,o)}catch(e){}return a}function i(e,t){if(e.has(l.COOKIE_LOCALE_NAME)){var o;const a=null===(o=e.get(l.COOKIE_LOCALE_NAME))||void 0===o?void 0:o.value;if(a&&t.includes(a))return a}}function r(e,t,l,a){let n,{defaultLocale:r,localeDetection:u,localePrefix:s,locales:d}=e;var f;a&&(n=null===(f=o.getPathnameMatch(a,d,s))||void 0===f?void 0:f.locale);return!n&&u&&l&&(n=i(l,d)),!n&&u&&t&&(n=c(t,d,r)),n||(n=r),n}function u(e,t,l,a){const n=function(e,t){var l;let a=o.getHost(e);if(a=null===(l=a)||void 0===l?void 0:l.replace(/:\d+$/,""),a&&t)return t.find((e=>e.domain===a))}(t,e.domains);if(!n)return{locale:r(e,t,l,a)};let u;if(a){var s;const t=null===(s=o.getPathnameMatch(a,e.locales,e.localePrefix))||void 0===s?void 0:s.locale;if(t){if(!o.isLocaleSupportedOnDomain(t,n))return{locale:t,domain:n};u=t}}if(!u&&e.localeDetection&&l){const t=i(l,e.locales);t&&o.isLocaleSupportedOnDomain(t,n)&&(u=t)}if(!u&&e.localeDetection&&t){const l=c(t,n.locales||e.locales,n.defaultLocale);l&&(u=l)}return u||(u=n.defaultLocale),{locale:u,domain:n}}exports.default=function(e,t,l,o){return e.domains?u(e,t,l,o):{locale:r(e,t,l,o)}},exports.getAcceptLanguageLocale=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("use-intl/core"),n=require("./RequestLocale.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(require("next-intl/config"));const a=e.cache((function(){return new Date}));const c=e.cache((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const s=e.cache((async function(e,t){let o=!1;const r={get locale(){return o=!0,t||n.getRequestLocale()}};let s=e(r);return s instanceof Promise&&(s=await s),s.locale&&o&&console.error("\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"),{...s,locale:s.locale||r.locale,now:s.now||a(),timeZone:s.timeZone||c()}})),i=e.cache(t._createFormatters);const u=e.cache((async function(e){const n=await s(r.default,e);return{...t.initializeConfig(n),_formatters:i()}}));exports.default=u;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("use-intl/core"),n=require("./RequestLocale.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(require("next-intl/config"));const a=e.cache((function(){return new Date}));const c=e.cache((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const s=e.cache((async function(e,t){let o=!1;const r={get locale(){return o=!0,t||n.getRequestLocale()}};let s=e(r);return s instanceof Promise&&(s=await s),s.locale&&o&&console.error("\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"),{...s,locale:s.locale||r.locale,now:s.now||a(),timeZone:s.timeZone||c()}})),i=e.cache(t._createIntlFormatters),u=e.cache(t._createCache);const l=e.cache((async function(e){const n=await s(r.default,e);return{...t.initializeConfig(n),_formatters:i(u())}}));exports.default=l;
@@ -1,10 +1,10 @@
1
- import { IntlConfig, _createFormatters } from 'use-intl/core';
1
+ import { IntlConfig, _createIntlFormatters } from 'use-intl/core';
2
2
  declare function getConfigImpl(localeOverride?: string): Promise<IntlConfig & {
3
3
  getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>;
4
4
  now: NonNullable<IntlConfig['now']>;
5
5
  onError: NonNullable<IntlConfig['onError']>;
6
6
  timeZone: NonNullable<IntlConfig['timeZone']>;
7
- _formatters: ReturnType<typeof _createFormatters>;
7
+ _formatters: ReturnType<typeof _createIntlFormatters>;
8
8
  }>;
9
9
  declare const getConfig: typeof getConfigImpl;
10
10
  export default getConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.17.3",
3
+ "version": "3.17.5",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -85,47 +85,13 @@
85
85
  "next.js"
86
86
  ],
87
87
  "dependencies": {
88
- "@formatjs/intl-localematcher": "^0.2.32",
88
+ "@formatjs/intl-localematcher": "^0.5.4",
89
89
  "negotiator": "^0.6.3",
90
- "use-intl": "^3.17.3"
90
+ "use-intl": "^3.17.5"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
94
94
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
95
95
  },
96
- "size-limit": [
97
- {
98
- "path": "dist/production/index.react-client.js",
99
- "limit": "16.055 KB"
100
- },
101
- {
102
- "path": "dist/production/index.react-server.js",
103
- "limit": "16.875 KB"
104
- },
105
- {
106
- "path": "dist/production/navigation.react-client.js",
107
- "limit": "3.55 KB"
108
- },
109
- {
110
- "path": "dist/production/navigation.react-server.js",
111
- "limit": "18.355 KB"
112
- },
113
- {
114
- "path": "dist/production/server.react-client.js",
115
- "limit": "1 KB"
116
- },
117
- {
118
- "path": "dist/production/server.react-server.js",
119
- "limit": "16.025 KB"
120
- },
121
- {
122
- "path": "dist/production/middleware.js",
123
- "limit": "6.525 KB"
124
- },
125
- {
126
- "path": "dist/production/routing.js",
127
- "limit": "0 KB"
128
- }
129
- ],
130
- "gitHead": "ed4681fa70b8f67a97e1364deaabf58df302d80c"
96
+ "gitHead": "ffa3b52e93c3282dd8e0dce6e1bb8c41eab8a499"
131
97
  }