use-intl 2.7.2 → 2.7.4-alpha.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/dist/use-intl.cjs.development.js +1 -8
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +6 -6
- package/dist/use-intl.esm10.js +3 -29
- package/dist/use-intl.esm10.js.map +1 -1
- package/dist/use-intl.esm11.js +1 -1
- package/dist/use-intl.esm12.js +1 -1
- package/dist/use-intl.esm2.js +2 -2
- package/dist/use-intl.esm3.js +151 -30
- package/dist/use-intl.esm3.js.map +1 -1
- package/dist/use-intl.esm4.js +3 -150
- package/dist/use-intl.esm4.js.map +1 -1
- package/dist/use-intl.esm5.js +39 -5
- package/dist/use-intl.esm5.js.map +1 -1
- package/dist/use-intl.esm6.js +3 -45
- package/dist/use-intl.esm6.js.map +1 -1
- package/dist/use-intl.esm7.js +21 -3
- package/dist/use-intl.esm7.js.map +1 -1
- package/dist/use-intl.esm8.js +49 -41
- package/dist/use-intl.esm8.js.map +1 -1
- package/dist/use-intl.esm9.js +29 -3
- package/dist/use-intl.esm9.js.map +1 -1
- package/dist/useTranslations.d.ts +19 -7
- package/package.json +2 -2
- package/src/useTranslations.tsx +11 -41
package/dist/use-intl.esm8.js
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
3
|
+
|
|
4
|
+
function getNow() {
|
|
5
|
+
return new Date();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Reading the current date via `new Date()` in components should be avoided, as
|
|
9
|
+
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
10
|
+
* hook can be used.
|
|
11
|
+
*
|
|
12
|
+
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
13
|
+
* is specified, the value will be updated based on the interval.
|
|
14
|
+
*
|
|
15
|
+
* You can however also return a static value from this hook, if you
|
|
16
|
+
* configure the `now` parameter on the context provider. Note however,
|
|
17
|
+
* that if `updateInterval` is configured in this case, the component
|
|
18
|
+
* will initialize with the global value, but will afterwards update
|
|
19
|
+
* continuously based on the interval.
|
|
20
|
+
*
|
|
21
|
+
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
22
|
+
* testing, an environment parameter can be passed to the `now` parameter
|
|
23
|
+
* of the provider to mock this to a static value.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function useNow(options) {
|
|
28
|
+
var updateInterval = options == null ? void 0 : options.updateInterval;
|
|
29
|
+
|
|
30
|
+
var _useIntlContext = useIntlContext(),
|
|
31
|
+
globalNow = _useIntlContext.now;
|
|
32
|
+
|
|
33
|
+
var _useState = useState(globalNow || getNow()),
|
|
34
|
+
now = _useState[0],
|
|
35
|
+
setNow = _useState[1];
|
|
36
|
+
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
if (!updateInterval) return;
|
|
39
|
+
var intervalId = setInterval(function () {
|
|
40
|
+
setNow(getNow());
|
|
41
|
+
}, updateInterval);
|
|
42
|
+
return function () {
|
|
43
|
+
clearInterval(intervalId);
|
|
44
|
+
};
|
|
45
|
+
}, [globalNow, updateInterval]);
|
|
46
|
+
return now;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { useNow as default };
|
|
42
50
|
//# sourceMappingURL=use-intl.esm8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm8.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.js","sources":["../src/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm9.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm5.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
4
|
+
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
+
var key = _ref[0],
|
|
6
|
+
messageOrMessages = _ref[1];
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
if (key.includes('.')) {
|
|
9
|
+
var keyLabel = key;
|
|
10
|
+
if (parentPath) keyLabel += " (at " + parentPath + ")";
|
|
11
|
+
invalidKeyLabels.push(keyLabel);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
15
|
+
validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
|
|
16
|
+
return part != null;
|
|
17
|
+
}).join('.'));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validateMessages(messages, onError) {
|
|
23
|
+
var invalidKeyLabels = [];
|
|
24
|
+
validateMessagesSegment(messages, invalidKeyLabels);
|
|
25
|
+
|
|
26
|
+
if (invalidKeyLabels.length > 0) {
|
|
27
|
+
onError(new IntlError(IntlErrorCode.INVALID_KEY, "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ')));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { validateMessages as default };
|
|
6
32
|
//# sourceMappingURL=use-intl.esm9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm9.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../src/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\\n\\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}`\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY"],"mappings":";;AAGA,SAASA,uBAAT,CACEC,QADF,EAEEC,gBAFF,EAGEC,UAHF,EAGqB;AAEnBC,EAAAA,MAAM,CAACC,OAAP,CAAeJ,QAAf,CAAyBK,CAAAA,OAAzB,CAAiC,UAA6B,IAAA,EAAA;AAAA,IAAA,IAA3BC,GAA2B,GAAA,IAAA,CAAA,CAAA,CAAA;AAAA,QAAtBC,iBAAsB,GAAA,IAAA,CAAA,CAAA,CAAA,CAAA;;AAC5D,IAAA,IAAID,GAAG,CAACE,QAAJ,CAAa,GAAb,CAAJ,EAAuB;AACrB,MAAIC,IAAAA,QAAQ,GAAGH,GAAf,CAAA;AACA,MAAA,IAAIJ,UAAJ,EAAgBO,QAAQ,IAAA,OAAA,GAAYP,UAAZ,GAAR,GAAA,CAAA;AAChBD,MAAAA,gBAAgB,CAACS,IAAjB,CAAsBD,QAAtB,CAAA,CAAA;AACD,KAAA;;AAED,IAAIF,IAAAA,iBAAiB,IAAI,IAArB,IAA6B,OAAOA,iBAAP,KAA6B,QAA9D,EAAwE;AACtER,MAAAA,uBAAuB,CACrBQ,iBADqB,EAErBN,gBAFqB,EAGrB,CAACC,UAAD,EAAaI,GAAb,CAAA,CAAkBK,MAAlB,CAAyB,UAACC,IAAD,EAAA;AAAA,QAAUA,OAAAA,IAAI,IAAI,IAAlB,CAAA;AAAA,OAAzB,CAAiDC,CAAAA,IAAjD,CAAsD,GAAtD,CAHqB,CAAvB,CAAA;AAKD,KAAA;AACF,GAdD,CAAA,CAAA;AAeD,CAAA;;AAEa,SAAUC,gBAAV,CACZd,QADY,EAEZe,OAFY,EAEuB;AAEnC,EAAMd,IAAAA,gBAAgB,GAAkB,EAAxC,CAAA;AACAF,EAAAA,uBAAuB,CAACC,QAAD,EAAWC,gBAAX,CAAvB,CAAA;;AAEA,EAAA,IAAIA,gBAAgB,CAACe,MAAjB,GAA0B,CAA9B,EAAiC;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAJ,CACEC,aAAa,CAACC,WADhB,EAAA,2JAAA,IAGIlB,gBAAgB,CAACe,MAAjB,KAA4B,CAA5B,GAAgC,KAAhC,GAAwC,MAH5C,CAIOf,GAAAA,IAAAA,GAAAA,gBAAgB,CAACY,IAAjB,CAAsB,IAAtB,CAJP,CADK,CAAP,CAAA;AAQD,GAAA;AACF;;;;"}
|
|
@@ -13,20 +13,32 @@ import NestedValueOf from './utils/NestedValueOf';
|
|
|
13
13
|
* The namespace can also indicate nesting by using a dot
|
|
14
14
|
* (e.g. `namespace.Component`).
|
|
15
15
|
*/
|
|
16
|
-
export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages
|
|
16
|
+
export default function useTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(namespace?: NestedKey): {
|
|
17
17
|
<TargetKey extends MessageKeys<NestedValueOf<{
|
|
18
18
|
'!': IntlMessages;
|
|
19
|
-
},
|
|
19
|
+
}, [
|
|
20
|
+
NestedKey
|
|
21
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
20
22
|
'!': IntlMessages;
|
|
21
|
-
},
|
|
23
|
+
}, [
|
|
24
|
+
NestedKey
|
|
25
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
|
|
22
26
|
rich<TargetKey extends MessageKeys<NestedValueOf<{
|
|
23
27
|
'!': IntlMessages;
|
|
24
|
-
},
|
|
28
|
+
}, [
|
|
29
|
+
NestedKey
|
|
30
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
25
31
|
'!': IntlMessages;
|
|
26
|
-
},
|
|
32
|
+
}, [
|
|
33
|
+
NestedKey
|
|
34
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey, values?: RichTranslationValues, formats?: Partial<Formats>): string | ReactElement | ReactNodeArray;
|
|
27
35
|
raw<TargetKey extends MessageKeys<NestedValueOf<{
|
|
28
36
|
'!': IntlMessages;
|
|
29
|
-
},
|
|
37
|
+
}, [
|
|
38
|
+
NestedKey
|
|
39
|
+
] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
|
|
30
40
|
'!': IntlMessages;
|
|
31
|
-
},
|
|
41
|
+
}, [
|
|
42
|
+
NestedKey
|
|
43
|
+
] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
|
|
32
44
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "2.7.2",
|
|
3
|
+
"version": "2.7.4-alpha.2",
|
|
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.",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=10"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6683168cc739943b8a3c7e86585fa614679440e6"
|
|
63
63
|
}
|
package/src/useTranslations.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {ReactElement, ReactNodeArray} from 'react';
|
|
2
2
|
import Formats from './Formats';
|
|
3
|
-
import IntlError, {IntlErrorCode} from './IntlError';
|
|
4
3
|
import TranslationValues, {RichTranslationValues} from './TranslationValues';
|
|
5
4
|
import useIntlContext from './useIntlContext';
|
|
6
5
|
import useTranslationsImpl from './useTranslationsImpl';
|
|
@@ -18,7 +17,10 @@ import NestedValueOf from './utils/NestedValueOf';
|
|
|
18
17
|
* (e.g. `namespace.Component`).
|
|
19
18
|
*/
|
|
20
19
|
export default function useTranslations<
|
|
21
|
-
NestedKey extends NamespaceKeys<
|
|
20
|
+
NestedKey extends NamespaceKeys<
|
|
21
|
+
IntlMessages,
|
|
22
|
+
NestedKeyOf<IntlMessages>
|
|
23
|
+
> = never
|
|
22
24
|
>(
|
|
23
25
|
namespace?: NestedKey
|
|
24
26
|
): // Explicitly defining the return type is necessary as TypeScript would get it wrong
|
|
@@ -28,19 +30,12 @@ export default function useTranslations<
|
|
|
28
30
|
TargetKey extends MessageKeys<
|
|
29
31
|
NestedValueOf<
|
|
30
32
|
{'!': IntlMessages},
|
|
31
|
-
|
|
32
|
-
? '!'
|
|
33
|
-
: `!.${NestedKey}`
|
|
33
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
34
34
|
>,
|
|
35
35
|
NestedKeyOf<
|
|
36
36
|
NestedValueOf<
|
|
37
37
|
{'!': IntlMessages},
|
|
38
|
-
|
|
39
|
-
IntlMessages,
|
|
40
|
-
NestedKeyOf<IntlMessages>
|
|
41
|
-
> extends NestedKey
|
|
42
|
-
? '!'
|
|
43
|
-
: `!.${NestedKey}`
|
|
38
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
44
39
|
>
|
|
45
40
|
>
|
|
46
41
|
>
|
|
@@ -55,19 +50,12 @@ export default function useTranslations<
|
|
|
55
50
|
TargetKey extends MessageKeys<
|
|
56
51
|
NestedValueOf<
|
|
57
52
|
{'!': IntlMessages},
|
|
58
|
-
|
|
59
|
-
? '!'
|
|
60
|
-
: `!.${NestedKey}`
|
|
53
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
61
54
|
>,
|
|
62
55
|
NestedKeyOf<
|
|
63
56
|
NestedValueOf<
|
|
64
57
|
{'!': IntlMessages},
|
|
65
|
-
|
|
66
|
-
IntlMessages,
|
|
67
|
-
NestedKeyOf<IntlMessages>
|
|
68
|
-
> extends NestedKey
|
|
69
|
-
? '!'
|
|
70
|
-
: `!.${NestedKey}`
|
|
58
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
71
59
|
>
|
|
72
60
|
>
|
|
73
61
|
>
|
|
@@ -82,19 +70,12 @@ export default function useTranslations<
|
|
|
82
70
|
TargetKey extends MessageKeys<
|
|
83
71
|
NestedValueOf<
|
|
84
72
|
{'!': IntlMessages},
|
|
85
|
-
|
|
86
|
-
? '!'
|
|
87
|
-
: `!.${NestedKey}`
|
|
73
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
88
74
|
>,
|
|
89
75
|
NestedKeyOf<
|
|
90
76
|
NestedValueOf<
|
|
91
77
|
{'!': IntlMessages},
|
|
92
|
-
|
|
93
|
-
IntlMessages,
|
|
94
|
-
NestedKeyOf<IntlMessages>
|
|
95
|
-
> extends NestedKey
|
|
96
|
-
? '!'
|
|
97
|
-
: `!.${NestedKey}`
|
|
78
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
98
79
|
>
|
|
99
80
|
>
|
|
100
81
|
>
|
|
@@ -103,25 +84,14 @@ export default function useTranslations<
|
|
|
103
84
|
): any;
|
|
104
85
|
} {
|
|
105
86
|
const context = useIntlContext();
|
|
106
|
-
|
|
107
87
|
const messages = context.messages as IntlMessages;
|
|
108
|
-
if (!messages) {
|
|
109
|
-
const intlError = new IntlError(
|
|
110
|
-
IntlErrorCode.MISSING_MESSAGE,
|
|
111
|
-
__DEV__ ? `No messages were configured on the provider.` : undefined
|
|
112
|
-
);
|
|
113
|
-
context.onError(intlError);
|
|
114
|
-
throw intlError;
|
|
115
|
-
}
|
|
116
88
|
|
|
117
89
|
// We have to wrap the actual hook so the type inference for the optional
|
|
118
90
|
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
119
91
|
// The prefix ("!"") is arbitrary, but we have to use some.
|
|
120
92
|
return useTranslationsImpl<
|
|
121
93
|
{'!': IntlMessages},
|
|
122
|
-
|
|
123
|
-
? '!'
|
|
124
|
-
: `!.${NestedKey}`
|
|
94
|
+
[NestedKey] extends [never] ? '!' : `!.${NestedKey}`
|
|
125
95
|
>(
|
|
126
96
|
{'!': messages},
|
|
127
97
|
// @ts-ignore
|