@jetshop/intl 5.12.4 → 5.13.2
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/{context.js → context.ts} +0 -0
- package/index.ts +66 -0
- package/package.json +1 -1
- package/tsconfig.json +8 -0
- package/index.js +0 -21
|
File without changes
|
package/index.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import IntlContext from '@jetshop/intl/context';
|
|
3
|
+
import formatMessage from 'format-message/types';
|
|
4
|
+
|
|
5
|
+
export const useIntl = () => useContext(IntlContext);
|
|
6
|
+
|
|
7
|
+
type FormatMsgType = typeof formatMessage;
|
|
8
|
+
type FormatMsgTypes =
|
|
9
|
+
| FormatMsgType
|
|
10
|
+
| FormatMsgType['rich']
|
|
11
|
+
| FormatMsgType['number']
|
|
12
|
+
| FormatMsgType['date']
|
|
13
|
+
| FormatMsgType['time']
|
|
14
|
+
| FormatMsgType['select']
|
|
15
|
+
| FormatMsgType['plural']
|
|
16
|
+
| FormatMsgType['selectordinal']
|
|
17
|
+
| FormatMsgType['custom'];
|
|
18
|
+
|
|
19
|
+
type WithContextFormatMessage = ReturnType<typeof withContextFormatMessage>;
|
|
20
|
+
|
|
21
|
+
interface TranslateType extends WithContextFormatMessage {
|
|
22
|
+
rich: (
|
|
23
|
+
...args: Parameters<FormatMsgType['rich']>
|
|
24
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
25
|
+
number: (
|
|
26
|
+
...args: Parameters<FormatMsgType['number']>
|
|
27
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
28
|
+
date: (
|
|
29
|
+
...args: Parameters<FormatMsgType['date']>
|
|
30
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
31
|
+
time: (
|
|
32
|
+
...args: Parameters<FormatMsgType['time']>
|
|
33
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
34
|
+
select: (
|
|
35
|
+
...args: Parameters<FormatMsgType['select']>
|
|
36
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
37
|
+
plural: (
|
|
38
|
+
...args: Parameters<FormatMsgType['plural']>
|
|
39
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
40
|
+
selectordinal: (
|
|
41
|
+
...args: Parameters<FormatMsgType['selectordinal']>
|
|
42
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
43
|
+
custom: (
|
|
44
|
+
...args: Parameters<FormatMsgType['custom']>
|
|
45
|
+
) => ReturnType<WithContextFormatMessage>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const withContextFormatMessage =
|
|
49
|
+
(callback: (t: FormatMsgType) => ReturnType<FormatMsgTypes>) =>
|
|
50
|
+
(...args: Parameters<FormatMsgTypes>) =>
|
|
51
|
+
React.createElement(IntlContext.Consumer, null, (t: FormatMsgType) =>
|
|
52
|
+
callback(t)(...args)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const Translate = withContextFormatMessage((t) => t) as TranslateType;
|
|
56
|
+
Translate.rich = withContextFormatMessage((t) => t.rich);
|
|
57
|
+
Translate.number = withContextFormatMessage((t) => t.number);
|
|
58
|
+
Translate.date = withContextFormatMessage((t) => t.date);
|
|
59
|
+
Translate.time = withContextFormatMessage((t) => t.time);
|
|
60
|
+
Translate.select = withContextFormatMessage((t) => t.select);
|
|
61
|
+
Translate.plural = withContextFormatMessage((t) => t.plural);
|
|
62
|
+
Translate.selectordinal = withContextFormatMessage((t) => t.selectordinal);
|
|
63
|
+
Translate.custom = withContextFormatMessage((t) => t.custom);
|
|
64
|
+
|
|
65
|
+
export const Intl = IntlContext.Consumer;
|
|
66
|
+
export default Translate;
|
package/package.json
CHANGED
package/tsconfig.json
ADDED
package/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import IntlContext from '@jetshop/intl/context';
|
|
3
|
-
|
|
4
|
-
export const useIntl = () => useContext(IntlContext);
|
|
5
|
-
|
|
6
|
-
const withContextFormatMessage =
|
|
7
|
-
(callback) =>
|
|
8
|
-
(...args) =>
|
|
9
|
-
React.createElement(IntlContext.Consumer, {}, (t) => callback(t)(...args));
|
|
10
|
-
|
|
11
|
-
const Translate = withContextFormatMessage((t) => t);
|
|
12
|
-
Translate.rich = withContextFormatMessage((t) => t.rich);
|
|
13
|
-
Translate.number = withContextFormatMessage((t) => t.number);
|
|
14
|
-
Translate.date = withContextFormatMessage((t) => t.date);
|
|
15
|
-
Translate.time = withContextFormatMessage((t) => t.time);
|
|
16
|
-
Translate.select = withContextFormatMessage((t) => t.select);
|
|
17
|
-
Translate.plural = withContextFormatMessage((t) => t.plural);
|
|
18
|
-
Translate.selectordinal = withContextFormatMessage((t) => t.selectordinal);
|
|
19
|
-
Translate.custom = withContextFormatMessage((t) => t.custom);
|
|
20
|
-
export const Intl = IntlContext.Consumer;
|
|
21
|
-
export default Translate;
|