next-intl 3.26.1 → 3.26.3

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.
@@ -6,6 +6,7 @@ var navigation = require('next/navigation');
6
6
  var _useLocale = require('use-intl/_useLocale');
7
7
  var constants = require('../shared/constants.js');
8
8
 
9
+ let hasWarnedForParams = false;
9
10
  function useLocale() {
10
11
  // The types aren't entirely correct here. Outside of Next.js
11
12
  // `useParams` can be called, but the return type is `null`.
@@ -17,6 +18,10 @@ function useLocale() {
17
18
  locale = _useLocale.useLocale();
18
19
  } catch (error) {
19
20
  if (typeof (params === null || params === void 0 ? void 0 : params[constants.LOCALE_SEGMENT_NAME]) === 'string') {
21
+ if (!hasWarnedForParams) {
22
+ console.warn('Deprecation warning: `useLocale` has returned a default from `useParams().locale` since no `NextIntlClientProvider` ancestor was found for the calling component. This behavior will be removed in the next major version. Please ensure all Client Components that use `next-intl` are wrapped in a `NextIntlClientProvider`.');
23
+ hasWarnedForParams = true;
24
+ }
20
25
  locale = params[constants.LOCALE_SEGMENT_NAME];
21
26
  } else {
22
27
  throw error;
@@ -13,6 +13,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
14
14
  var getRuntimeConfig__default = /*#__PURE__*/_interopDefault(getRuntimeConfig);
15
15
 
16
+ let hasWarnedForMissingReturnedLocale = false;
17
+ let hasWarnedForAccessedLocaleParam = false;
18
+
16
19
  // Make sure `now` is consistent across the request in case none was configured
17
20
  function getDefaultNowImpl() {
18
21
  return new Date();
@@ -34,6 +37,10 @@ async function receiveRuntimeConfigImpl(getConfig, localeOverride) {
34
37
  // `locale` (either in a single-language workflow or because the locale is
35
38
  // read from the user settings), don't attempt to read the request locale.
36
39
  get locale() {
40
+ if (!hasWarnedForAccessedLocaleParam) {
41
+ console.warn("\nThe `locale` parameter in `getRequestConfig` is deprecated, please switch to `await requestLocale`. See https://next-intl.dev/blog/next-intl-3-22#await-request-locale\n");
42
+ hasWarnedForAccessedLocaleParam = true;
43
+ }
37
44
  return localeOverride || RequestLocaleLegacy.getRequestLocale();
38
45
  },
39
46
  get requestLocale() {
@@ -44,12 +51,19 @@ async function receiveRuntimeConfigImpl(getConfig, localeOverride) {
44
51
  if (result instanceof Promise) {
45
52
  result = await result;
46
53
  }
47
- const locale = result.locale || (await params.requestLocale);
54
+ let locale = result.locale;
48
55
  if (!locale) {
49
- {
50
- console.error("\nUnable to find `next-intl` locale because the middleware didn't run on this request and no `locale` was returned in `getRequestConfig`. See https://next-intl.dev/docs/routing/middleware#unable-to-find-locale. The `notFound()` function will be called as a result.\n");
56
+ if (!hasWarnedForMissingReturnedLocale) {
57
+ console.error("\nA `locale` is expected to be returned from `getRequestConfig`, but none was returned. This will be an error in the next major version of next-intl.\n\nSee: https://next-intl.dev/blog/next-intl-3-22#await-request-locale\n");
58
+ hasWarnedForMissingReturnedLocale = true;
59
+ }
60
+ locale = await params.requestLocale;
61
+ if (!locale) {
62
+ {
63
+ console.error("\nUnable to find `next-intl` locale because the middleware didn't run on this request and no `locale` was returned in `getRequestConfig`. See https://next-intl.dev/docs/routing/middleware#unable-to-find-locale. The `notFound()` function will be called as a result.\n");
64
+ }
65
+ navigation.notFound();
51
66
  }
52
- navigation.notFound();
53
67
  }
54
68
  return {
55
69
  ...result,
@@ -1 +1 @@
1
- import{useParams as t}from"next/navigation";import{useLocale as o}from"use-intl/_useLocale";import{LOCALE_SEGMENT_NAME as r}from"../shared/constants.js";function e(){const e=t();let n;try{n=o()}catch(t){if("string"!=typeof(null==e?void 0:e[r]))throw t;n=e[r]}return n}export{e as default};
1
+ import{useParams as e}from"next/navigation";import{useLocale as t}from"use-intl/_useLocale";import{LOCALE_SEGMENT_NAME as n}from"../shared/constants.js";let o=!1;function r(){const r=e();let a;try{a=t()}catch(e){if("string"!=typeof(null==r?void 0:r[n]))throw e;o||(console.warn("Deprecation warning: `useLocale` has returned a default from `useParams().locale` since no `NextIntlClientProvider` ancestor was found for the calling component. This behavior will be removed in the next major version. Please ensure all Client Components that use `next-intl` are wrapped in a `NextIntlClientProvider`."),o=!0),a=r[n]}return a}export{r as default};
@@ -1 +1 @@
1
- import{notFound as e}from"next/navigation";import{cache as t}from"react";import{_createIntlFormatters as n,_createCache as o,initializeConfig as r}from"use-intl/core";import{getRequestLocale as i}from"./RequestLocale.js";import{getRequestLocale as a}from"./RequestLocaleLegacy.js";import s from"next-intl/config";const c=t((function(){return new Date}));const l=t((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const u=t((async function(t,n){if("function"!=typeof t)throw new Error("Invalid i18n request configuration detected.\n\nPlease verify that:\n1. In case you've specified a custom location in your Next.js config, make sure that the path is correct.\n2. You have a default export in your i18n request configuration file.\n\nSee also: https://next-intl.dev/docs/usage/configuration#i18n-request\n");const o={get locale(){return n||a()},get requestLocale(){return n?Promise.resolve(n):i()}};let r=t(o);r instanceof Promise&&(r=await r);const s=r.locale||await o.requestLocale;return s||(console.error("\nUnable to find `next-intl` locale because the middleware didn't run on this request and no `locale` was returned in `getRequestConfig`. See https://next-intl.dev/docs/routing/middleware#unable-to-find-locale. The `notFound()` function will be called as a result.\n"),e()),{...r,locale:s,now:r.now||c(),timeZone:r.timeZone||l()}})),f=t(n),m=t(o);const d=t((async function(e){const t=await u(s,e);return{...r(t),_formatters:f(m())}}));export{d as default};
1
+ import{notFound as e}from"next/navigation";import{cache as t}from"react";import{_createIntlFormatters as n,_createCache as o,initializeConfig as r}from"use-intl/core";import{getRequestLocale as i}from"./RequestLocale.js";import{getRequestLocale as a}from"./RequestLocaleLegacy.js";import l from"next-intl/config";let s=!1,c=!1;const u=t((function(){return new Date}));const f=t((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const d=t((async function(t,n){if("function"!=typeof t)throw new Error("Invalid i18n request configuration detected.\n\nPlease verify that:\n1. In case you've specified a custom location in your Next.js config, make sure that the path is correct.\n2. You have a default export in your i18n request configuration file.\n\nSee also: https://next-intl.dev/docs/usage/configuration#i18n-request\n");const o={get locale(){return c||(console.warn("\nThe `locale` parameter in `getRequestConfig` is deprecated, please switch to `await requestLocale`. See https://next-intl.dev/blog/next-intl-3-22#await-request-locale\n"),c=!0),n||a()},get requestLocale(){return n?Promise.resolve(n):i()}};let r=t(o);r instanceof Promise&&(r=await r);let l=r.locale;return l||(s||(console.error("\nA `locale` is expected to be returned from `getRequestConfig`, but none was returned. This will be an error in the next major version of next-intl.\n\nSee: https://next-intl.dev/blog/next-intl-3-22#await-request-locale\n"),s=!0),l=await o.requestLocale,l||(console.error("\nUnable to find `next-intl` locale because the middleware didn't run on this request and no `locale` was returned in `getRequestConfig`. See https://next-intl.dev/docs/routing/middleware#unable-to-find-locale. The `notFound()` function will be called as a result.\n"),e())),{...r,locale:l,now:r.now||u(),timeZone:r.timeZone||f()}})),m=t(n),g=t(o);const p=t((async function(e){const t=await d(l,e);return{...r(t),_formatters:m(g())}}));export{p as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),n=require("use-intl/core"),r=require("./RequestLocale.js"),o=require("./RequestLocaleLegacy.js");function c(e){return e&&e.__esModule?e:{default:e}}var a=c(require("next-intl/config"));const i=t.cache((function(){return new Date}));const u=t.cache((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const s=t.cache((async function(t,n){const c={get locale(){return n||o.getRequestLocale()},get requestLocale(){return n?Promise.resolve(n):r.getRequestLocale()}};let a=t(c);a instanceof Promise&&(a=await a);const s=a.locale||await c.requestLocale;return s||e.notFound(),{...a,locale:s,now:a.now||i(),timeZone:a.timeZone||u()}})),l=t.cache(n._createIntlFormatters),f=t.cache(n._createCache);const q=t.cache((async function(e){const t=await s(a.default,e);return{...n.initializeConfig(t),_formatters:l(f())}}));exports.default=q;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),n=require("use-intl/core"),r=require("./RequestLocale.js"),o=require("./RequestLocaleLegacy.js");function c(e){return e&&e.__esModule?e:{default:e}}var a=c(require("next-intl/config"));const i=t.cache((function(){return new Date}));const u=t.cache((function(){return Intl.DateTimeFormat().resolvedOptions().timeZone}));const s=t.cache((async function(t,n){const c={get locale(){return n||o.getRequestLocale()},get requestLocale(){return n?Promise.resolve(n):r.getRequestLocale()}};let a=t(c);a instanceof Promise&&(a=await a);let s=a.locale;return s||(s=await c.requestLocale,s||e.notFound()),{...a,locale:s,now:a.now||i(),timeZone:a.timeZone||u()}})),l=t.cache(n._createIntlFormatters),f=t.cache(n._createCache);const q=t.cache((async function(e){const t=await s(a.default,e);return{...n.initializeConfig(t),_formatters:l(f())}}));exports.default=q;
@@ -1,14 +1,7 @@
1
1
  import type { IntlConfig } from 'use-intl/core';
2
2
  export type RequestConfig = Omit<IntlConfig, 'locale'> & {
3
3
  /**
4
- * Instead of reading a `requestLocale` from the argument that's passed to the
5
- * function within `getRequestConfig`, you can include a locale as part of the
6
- * returned request configuration.
7
- *
8
- * This can be helpful for the following use cases:
9
- * - Apps that only support a single language
10
- * - Apps where the locale should be read from user settings instead of the pathname
11
- * - Providing a fallback locale in case the locale was not matched by the middleware
4
+ * @see https://next-intl.dev/docs/usage/configuration#i18n-request
12
5
  **/
13
6
  locale?: IntlConfig['locale'];
14
7
  };
@@ -87,6 +87,15 @@ declare function getTranslations<NestedKey extends NamespaceKeys<IntlMessages, N
87
87
  }, [
88
88
  NestedKey
89
89
  ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
90
+ has<TargetKey extends MessageKeys<NestedValueOf<{
91
+ '!': IntlMessages;
92
+ }, [
93
+ NestedKey
94
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
95
+ '!': IntlMessages;
96
+ }, [
97
+ NestedKey
98
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: [TargetKey] extends [never] ? string : TargetKey): boolean;
90
99
  }>;
91
100
  declare const _default: typeof getTranslations;
92
101
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.26.1",
3
+ "version": "3.26.3",
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.26.1"
91
+ "use-intl": "^3.26.3"
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 || ^19.0.0"
96
96
  },
97
- "gitHead": "33cae85fcf6421f076358f9db26b5e137e83e543"
97
+ "gitHead": "0b484fbbe5123eb03fa4e1d4244c4a8c20e6dec4"
98
98
  }