use-intl 2.13.0-beta.2 → 2.13.0

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/{IntlConfiguration.d.ts → IntlConfig.d.ts} +12 -5
  3. package/dist/core/createBaseTranslator.d.ts +2 -2
  4. package/dist/core/createIntl.d.ts +1 -1
  5. package/dist/core/createTranslator.d.ts +3 -3
  6. package/dist/core/createTranslatorImpl.d.ts +2 -2
  7. package/dist/core/use-intl.esm.js +38 -11
  8. package/dist/core/use-intl.esm.js.map +1 -1
  9. package/dist/core/use-intl.esm2.js +38 -41
  10. package/dist/core/use-intl.esm2.js.map +1 -1
  11. package/dist/core/use-intl.esm3.js +151 -35
  12. package/dist/core/use-intl.esm3.js.map +1 -1
  13. package/dist/core/use-intl.esm4.js +8 -148
  14. package/dist/core/use-intl.esm4.js.map +1 -1
  15. package/dist/core/use-intl.esm5.js +56 -12
  16. package/dist/core/use-intl.esm5.js.map +1 -1
  17. package/dist/core/use-intl.esm6.js +12 -56
  18. package/dist/core/use-intl.esm6.js.map +1 -1
  19. package/dist/core/use-intl.esm7.js +2 -2
  20. package/dist/core/use-intl.esm7.js.map +1 -1
  21. package/dist/core/use-intl.esm9.js +1 -1
  22. package/dist/react/IntlContext.d.ts +2 -2
  23. package/dist/react/IntlProvider.d.ts +7 -2
  24. package/dist/react/getInitializedConfig.d.ts +5 -0
  25. package/dist/react/use-intl.esm.js +3 -3
  26. package/dist/react/use-intl.esm.js.map +1 -1
  27. package/dist/react/use-intl.esm10.js +1 -1
  28. package/dist/react/use-intl.esm2.js +21 -3
  29. package/dist/react/use-intl.esm2.js.map +1 -1
  30. package/dist/react/use-intl.esm3.js +3 -28
  31. package/dist/react/use-intl.esm3.js.map +1 -1
  32. package/dist/react/use-intl.esm5.js +3 -20
  33. package/dist/react/use-intl.esm5.js.map +1 -1
  34. package/dist/react/use-intl.esm6.js +19 -20
  35. package/dist/react/use-intl.esm6.js.map +1 -1
  36. package/dist/react/use-intl.esm7.js +28 -3
  37. package/dist/react/use-intl.esm7.js.map +1 -1
  38. package/dist/react/use-intl.esm8.js +3 -30
  39. package/dist/react/use-intl.esm8.js.map +1 -1
  40. package/dist/react/use-intl.esm9.js +30 -3
  41. package/dist/react/use-intl.esm9.js.map +1 -1
  42. package/dist/react/useFormatter.d.ts +1 -1
  43. package/dist/react/useIntl.d.ts +2 -2
  44. package/dist/react/useIntlContext.d.ts +1 -1
  45. package/dist/src/core/{IntlConfiguration.d.ts → IntlConfig.d.ts} +12 -5
  46. package/dist/src/core/IntlConfig.js +2 -0
  47. package/dist/src/core/IntlConfig.js.map +1 -0
  48. package/dist/src/core/createBaseTranslator.d.ts +2 -2
  49. package/dist/src/core/createBaseTranslator.js.map +1 -1
  50. package/dist/src/core/createTranslator.d.ts +3 -3
  51. package/dist/src/core/createTranslatorImpl.d.ts +2 -2
  52. package/dist/src/core/createTranslatorImpl.js.map +1 -1
  53. package/dist/src/react/IntlContext.d.ts +2 -2
  54. package/dist/src/react/IntlContext.js.map +1 -1
  55. package/dist/src/react/IntlProvider.d.ts +7 -2
  56. package/dist/src/react/IntlProvider.js +2 -2
  57. package/dist/src/react/IntlProvider.js.map +1 -1
  58. package/dist/src/react/getInitializedConfig.d.ts +5 -0
  59. package/dist/src/react/{getIntlContextValue.js → getInitializedConfig.js} +2 -2
  60. package/dist/src/react/getInitializedConfig.js.map +1 -0
  61. package/dist/src/react/useIntl.d.ts +1 -1
  62. package/dist/src/react/useIntl.js +1 -1
  63. package/dist/src/react/useIntl.js.map +1 -1
  64. package/dist/src/react/useIntlContext.d.ts +1 -1
  65. package/dist/use-intl.cjs.development.js +3 -3
  66. package/dist/use-intl.cjs.development.js.map +1 -1
  67. package/dist/use-intl.cjs.production.min.js.map +1 -1
  68. package/dist/use-intl.esm.js +9 -9
  69. package/package.json +3 -2
  70. package/src/core/{IntlConfiguration.tsx → IntlConfig.tsx} +14 -6
  71. package/src/core/createBaseTranslator.tsx +7 -8
  72. package/src/core/createTranslator.tsx +3 -3
  73. package/src/core/createTranslatorImpl.tsx +8 -6
  74. package/src/react/IntlContext.tsx +2 -2
  75. package/src/react/IntlProvider.tsx +9 -5
  76. package/src/react/{getIntlContextValue.tsx → getInitializedConfig.tsx} +9 -4
  77. package/src/react/useIntl.tsx +1 -1
  78. package/CHANGELOG.md +0 -542
  79. package/dist/react/IntlContextValue.d.ts +0 -19
  80. package/dist/react/IntlProviderProps.d.ts +0 -15
  81. package/dist/react/getIntlContextValue.d.ts +0 -13
  82. package/dist/src/core/IntlConfiguration.js +0 -2
  83. package/dist/src/core/IntlConfiguration.js.map +0 -1
  84. package/dist/src/react/IntlContextValue.d.ts +0 -19
  85. package/dist/src/react/IntlContextValue.js +0 -2
  86. package/dist/src/react/IntlContextValue.js.map +0 -1
  87. package/dist/src/react/IntlProviderProps.d.ts +0 -15
  88. package/dist/src/react/IntlProviderProps.js +0 -2
  89. package/dist/src/react/IntlProviderProps.js.map +0 -1
  90. package/dist/src/react/getIntlContextValue.d.ts +0 -13
  91. package/dist/src/react/getIntlContextValue.js.map +0 -1
  92. package/src/react/IntlContextValue.tsx +0 -21
  93. package/src/react/IntlProviderProps.tsx +0 -17
