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.
- package/LICENSE +21 -0
- package/dist/core/{IntlConfiguration.d.ts → IntlConfig.d.ts} +12 -5
- package/dist/core/createBaseTranslator.d.ts +2 -2
- package/dist/core/createIntl.d.ts +1 -1
- package/dist/core/createTranslator.d.ts +3 -3
- package/dist/core/createTranslatorImpl.d.ts +2 -2
- package/dist/core/use-intl.esm.js +38 -11
- package/dist/core/use-intl.esm.js.map +1 -1
- package/dist/core/use-intl.esm2.js +38 -41
- package/dist/core/use-intl.esm2.js.map +1 -1
- package/dist/core/use-intl.esm3.js +151 -35
- package/dist/core/use-intl.esm3.js.map +1 -1
- package/dist/core/use-intl.esm4.js +8 -148
- package/dist/core/use-intl.esm4.js.map +1 -1
- package/dist/core/use-intl.esm5.js +56 -12
- package/dist/core/use-intl.esm5.js.map +1 -1
- package/dist/core/use-intl.esm6.js +12 -56
- package/dist/core/use-intl.esm6.js.map +1 -1
- package/dist/core/use-intl.esm7.js +2 -2
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm9.js +1 -1
- package/dist/react/IntlContext.d.ts +2 -2
- package/dist/react/IntlProvider.d.ts +7 -2
- package/dist/react/getInitializedConfig.d.ts +5 -0
- package/dist/react/use-intl.esm.js +3 -3
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +1 -1
- package/dist/react/use-intl.esm2.js +21 -3
- package/dist/react/use-intl.esm2.js.map +1 -1
- package/dist/react/use-intl.esm3.js +3 -28
- package/dist/react/use-intl.esm3.js.map +1 -1
- package/dist/react/use-intl.esm5.js +3 -20
- package/dist/react/use-intl.esm5.js.map +1 -1
- package/dist/react/use-intl.esm6.js +19 -20
- package/dist/react/use-intl.esm6.js.map +1 -1
- package/dist/react/use-intl.esm7.js +28 -3
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js +3 -30
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +30 -3
- package/dist/react/use-intl.esm9.js.map +1 -1
- package/dist/react/useFormatter.d.ts +1 -1
- package/dist/react/useIntl.d.ts +2 -2
- package/dist/react/useIntlContext.d.ts +1 -1
- package/dist/src/core/{IntlConfiguration.d.ts → IntlConfig.d.ts} +12 -5
- package/dist/src/core/IntlConfig.js +2 -0
- package/dist/src/core/IntlConfig.js.map +1 -0
- package/dist/src/core/createBaseTranslator.d.ts +2 -2
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createTranslator.d.ts +3 -3
- package/dist/src/core/createTranslatorImpl.d.ts +2 -2
- package/dist/src/core/createTranslatorImpl.js.map +1 -1
- package/dist/src/react/IntlContext.d.ts +2 -2
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlProvider.d.ts +7 -2
- package/dist/src/react/IntlProvider.js +2 -2
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/getInitializedConfig.d.ts +5 -0
- package/dist/src/react/{getIntlContextValue.js → getInitializedConfig.js} +2 -2
- package/dist/src/react/getInitializedConfig.js.map +1 -0
- package/dist/src/react/useIntl.d.ts +1 -1
- package/dist/src/react/useIntl.js +1 -1
- package/dist/src/react/useIntl.js.map +1 -1
- package/dist/src/react/useIntlContext.d.ts +1 -1
- package/dist/use-intl.cjs.development.js +3 -3
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +9 -9
- package/package.json +3 -2
- package/src/core/{IntlConfiguration.tsx → IntlConfig.tsx} +14 -6
- package/src/core/createBaseTranslator.tsx +7 -8
- package/src/core/createTranslator.tsx +3 -3
- package/src/core/createTranslatorImpl.tsx +8 -6
- package/src/react/IntlContext.tsx +2 -2
- package/src/react/IntlProvider.tsx +9 -5
- package/src/react/{getIntlContextValue.tsx → getInitializedConfig.tsx} +9 -4
- package/src/react/useIntl.tsx +1 -1
- package/CHANGELOG.md +0 -542
- package/dist/react/IntlContextValue.d.ts +0 -19
- package/dist/react/IntlProviderProps.d.ts +0 -15
- package/dist/react/getIntlContextValue.d.ts +0 -13
- package/dist/src/core/IntlConfiguration.js +0 -2
- package/dist/src/core/IntlConfiguration.js.map +0 -1
- package/dist/src/react/IntlContextValue.d.ts +0 -19
- package/dist/src/react/IntlContextValue.js +0 -2
- package/dist/src/react/IntlContextValue.js.map +0 -1
- package/dist/src/react/IntlProviderProps.d.ts +0 -15
- package/dist/src/react/IntlProviderProps.js +0 -2
- package/dist/src/react/IntlProviderProps.js.map +0 -1
- package/dist/src/react/getIntlContextValue.d.ts +0 -13
- package/dist/src/react/getIntlContextValue.js.map +0 -1
- package/src/react/IntlContextValue.tsx +0 -21
- 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
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
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 {
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
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
|
-
}:
|
|
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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
2
|
+
import {InitializedIntlConfig} from '../core/IntlConfig';
|
|
3
3
|
|
|
4
|
-
const IntlContext = createContext<
|
|
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
|
|
4
|
-
import getIntlContextValue from './getIntlContextValue';
|
|
4
|
+
import getInitializedConfig from './getInitializedConfig';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
type Props = IntlConfig & {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default function IntlProvider({children, ...props}: Props) {
|
|
7
11
|
return (
|
|
8
|
-
<IntlContext.Provider value={
|
|
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
|
|
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<
|
|
12
|
-
>({
|
|
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;
|
package/src/react/useIntl.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import useIntlContext from './useIntlContext';
|
|
|
4
4
|
|
|
5
5
|
let hasWarned = false;
|
|
6
6
|
|
|
7
|
-
/** @deprecated
|
|
7
|
+
/** @deprecated Switch to `useFormatter` instead. */
|
|
8
8
|
export default function useIntl() {
|
|
9
9
|
const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();
|
|
10
10
|
|