use-intl 3.17.5 → 3.17.6

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.
@@ -26,8 +26,9 @@ function IntlProvider(_ref) {
26
26
  // The formatter cache is released when the locale changes. For
27
27
  // long-running apps with a persistent `IntlProvider` at the root,
28
28
  // this can reduce the memory footprint (e.g. in React Native).
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- const cache = React.useMemo(() => initializeConfig.createCache(), [locale]);
29
+ const cache = React.useMemo(() => {
30
+ return initializeConfig.createCache();
31
+ }, [locale]);
31
32
  const formatters = React.useMemo(() => initializeConfig.createIntlFormatters(cache), [cache]);
32
33
 
33
34
  // Memoizing this value helps to avoid triggering a re-render of all
@@ -13,7 +13,7 @@ require('@formatjs/fast-memoize');
13
13
 
14
14
  let hasWarnedForMissingTimezone = false;
15
15
  const isServer = typeof window === 'undefined';
16
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
16
+ function useTranslationsImpl(allMessagesPrefixed, namespacePrefixed, namespacePrefix) {
17
17
  const {
18
18
  cache,
19
19
  defaultTranslationValues,
@@ -27,9 +27,10 @@ function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
27
27
 
28
28
  // The `namespacePrefix` is part of the type system.
29
29
  // See the comment in the hook invocation.
30
- allMessages = allMessages[namespacePrefix];
31
- namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
30
+ const allMessages = allMessagesPrefixed[namespacePrefix];
31
+ const namespace = createFormatter.resolveNamespace(namespacePrefixed, namespacePrefix);
32
32
  if (!timeZone && !hasWarnedForMissingTimezone && isServer) {
33
+ // eslint-disable-next-line react-compiler/react-compiler
33
34
  hasWarnedForMissingTimezone = true;
34
35
  onError(new initializeConfig.IntlError(initializeConfig.IntlErrorCode.ENVIRONMENT_FALLBACK, "There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone" ));
35
36
  }
package/dist/esm/react.js CHANGED
@@ -1 +1 @@
1
- export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-s2RNdTF5.js";import{I as i,a as c}from"./initializeConfig-D2A8plWf.js";import"./IntlContext-DoS4CDM3.js";import"intl-messageformat";import"@formatjs/fast-memoize";let m=!1;const l="undefined"==typeof window;function f(o){return function(o,r,s){const{cache:f,defaultTranslationValues:u,formats:d,formatters:p,getMessageFallback:g,locale:v,onError:h,timeZone:w}=e();return o=o[s],r=n(r,s),w||m||!l||(m=!0,h(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),t((()=>a({cache:f,formatters:p,getMessageFallback:g,messages:o,defaultTranslationValues:u,namespace:r,onError:h,formats:d,locale:v,timeZone:w})),[f,p,g,o,u,r,h,d,v,w])}({"!":e().messages},o?"!.".concat(o):"!","!")}function d(){return new Date}function p(t){const n=null==t?void 0:t.updateInterval,{now:a}=e(),[s,i]=o(a||d());return r((()=>{if(!n)return;const e=setInterval((()=>{i(d())}),n);return()=>{clearInterval(e)}}),[a,n]),null==n&&a?a:s}function g(){return e().timeZone}function v(){const t=e();if(!t.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return t.messages}function h(){const{formats:o,formatters:r,locale:n,now:a,onError:i,timeZone:c}=e();return t((()=>s({formats:o,locale:n,now:a,onError:i,timeZone:c,_formatters:r})),[o,r,a,n,i,c])}export{h as useFormatter,v as useMessages,p as useNow,g as useTimeZone,f as useTranslations};
1
+ export{IntlProvider}from"./_IntlProvider.js";import{a as e}from"./_useLocale-v-ZT5JoE.js";export{u as useLocale}from"./_useLocale-v-ZT5JoE.js";import{useMemo as t,useState as o,useEffect as r}from"react";import{r as n,a,c as s}from"./createFormatter-s2RNdTF5.js";import{I as i,a as c}from"./initializeConfig-D2A8plWf.js";import"./IntlContext-DoS4CDM3.js";import"intl-messageformat";import"@formatjs/fast-memoize";let m=!1;const l="undefined"==typeof window;function f(o){return function(o,r,s){const{cache:f,defaultTranslationValues:u,formats:d,formatters:p,getMessageFallback:g,locale:v,onError:h,timeZone:w}=e(),I=o[s],j=n(r,s);return w||m||!l||(m=!0,h(new i(c.ENVIRONMENT_FALLBACK,"There is no `timeZone` configured, this can lead to markup mismatches caused by environment differences. Consider adding a global default: https://next-intl-docs.vercel.app/docs/configuration#time-zone"))),t((()=>a({cache:f,formatters:p,getMessageFallback:g,messages:I,defaultTranslationValues:u,namespace:j,onError:h,formats:d,locale:v,timeZone:w})),[f,p,g,I,u,j,h,d,v,w])}({"!":e().messages},o?"!.".concat(o):"!","!")}function d(){return new Date}function p(t){const n=null==t?void 0:t.updateInterval,{now:a}=e(),[s,i]=o(a||d());return r((()=>{if(!n)return;const e=setInterval((()=>{i(d())}),n);return()=>{clearInterval(e)}}),[a,n]),null==n&&a?a:s}function g(){return e().timeZone}function v(){const t=e();if(!t.messages)throw new Error("No messages found. Have you configured them correctly? See https://next-intl-docs.vercel.app/docs/configuration#messages");return t.messages}function h(){const{formats:o,formatters:r,locale:n,now:a,onError:i,timeZone:c}=e();return t((()=>s({formats:o,locale:n,now:a,onError:i,timeZone:c,_formatters:r})),[o,r,a,n,i,c])}export{h as useFormatter,v as useMessages,p as useNow,g as useTimeZone,f as useTranslations};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-BUmzSWag.js");require("./initializeConfig-AbYTngyP.js"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,formatters:n,locale:s,now:a,onError:u,timeZone:l}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:s,now:a,onError:u,timeZone:l,_formatters:n})),[e,n,a,s,u,l])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),null==o&&n?n:s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{cache:l,defaultTranslationValues:i,formats:c,formatters:m,getMessageFallback:f,locale:I,onError:d,timeZone:x}=t.useIntlContext();return e=e[u],a=o.resolveNamespace(a,u),x||n||!s||(n=!0,d(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({cache:l,formatters:m,getMessageFallback:f,messages:e,defaultTranslationValues:i,namespace:a,onError:d,formats:c,locale:I,timeZone:x})),[l,m,f,e,i,a,d,c,I,x])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_IntlProvider.js"),t=require("./_useLocale-CpTrqBDt.js"),r=require("react"),o=require("./createFormatter-BUmzSWag.js");require("./initializeConfig-AbYTngyP.js"),require("@formatjs/fast-memoize"),require("./IntlContext-DcFt0tgW.js"),require("intl-messageformat");let n=!1;const s="undefined"==typeof window;function a(){return new Date}exports.IntlProvider=e.IntlProvider,exports.useLocale=t.useLocale,exports.useFormatter=function(){const{formats:e,formatters:n,locale:s,now:a,onError:u,timeZone:l}=t.useIntlContext();return r.useMemo((()=>o.createFormatter({formats:e,locale:s,now:a,onError:u,timeZone:l,_formatters:n})),[e,n,a,s,u,l])},exports.useMessages=function(){const e=t.useIntlContext();if(!e.messages)throw new Error(void 0);return e.messages},exports.useNow=function(e){const o=null==e?void 0:e.updateInterval,{now:n}=t.useIntlContext(),[s,u]=r.useState(n||a());return r.useEffect((()=>{if(!o)return;const e=setInterval((()=>{u(a())}),o);return()=>{clearInterval(e)}}),[n,o]),null==o&&n?n:s},exports.useTimeZone=function(){return t.useIntlContext().timeZone},exports.useTranslations=function(e){return function(e,a,u){const{cache:l,defaultTranslationValues:i,formats:c,formatters:m,getMessageFallback:f,locale:I,onError:d,timeZone:x}=t.useIntlContext(),p=e[u],v=o.resolveNamespace(a,u);return x||n||!s||(n=!0,d(new o.IntlError(o.IntlErrorCode.ENVIRONMENT_FALLBACK,void 0))),r.useMemo((()=>o.createBaseTranslator({cache:l,formatters:m,getMessageFallback:f,messages:p,defaultTranslationValues:i,namespace:v,onError:d,formats:c,locale:I,timeZone:x})),[l,m,f,p,i,v,d,c,I,x])}({"!":t.useIntlContext().messages},e?"!.".concat(e):"!","!")};
@@ -1,6 +1,6 @@
1
1
  import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
2
  import NestedKeyOf from '../core/utils/NestedKeyOf';
3
- export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
3
+ export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
4
4
  <TargetKey extends unknown>(key: TargetKey, values?: import("../core").TranslationValues, formats?: Partial<import("../core").Formats>): string;
5
5
  rich: (key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray;
6
6
  markup(key: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray>[0], values: import("../core").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core").RichTranslationValues, formats?: Partial<import("../core").Formats>) => string | import("react").ReactElement | import("react").ReactNodeArray>[2]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "3.17.5",
3
+ "version": "3.17.6",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Internationalization (i18n) for React",
@@ -69,5 +69,5 @@
69
69
  "peerDependencies": {
70
70
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
71
71
  },
72
- "gitHead": "ffa3b52e93c3282dd8e0dce6e1bb8c41eab8a499"
72
+ "gitHead": "9d9d53c9e55f80ce5c6f5cb9bb5f1be04e4d302c"
73
73
  }