@@ -1,11 +1,12 @@
1
1
  import Formats from './Formats';
2
2
  import IntlError from './IntlError';
3
+ import {AbstractIntlMessages, RichTranslationValues} from '.';
3
4
 
4
5
  /**
5
6
  * Should be used for entry points that configure the library.
6
7
  */
7
8
 
8
- type IntlConfiguration = {
9
+ type IntlConfig<Messages = AbstractIntlMessages> = {
9
10
  /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
10
11
  locale: string;
11
12
  /** Global formats can be provided to achieve consistent
@@ -36,15 +37,22 @@ type IntlConfiguration = {
36
37
  * afterwards the current date will be returned continuously.
37
38
  */
38
39
  now?: Date;
40
+ /** All messages that will be available. */
41
+ messages?: Messages;
42
+ /** Global default values for translation values and rich text elements.
43
+ * Can be used for consistent usage or styling of rich text elements.
44
+ * Defaults will be overidden by locally provided values. */
45
+ defaultTranslationValues?: RichTranslationValues;
39
46
  };
40
47
 
41
48
  /**
42
49
  * A stricter set of the configuration that should be used internally
43
50
  * once defaults are assigned to `IntlConfiguration`.
44
51
  */
45
- export type InitializedIntlConfiguration = IntlConfiguration & {
46
- onError: NonNullable<IntlConfiguration['onError']>;
47
- getMessageFallback: NonNullable<IntlConfiguration['getMessageFallback']>;
48
- };
52
+ export type InitializedIntlConfig<Messages = AbstractIntlMessages> =
53
+ IntlConfig<Messages> & {
54
+ onError: NonNullable<IntlConfig<Messages>['onError']>;
55
+ getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
56
+ };
49
57
 
50
- export default IntlConfiguration;
58
+ export default IntlConfig;
@@ -9,7 +9,7 @@ import {
9
9
  } from 'react';
10
10
  import AbstractIntlMessages from './AbstractIntlMessages';
11
11
  import Formats from './Formats';
12
- import {InitializedIntlConfiguration} from './IntlConfiguration';
12
+ import {InitializedIntlConfig} from './IntlConfig';
13
13
  import IntlError, {IntlErrorCode} from './IntlError';
14
14
  import TranslationValues, {RichTranslationValues} from './TranslationValues';
15
15
  import convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';
@@ -121,13 +121,12 @@ export function getMessagesOrError<Messages extends AbstractIntlMessages>({
121
121
  }
122
122
  }
123
123
 
124
- export type CreateBaseTranslatorProps<Messages> =
125
- InitializedIntlConfiguration & {
126
- cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
127
- defaultTranslationValues?: RichTranslationValues;
128
- namespace?: string;
129
- messagesOrError: Messages | IntlError;
130
- };
124
+ export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
125
+ cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
126
+ defaultTranslationValues?: RichTranslationValues;
127
+ namespace?: string;
128
+ messagesOrError: Messages | IntlError;
129
+ };
131
130
 
132
131
  export default function createBaseTranslator<
133
132
  Messages extends AbstractIntlMessages,
@@ -1,5 +1,5 @@
1
1
  import Formats from './Formats';
