use-intl 2.10.0-alpha.3 → 2.10.0-alpha.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/core/use-intl.esm.js +35 -151
  3. package/dist/core/use-intl.esm.js.map +1 -1
  4. package/dist/core/use-intl.esm3.js +151 -35
  5. package/dist/core/use-intl.esm3.js.map +1 -1
  6. package/dist/core/use-intl.esm5.js +2 -2
  7. package/dist/core/use-intl.esm5.js.map +1 -1
  8. package/dist/core/use-intl.esm6.js +29 -7
  9. package/dist/core/use-intl.esm6.js.map +1 -1
  10. package/dist/core/use-intl.esm7.js +7 -7
  11. package/dist/core/use-intl.esm7.js.map +1 -1
  12. package/dist/core/use-intl.esm8.js +7 -29
  13. package/dist/core/use-intl.esm8.js.map +1 -1
  14. package/dist/react/IntlContext.d.ts +19 -2
  15. package/dist/react/IntlProvider.d.ts +16 -2
  16. package/dist/react/use-intl.esm.js +26 -7
  17. package/dist/react/use-intl.esm.js.map +1 -1
  18. package/dist/react/use-intl.esm2.js +44 -19
  19. package/dist/react/use-intl.esm2.js.map +1 -1
  20. package/dist/react/use-intl.esm3.js +2 -2
  21. package/dist/react/use-intl.esm4.js +19 -44
  22. package/dist/react/use-intl.esm4.js.map +1 -1
  23. package/dist/react/use-intl.esm5.js +4 -4
  24. package/dist/react/use-intl.esm5.js.map +1 -1
  25. package/dist/react/use-intl.esm6.js +4 -4
  26. package/dist/react/use-intl.esm6.js.map +1 -1
  27. package/dist/react/use-intl.esm7.js +12 -3
  28. package/dist/react/use-intl.esm7.js.map +1 -1
  29. package/dist/react/use-intl.esm8.js +38 -27
  30. package/dist/react/use-intl.esm8.js.map +1 -1
  31. package/dist/react/use-intl.esm9.js +3 -12
  32. package/dist/react/use-intl.esm9.js.map +1 -1
  33. package/dist/react/useIntlContext.d.ts +1 -1
  34. package/dist/src/core/createBaseTranslator.js +7 -11
  35. package/dist/src/core/createBaseTranslator.js.map +1 -1
  36. package/dist/src/core/createIntl.js +2 -2
  37. package/dist/src/core/createIntl.js.map +1 -1
  38. package/dist/src/core/createTranslatorImpl.js +1 -1
  39. package/dist/src/core/createTranslatorImpl.js.map +1 -1
  40. package/dist/src/react/IntlContext.d.ts +19 -2
  41. package/dist/src/react/IntlContext.js.map +1 -1
  42. package/dist/src/react/IntlProvider.d.ts +16 -2
  43. package/dist/src/react/IntlProvider.js +13 -4
  44. package/dist/src/react/IntlProvider.js.map +1 -1
  45. package/dist/src/react/useIntlContext.d.ts +1 -1
  46. package/dist/src/react/useIntlContext.js +1 -1
  47. package/dist/src/react/useIntlContext.js.map +1 -1
  48. package/dist/use-intl.cjs.development.js +28 -37
  49. package/dist/use-intl.cjs.development.js.map +1 -1
  50. package/dist/use-intl.cjs.production.min.js +1 -1
  51. package/dist/use-intl.cjs.production.min.js.map +1 -1
  52. package/dist/use-intl.esm.js +6 -6
  53. package/package.json +2 -2
  54. package/src/core/createBaseTranslator.tsx +7 -11
  55. package/src/core/createIntl.tsx +2 -2
  56. package/src/core/createTranslatorImpl.tsx +1 -1
  57. package/src/react/IntlContext.tsx +20 -2
  58. package/src/react/IntlProvider.tsx +36 -5
  59. package/src/react/useIntlContext.tsx +1 -1
  60. package/dist/react/IntlContextValue.d.ts +0 -19
  61. package/dist/react/IntlProviderProps.d.ts +0 -15
  62. package/dist/react/getIntlContextValue.d.ts +0 -18
  63. package/dist/react/use-intl.esm10.js +0 -44
  64. package/dist/react/use-intl.esm10.js.map +0 -1
  65. package/dist/src/react/IntlContextValue.d.ts +0 -19
  66. package/dist/src/react/IntlContextValue.js +0 -2
  67. package/dist/src/react/IntlContextValue.js.map +0 -1
  68. package/dist/src/react/IntlProviderProps.d.ts +0 -15
  69. package/dist/src/react/IntlProviderProps.js +0 -2
  70. package/dist/src/react/IntlProviderProps.js.map +0 -1
  71. package/dist/src/react/getIntlContextValue.d.ts +0 -18
  72. package/dist/src/react/getIntlContextValue.js +0 -21
  73. package/dist/src/react/getIntlContextValue.js.map +0 -1
  74. package/src/react/IntlContextValue.tsx +0 -21
  75. package/src/react/IntlProviderProps.tsx +0 -17
  76. package/src/react/getIntlContextValue.tsx +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "2.10.0-alpha.3",
