use-intl 2.7.2-alpha.1 → 2.7.3
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 +7 -7
- package/dist/use-intl.esm10.js +26 -9
- package/dist/use-intl.esm10.js.map +1 -1
- package/dist/use-intl.esm11.js +12 -3
- package/dist/use-intl.esm11.js.map +1 -1
- package/dist/use-intl.esm12.js +2 -2
- package/dist/use-intl.esm2.js +39 -146
- package/dist/use-intl.esm2.js.map +1 -1
- package/dist/use-intl.esm3.js +20 -42
- package/dist/use-intl.esm3.js.map +1 -1
- package/dist/use-intl.esm4.js +152 -31
- package/dist/use-intl.esm4.js.map +1 -1
- package/dist/use-intl.esm5.js +4 -46
- package/dist/use-intl.esm5.js.map +1 -1
- package/dist/use-intl.esm6.js +49 -41
- package/dist/use-intl.esm6.js.map +1 -1
- package/dist/use-intl.esm7.js +4 -4
- package/dist/use-intl.esm7.js.map +1 -1
- package/dist/use-intl.esm8.js +39 -5
- package/dist/use-intl.esm8.js.map +1 -1
- package/dist/use-intl.esm9.js +3 -29
- package/dist/use-intl.esm9.js.map +1 -1
- package/package.json +2 -2
- package/src/useTranslations.tsx +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm5.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../src/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm6.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.esm6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm6.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.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.esm7.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import useIntlContext from './use-intl.
|
|
1
|
+
import useIntlContext from './use-intl.esm11.js';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
return useIntlContext().
|
|
3
|
+
function useTimeZone() {
|
|
4
|
+
return useIntlContext().timeZone;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { useTimeZone as default };
|
|
8
8
|
//# sourceMappingURL=use-intl.esm7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm7.js","sources":["../src/
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../src/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
|
package/dist/use-intl.esm8.js
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from './_virtual/use-intl.esm.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return useIntlContext().timeZone;
|
|
5
|
-
}
|
|
3
|
+
var IntlErrorCode;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
(function (IntlErrorCode) {
|
|
6
|
+
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
7
|
+
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
8
|
+
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
9
|
+
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
10
|
+
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
11
|
+
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
12
|
+
})(IntlErrorCode || (IntlErrorCode = {}));
|
|
13
|
+
|
|
14
|
+
var IntlError = /*#__PURE__*/function (_Error) {
|
|
15
|
+
_inheritsLoose(IntlError, _Error);
|
|
16
|
+
|
|
17
|
+
function IntlError(code, originalMessage) {
|
|
18
|
+
var _this;
|
|
19
|
+
|
|
20
|
+
var message = code;
|
|
21
|
+
|
|
22
|
+
if (originalMessage) {
|
|
23
|
+
message += ': ' + originalMessage;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_this = _Error.call(this, message) || this;
|
|
27
|
+
_this.code = void 0;
|
|
28
|
+
_this.originalMessage = void 0;
|
|
29
|
+
_this.code = code;
|
|
30
|
+
|
|
31
|
+
if (originalMessage) {
|
|
32
|
+
_this.originalMessage = originalMessage;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return _this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return IntlError;
|
|
39
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
40
|
+
|
|
41
|
+
export { IntlErrorCode, IntlError as default };
|
|
8
42
|
//# 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/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage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9.js
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
-
var key = _ref[0],
|
|
6
|
-
messageOrMessages = _ref[1];
|
|
3
|
+
var IntlContext = /*#__PURE__*/createContext(undefined);
|
|
7
4
|
|
|
8
|
-
|
|
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 };
|
|
5
|
+
export { IntlContext as default };
|
|
32
6
|
//# 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/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport IntlError from './IntlError';\nimport {RichTranslationValues} from './TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
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": "96716718eccdc05566b080c55863d7b7e9a0bfdc"
|
|
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';
|
|
@@ -103,16 +102,7 @@ export default function useTranslations<
|
|
|
103
102
|
): any;
|
|
104
103
|
} {
|
|
105
104
|
const context = useIntlContext();
|
|
106
|
-
|
|
107
105
|
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
106
|
|
|
117
107
|
// We have to wrap the actual hook so the type inference for the optional
|
|
118
108
|
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|