2
- import IntlConfiguration from './IntlConfiguration';
2
+ import IntlConfig from './IntlConfig';
3
3
  import TranslationValues from './TranslationValues';
4
4
  import createTranslatorImpl, {
5
5
  CoreRichTranslationValues
@@ -29,8 +29,8 @@ export default function createTranslator<
29
29
  messages,
30
30
  namespace,
31
31
  ...rest
32
- }: IntlConfiguration & {
33
- messages: IntlMessages;
32
+ }: Omit<IntlConfig<IntlMessages>, 'defaultTranslationValues' | 'messages'> & {
33
+ messages: NonNullable<IntlConfig<IntlMessages>['messages']>;
34
34
  namespace?: NestedKey;
35
35
  }): // Explicitly defining the return type is necessary as TypeScript would get it wrong
36
36
  {
@@ -1,5 +1,5 @@
1
1
  import AbstractIntlMessages from './AbstractIntlMessages';
2
- import {InitializedIntlConfiguration} from './IntlConfiguration';
2
+ import {InitializedIntlConfig} from './IntlConfig';
3
3
  import IntlError, {IntlErrorCode} from './IntlError';
4
4
  import {RichTranslationValues, TranslationValue} from './TranslationValues';
5
5
  import createBaseTranslator, {getMessagesOrError} from './createBaseTranslator';
@@ -11,11 +11,13 @@ export type CoreRichTranslationValues = Record<
11
11
  TranslationValue | ((chunks: string) => string)
12
12
  >;
13
13
 
14
- export type CreateTranslatorImplProps<Messages> =
15
- InitializedIntlConfiguration & {
16
- namespace: string;
17
- messages: Messages;
18
- };
14
+ export type CreateTranslatorImplProps<Messages> = Omit<
15
+ InitializedIntlConfig,
16
+ 'messages'
17
+ > & {
18
+ namespace: string;
19
+ messages: Messages;
20
+ };
19
21
 
20
22
  export default function createTranslatorImpl<
21
23
  Messages extends AbstractIntlMessages,
@@ -1,6 +1,6 @@
1
1
  import {createContext} from 'react';
2
- import IntlContextValue from './IntlContextValue';
2
+ import {InitializedIntlConfig} from '../core/IntlConfig';
3
3
 
4
- const IntlContext = createContext<IntlContextValue | undefined>(undefined);
4
+ const IntlContext = createContext<InitializedIntlConfig | undefined>(undefined);
5
5
 
6
6
  export default IntlContext;
@@ -1,11 +1,15 @@
1
- import React from 'react';
1
+ import React, {ReactNode} from 'react';
2
+ import IntlConfig from '../core/IntlConfig';
2
3
  import IntlContext from './IntlContext';
3
- import IntlProviderProps from './IntlProviderProps';
4
- import getIntlContextValue from './getIntlContextValue';
4
+ import getInitializedConfig from './getInitializedConfig';
5
5
 
6
- export default function IntlProvider({children, ...props}: IntlProviderProps) {
6
+ type Props = IntlConfig & {
7
+ children: ReactNode;
8
+ };
9
+
10
+ export default function IntlProvider({children, ...props}: Props) {
7
11
  return (
8
- <IntlContext.Provider value={getIntlContextValue(props)}>
12
+ <IntlContext.Provider value={getInitializedConfig(props)}>
9
13
  {children}
10
14
  </IntlContext.Provider>
11
15
  );
@@ -1,15 +1,20 @@
1
+ import IntlConfig, {InitializedIntlConfig} from '../core/IntlConfig';
1
2
  import {defaultGetMessageFallback, defaultOnError} from '../core/defaults';
2
3
  import validateMessages from '../core/validateMessages';
3
- import IntlProviderProps from './IntlProviderProps';
4
4
 
5
5
  /**
6
6
  * Enhances the incoming props with defaults.
7
7
  */
8
- export default function getIntlContextValue<
8
+ export default function getInitializedConfig<
9
9
  // This is a generic to allow for stricter typing. E.g.
10
10
  // the RSC integration always provides a `now` value.
11
- Props extends Omit<IntlProviderProps, 'children'>
12
- >({getMessageFallback, messages, onError, ...rest}: Props) {
11
+ Props extends Omit<IntlConfig, 'children'>
12
+ >({
13
+ getMessageFallback,
14
+ messages,
15
+ onError,
16
+ ...rest
17
+ }: Props): InitializedIntlConfig {
13
18
  const finalOnError = onError || defaultOnError;
14
19
  const finalGetMessageFallback =
15
20
  getMessageFallback || defaultGetMessageFallback;
@@ -4,7 +4,7 @@ import useIntlContext from './useIntlContext';
4
4
 
5
5
  let hasWarned = false;
6
6
 
7
- /** @deprecated Switch to `useFormatter` */
7
+ /** @deprecated Switch to `useFormatter` instead. */
8
8
  export default function useIntl() {
9
9
  const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();
10
10