3
+ "version": "2.10.0-alpha.4",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.me>",
6
6
  "description": "Minimal, but complete solution for managing internationalization in React apps.",
@@ -15,7 +15,7 @@
15
15
  "build": "yarn build:default && yarn build:rsc",
16
16
  "build:default": "rm -rf dist && dts build",
17
17
  "build:rsc": "tsc && rm -rf dist/test",
18
- "test": "TZ=Europe/Berlin dts test",
18
+ "test": "TZ=Europe/Berlin dts test --testPathIgnorePatterns=dist",
19
19
  "lint": "eslint src test && tsc --noEmit",
20
20
  "prepublishOnly": "yarn test && yarn lint && yarn build"
21
21
  },
@@ -24,9 +24,7 @@ function resolvePath(
24
24
  ) {
25
25
  if (!messages) {
26
26
  throw new Error(
27
- process.env.NODE_ENV !== 'production'
28
- ? `No messages available at \`${namespace}\`.`
29
- : undefined
27
+ __DEV__ ? `No messages available at \`${namespace}\`.` : undefined
30
28
  );
31
29
  }
32
30
 
@@ -37,7 +35,7 @@ function resolvePath(
37
35
 
38
36
  if (part == null || next == null) {
39
37
  throw new Error(
40
- process.env.NODE_ENV !== 'production'
38
+ __DEV__
41
39
  ? `Could not resolve \`${key}\` in ${
42
40
  namespace ? `\`${namespace}\`` : 'messages'
43
41
  }.`
@@ -91,9 +89,7 @@ export function getMessagesOrError<Messages extends AbstractIntlMessages>({
91
89
  try {
92
90
  if (!messages) {
93
91
  throw new Error(
94
- process.env.NODE_ENV !== 'production'
95
- ? `No messages were configured on the provider.`
96
- : undefined
92
+ __DEV__ ? `No messages were configured on the provider.` : undefined
97
93
  );
98
94
  }
99
95
 
@@ -103,7 +99,7 @@ export function getMessagesOrError<Messages extends AbstractIntlMessages>({
103
99
 
104
100
  if (!retrievedMessages) {
105
101
  throw new Error(
106
- process.env.NODE_ENV !== 'production'
102
+ __DEV__
107
103
  ? `No messages for namespace \`${namespace}\` found.`
108
104
  : undefined
109
105
  );
@@ -191,7 +187,7 @@ export default function createBaseTranslator<
191
187
  return getFallbackFromErrorAndNotify(
192
188
  key,
193
189
  IntlErrorCode.INSUFFICIENT_PATH,
194
- process.env.NODE_ENV !== 'production'
190
+ __DEV__
195
191
  ? `Insufficient path specified for \`${key}\` in \`${
196
192
  namespace ? `\`${namespace}\`` : 'messages'
197
193
  }\`.`
@@ -235,7 +231,7 @@ export default function createBaseTranslator<
235
231
 
236
232
  if (formattedMessage == null) {
237
233
  throw new Error(
238
- process.env.NODE_ENV !== 'production'
234
+ __DEV__
239
235
  ? `Unable to format \`${key}\` in ${
240
236
  namespace ? `namespace \`${namespace}\`` : 'messages'
241
237
  }`
@@ -278,7 +274,7 @@ export default function createBaseTranslator<
278
274
  return getFallbackFromErrorAndNotify(
279
275
  key,
280
276
  IntlErrorCode.INVALID_MESSAGE,
281
- process.env.NODE_ENV !== 'production'
277
+ __DEV__
282
278
  ? `The message \`${key}\` in ${
283
279
  namespace ? `namespace \`${namespace}\`` : 'messages'
284
280
  } didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`
@@ -71,7 +71,7 @@ export default function createIntl({
71
71
  if (!options) {
72
72
  const error = new IntlError(
73
73
  IntlErrorCode.MISSING_FORMAT,
74
- process.env.NODE_ENV !== 'production'
74
+ __DEV__
75
75
  ? `Format \`${formatName}\` is not available. You can configure it on the provider or provide custom options.`
76
76
  : undefined
77
77
  );
@@ -153,7 +153,7 @@ export default function createIntl({
153
153
  now = globalNow;
154
154
  } else {
155
155
  throw new Error(
156
- process.env.NODE_ENV !== 'production'
156
+ __DEV__
157
157
  ? `The \`now\` parameter wasn't provided to \`formatRelativeTime\` and there was no global fallback configured on the provider.`
158
158
  : undefined
159
159
  );
@@ -67,7 +67,7 @@ export default function createTranslatorImpl<
67
67
  if (typeof result !== 'string') {
68
68
  const error = new IntlError(
69
69
  IntlErrorCode.FORMATTING_ERROR,
70
- process.env.NODE_ENV !== 'production'
70
+ __DEV__
71
71
  ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})"
72
72
  : undefined
73
73
  );
@@ -1,6 +1,24 @@
1
1
  import {createContext} from 'react';
2
- import IntlContextValue from './IntlContextValue';
2
+ import AbstractIntlMessages from '../core/AbstractIntlMessages';
3
+ import Formats from '../core/Formats';
4
+ import IntlError from '../core/IntlError';
5
+ import {RichTranslationValues} from '../core/TranslationValues';
3
6
 
4
- const IntlContext = createContext<IntlContextValue | undefined>(undefined);
7
+ export type IntlContextShape = {
8
+ messages?: AbstractIntlMessages;
9
+ locale: string;
10
+ formats?: Partial<Formats>;
11
+ timeZone?: string;
12
+ onError(error: IntlError): void;
13
+ getMessageFallback(info: {
14
+ error: IntlError;
15
+ key: string;
16
+ namespace?: string;
17
+ }): string;
18
+ now?: Date;
19
+ defaultTranslationValues?: RichTranslationValues;
20
+ };
21
+
22
+ const IntlContext = createContext<IntlContextShape | undefined>(undefined);
5
23
 
6
24
  export default IntlContext;
@@ -1,11 +1,42 @@
1
- import React from 'react';
1
+ import React, {ReactNode, useEffect} from 'react';
2
+ import {AbstractIntlMessages} from '../core';
3
+ import IntlConfiguration from '../core/IntlConfiguration';
4
+ import {RichTranslationValues} from '../core/TranslationValues';
5
+ import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';
6
+ import validateMessages from '../core/validateMessages';
2
7
  import IntlContext from './IntlContext';
3
- import IntlProviderProps from './IntlProviderProps';
4
- import getIntlContextValue from './getIntlContextValue';
5
8
 
6
- export default function IntlProvider({children, ...props}: IntlProviderProps) {
9
+ type Props = IntlConfiguration & {
10
+ /** All components that use the provided hooks should be within this tree. */
11
+ children: ReactNode;
12
+ /** Global default values for translation values and rich text elements.
13
+ * Can be used for consistent usage or styling of rich text elements.
14
+ * Defaults will be overidden by locally provided values. */
15
+ defaultTranslationValues?: RichTranslationValues;
16
+ /** All messages that will be available in your components. */
17
+ messages?: AbstractIntlMessages;
18
+ };
19
+
20
+ export default function IntlProvider({
21
+ children,
22
+ onError = defaultOnError,
23
+ getMessageFallback = defaultGetMessageFallback,
24
+ messages,
25
+ ...contextValues
26
+ }: Props) {
27
+ if (__DEV__) {
28
+ // eslint-disable-next-line react-hooks/rules-of-hooks
29
+ useEffect(() => {
30
+ if (messages) {
31
+ validateMessages(messages, onError);
32
+ }
33
+ }, [messages, onError]);
34
+ }
35
+
7
36
  return (
8
- <IntlContext.Provider value={getIntlContextValue(props)}>
37
+ <IntlContext.Provider
38
+ value={{...contextValues, messages, onError, getMessageFallback}}
39
+ >
9
40
  {children}
10
41
  </IntlContext.Provider>
11
42
  );
@@ -6,7 +6,7 @@ export default function useIntlContext() {
6
6
 
7
7
  if (!context) {
8
8
  throw new Error(
9
- process.env.NODE_ENV !== 'production'
9
+ __DEV__
10
10
  ? 'No intl context found. Have you configured the provider?'
11
11
  : undefined
12
12
  );
@@ -1,19 +0,0 @@
1
- import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
- import Formats from '../core/Formats';
3
- import IntlError from '../core/IntlError';
4
- import { RichTranslationValues } from '../core/TranslationValues';
5
- declare type IntlContextValue = {
6
- messages?: AbstractIntlMessages;
7
- locale: string;
8
- formats?: Partial<Formats>;
9
- timeZone?: string;
10
- onError(error: IntlError): void;
11
- getMessageFallback(info: {
12
- error: IntlError;
13
- key: string;
14
- namespace?: string;
15
- }): string;
16
- now?: Date;
17
- defaultTranslationValues?: RichTranslationValues;
18
- };
19
- export default IntlContextValue;
@@ -1,15 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { AbstractIntlMessages } from '../core';
3
- import IntlConfiguration from '../core/IntlConfiguration';
4
- import { RichTranslationValues } from '../core/TranslationValues';
5
- declare type IntlProviderProps = IntlConfiguration & {
6
- /** All components that use the provided hooks should be within this tree. */
7
- children: ReactNode;
8
- /** Global default values for translation values and rich text elements.
9
- * Can be used for consistent usage or styling of rich text elements.
10
- * Defaults will be overidden by locally provided values. */
11
- defaultTranslationValues?: RichTranslationValues;
12
- /** All messages that will be available in your components. */
13
- messages?: AbstractIntlMessages;
14
- };
15
- export default IntlProviderProps;
@@ -1,18 +0,0 @@
1
- import IntlProviderProps from './IntlProviderProps';
2
- /**
3
- * Enhances the incoming props with defaults.
4
- */
5
- export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }: Omit<IntlProviderProps, 'children'>): {
6
- messages: import("../core/AbstractIntlMessages").default | undefined;
7
- onError: (error: import("..").IntlError) => void;
8
- getMessageFallback: (info: {
9
- error: import("..").IntlError;
10
- key: string;
11
- namespace?: string | undefined;
12
- }) => string;
13
- locale: string;
14
- formats?: Partial<import("../core/Formats").default> | undefined;
15
- timeZone?: string | undefined;
16
- now?: Date | undefined;
17
- defaultTranslationValues?: import("..").RichTranslationValues | undefined;
18
- };
@@ -1,44 +0,0 @@
1
- import { useRef, useMemo } from 'react';
2
- import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
3
- import resolveNamespace from '../core/use-intl.esm6.js';
4
- import useIntlContext from './use-intl.esm9.js';
5
-
6
- function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
7
- var _useIntlContext = useIntlContext(),
8
- defaultTranslationValues = _useIntlContext.defaultTranslationValues,
9
- globalFormats = _useIntlContext.formats,
10
- getMessageFallback = _useIntlContext.getMessageFallback,
11
- locale = _useIntlContext.locale,
12
- onError = _useIntlContext.onError,
13
- timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
14
- // See the comment in the hook invocation.
15
-
16
-
17
- allMessages = allMessages[namespacePrefix];
18
- namespace = resolveNamespace(namespace, namespacePrefix);
19
- var cachedFormatsByLocaleRef = useRef({});
20
- var messagesOrError = useMemo(function () {
21
- return getMessagesOrError({
22
- messages: allMessages,
23
- namespace: namespace,
24
- onError: onError
25
- });
26
- }, [allMessages, namespace, onError]);
27
- var translate = useMemo(function () {
28
- return createBaseTranslator({
29
- cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
30
- getMessageFallback: getMessageFallback,
31
- messagesOrError: messagesOrError,
32
- defaultTranslationValues: defaultTranslationValues,
33
- namespace: namespace,
34
- onError: onError,
35
- formats: globalFormats,
36
- locale: locale,
37
- timeZone: timeZone
38
- });
39
- }, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
40
- return translate;
41
- }
42
-
43
- export { useTranslationsImpl as default };
44
- //# sourceMappingURL=use-intl.esm10.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-intl.esm10.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAUwB,SAAAA,mBAAA,CAGtBC,WAHsB,EAGCC,SAHD,EAGuBC,eAHvB,EAG8C;AACpE,EAAA,IAAA,eAAA,GAOIC,cAAc,EAPlB;AAAA,MACEC,wBADF,mBACEA,wBADF;AAAA,MAEWC,aAFX,mBAEEC,OAFF;AAAA,MAGEC,kBAHF,mBAGEA,kBAHF;AAAA,MAIEC,MAJF,mBAIEA,MAJF;AAAA,MAKEC,OALF,mBAKEA,OALF;AAAA,MAMEC,QANF,GAAA,eAAA,CAMEA,QANF,CADoE;AAWpE;;;AACAV,EAAAA,WAAW,GAAGA,WAAW,CAACE,eAAD,CAAzB,CAAA;AACAD,EAAAA,SAAS,GAAGU,gBAAgB,CAACV,SAAD,EAAYC,eAAZ,CAA5B,CAAA;AAEA,EAAA,IAAMU,wBAAwB,GAAGC,MAAM,CAErC,EAFqC,CAAvC,CAAA;AAIA,EAAMC,IAAAA,eAAe,GAAGC,OAAO,CAC7B,YAAA;AAAA,IAAA,OAAMC,kBAAkB,CAAC;AAACC,MAAAA,QAAQ,EAAEjB,WAAX;AAAwBC,MAAAA,SAAS,EAATA,SAAxB;AAAmCQ,MAAAA,OAAO,EAAPA,OAAAA;AAAnC,KAAD,CAAxB,CAAA;AAAA,GAD6B,EAE7B,CAACT,WAAD,EAAcC,SAAd,EAAyBQ,OAAzB,CAF6B,CAA/B,CAAA;AAKA,EAAMS,IAAAA,SAAS,GAAGH,OAAO,CACvB,YAAA;AAAA,IAAA,OACEI,oBAAoB,CAAC;AACnBC,MAAAA,qBAAqB,EAAER,wBAAwB,CAACS,OAD7B;AAEnBd,MAAAA,kBAAkB,EAAlBA,kBAFmB;AAGnBO,MAAAA,eAAe,EAAfA,eAHmB;AAInBV,MAAAA,wBAAwB,EAAxBA,wBAJmB;AAKnBH,MAAAA,SAAS,EAATA,SALmB;AAMnBQ,MAAAA,OAAO,EAAPA,OANmB;AAOnBH,MAAAA,OAAO,EAAED,aAPU;AAQnBG,MAAAA,MAAM,EAANA,MARmB;AASnBE,MAAAA,QAAQ,EAARA,QAAAA;AATmB,KAAD,CADtB,CAAA;AAAA,GADuB,EAavB,CACEH,kBADF,EAEEO,eAFF,EAGEV,wBAHF,EAIEH,SAJF,EAKEQ,OALF,EAMEJ,aANF,EAOEG,MAPF,EAQEE,QARF,CAbuB,CAAzB,CAAA;AAyBA,EAAA,OAAOQ,SAAP,CAAA;AACD;;;;"}
@@ -1,19 +0,0 @@
1
- import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
- import Formats from '../core/Formats';
3
- import IntlError from '../core/IntlError';
4
- import { RichTranslationValues } from '../core/TranslationValues';
5
- declare type IntlContextValue = {
6
- messages?: AbstractIntlMessages;
7
- locale: string;
8
- formats?: Partial<Formats>;
9
- timeZone?: string;
10
- onError(error: IntlError): void;
11
- getMessageFallback(info: {
12
- error: IntlError;
13
- key: string;
14
- namespace?: string;
15
- }): string;
16
- now?: Date;
17
- defaultTranslationValues?: RichTranslationValues;
18
- };
19
- export default IntlContextValue;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntlContextValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlContextValue.js","sourceRoot":"","sources":["../../../src/react/IntlContextValue.tsx"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { AbstractIntlMessages } from '../core';
3
- import IntlConfiguration from '../core/IntlConfiguration';
4
- import { RichTranslationValues } from '../core/TranslationValues';
5
- declare type IntlProviderProps = IntlConfiguration & {
6
- /** All components that use the provided hooks should be within this tree. */
7
- children: ReactNode;
8
- /** Global default values for translation values and rich text elements.
9
- * Can be used for consistent usage or styling of rich text elements.
10
- * Defaults will be overidden by locally provided values. */
11
- defaultTranslationValues?: RichTranslationValues;
12
- /** All messages that will be available in your components. */
13
- messages?: AbstractIntlMessages;
14
- };
15
- export default IntlProviderProps;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IntlProviderProps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntlProviderProps.js","sourceRoot":"","sources":["../../../src/react/IntlProviderProps.tsx"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import IntlProviderProps from './IntlProviderProps';
2
- /**
3
- * Enhances the incoming props with defaults.
4
- */
5
- export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }: Omit<IntlProviderProps, 'children'>): {
6
- messages: import("../core/AbstractIntlMessages").default | undefined;
7
- onError: (error: import("..").IntlError) => void;
8
- getMessageFallback: (info: {
9
- error: import("..").IntlError;
10
- key: string;
11
- namespace?: string | undefined;
12
- }) => string;
13
- defaultTranslationValues?: import("..").RichTranslationValues | undefined;
14
- formats?: Partial<import("../core/Formats").default> | undefined;
15
- locale: string;
16
- timeZone?: string | undefined;
17
- now?: Date | undefined;
18
- };
@@ -1,21 +0,0 @@
1
- import { defaultGetMessageFallback, defaultOnError } from '../core/defaults';
2
- import validateMessages from '../core/validateMessages';
3
- /**
4
- * Enhances the incoming props with defaults.
5
- */
6
- export default function getIntlContextValue({ getMessageFallback, messages, onError, ...rest }) {
7
- const finalOnError = onError || defaultOnError;
8
- const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
9
- if (process.env.NODE_ENV !== 'production') {
10
- if (messages) {
11
- validateMessages(messages, finalOnError);
12
- }
13
- }
14
- return {
15
- ...rest,
16
- messages,
17
- onError: finalOnError,
18
- getMessageFallback: finalGetMessageFallback
19
- };
20
- }
21
- //# sourceMappingURL=getIntlContextValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getIntlContextValue.js","sourceRoot":"","sources":["../../../src/react/getIntlContextValue.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC3E,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAGxD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,GAAG,IAAI,EAC6B;IACpC,MAAM,YAAY,GAAG,OAAO,IAAI,cAAc,CAAC;IAC/C,MAAM,uBAAuB,GAC3B,kBAAkB,IAAI,yBAAyB,CAAC;IAElD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,QAAQ,EAAE;YACZ,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;SAC1C;KACF;IAED,OAAO;QACL,GAAG,IAAI;QACP,QAAQ;QACR,OAAO,EAAE,YAAY;QACrB,kBAAkB,EAAE,uBAAuB;KAC5C,CAAC;AACJ,CAAC"}
@@ -1,21 +0,0 @@
1
- import AbstractIntlMessages from '../core/AbstractIntlMessages';
2
- import Formats from '../core/Formats';
3
- import IntlError from '../core/IntlError';
4
- import {RichTranslationValues} from '../core/TranslationValues';
5
-
6
- type IntlContextValue = {
7
- messages?: AbstractIntlMessages;
8
- locale: string;
9
- formats?: Partial<Formats>;
10
- timeZone?: string;
11
- onError(error: IntlError): void;
12
- getMessageFallback(info: {
13
- error: IntlError;
14
- key: string;
15
- namespace?: string;
16
- }): string;
17
- now?: Date;
18
- defaultTranslationValues?: RichTranslationValues;
19
- };
20
-
21
- export default IntlContextValue;
@@ -1,17 +0,0 @@
1
- import {ReactNode} from 'react';
2
- import {AbstractIntlMessages} from '../core';
3
- import IntlConfiguration from '../core/IntlConfiguration';
4
- import {RichTranslationValues} from '../core/TranslationValues';
5
-
6
- type IntlProviderProps = IntlConfiguration & {
7
- /** All components that use the provided hooks should be within this tree. */
8
- children: ReactNode;
9
- /** Global default values for translation values and rich text elements.
10
- * Can be used for consistent usage or styling of rich text elements.
11
- * Defaults will be overidden by locally provided values. */
12
- defaultTranslationValues?: RichTranslationValues;
13
- /** All messages that will be available in your components. */
14
- messages?: AbstractIntlMessages;
15
- };
16
-
17
- export default IntlProviderProps;
@@ -1,30 +0,0 @@
1
- import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';
2
- import validateMessages from '../core/validateMessages';
3
- import IntlProviderProps from './IntlProviderProps';
4
-
5
- /**
6
- * Enhances the incoming props with defaults.
7
- */
8
- export default function getIntlContextValue({
9
- getMessageFallback,
10
- messages,
11
- onError,
12
- ...rest
13
- }: Omit<IntlProviderProps, 'children'>) {
14
- const finalOnError = onError || defaultOnError;
15
- const finalGetMessageFallback =
16
- getMessageFallback || defaultGetMessageFallback;
17
-
18
- if (process.env.NODE_ENV !== 'production') {
19
- if (messages) {
20
- validateMessages(messages, finalOnError);
21
- }
22
- }
23
-
24
- return {
25
- ...rest,
26
- messages,
27
- onError: finalOnError,
28
- getMessageFallback: finalGetMessageFallback
29
- };
30
- }