use-intl 3.25.0 → 4.0.0-beta-00a79d4
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/core.d.ts +2 -1
- package/dist/esm/development/core.js +82 -0
- package/dist/esm/development/index.js +7 -0
- package/dist/{development/createFormatter-D2v4ATzl.js → esm/development/initializeConfig-DSmAVNvj.js} +277 -129
- package/dist/esm/development/react.js +184 -0
- package/dist/esm/production/core.js +1 -0
- package/dist/esm/production/index.js +1 -0
- package/dist/esm/production/initializeConfig-BE7tJS3N.js +1 -0
- package/dist/esm/production/react.js +1 -0
- package/dist/types/{src/core → core}/AbstractIntlMessages.d.ts +3 -2
- package/dist/types/core/AppConfig.d.ts +25 -0
- package/dist/types/{src/core → core}/DateTimeFormatOptions.d.ts +1 -1
- package/dist/types/{src/core → core}/Formats.d.ts +2 -2
- package/dist/types/core/ICUArgs.d.ts +3 -0
- package/dist/types/core/ICUTags.d.ts +2 -0
- package/dist/types/{src/core → core}/IntlConfig.d.ts +6 -13
- package/dist/types/core/IntlError.d.ts +6 -0
- package/dist/types/{src/core/IntlError.d.ts → core/IntlErrorCode.d.ts} +2 -6
- package/dist/types/core/MessageKeys.d.ts +10 -0
- package/dist/types/core/TranslationValues.d.ts +9 -0
- package/dist/types/{src/core → core}/convertFormatsToIntlMessageFormat.d.ts +4 -4
- package/dist/types/{src/core → core}/createBaseTranslator.d.ts +9 -12
- package/dist/types/core/createFormatter.d.ts +28 -0
- package/dist/types/core/createTranslator.d.ts +52 -0
- package/dist/types/core/createTranslatorImpl.d.ts +17 -0
- package/dist/types/{src/core → core}/defaults.d.ts +1 -1
- package/dist/types/{src/core → core}/formatters.d.ts +1 -1
- package/dist/types/core/hasLocale.d.ts +10 -0
- package/dist/types/core/index.d.ts +20 -0
- package/dist/types/{src/core → core}/initializeConfig.d.ts +4 -4
- package/dist/types/core/types.d.ts +3 -0
- package/dist/types/{src/core → core}/validateMessages.d.ts +2 -2
- package/dist/types/core.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/{src/react → react}/IntlContext.d.ts +2 -2
- package/dist/types/react/IntlProvider.d.ts +7 -0
- package/dist/types/react/index.d.ts +7 -0
- package/dist/types/{src/react → react}/useFormatter.d.ts +1 -1
- package/dist/types/{src/react → react}/useIntlContext.d.ts +1 -1
- package/dist/types/react/useLocale.d.ts +2 -0
- package/dist/types/react/useMessages.d.ts +2 -0
- package/dist/types/react/useNow.d.ts +8 -0
- package/dist/types/react/useTimeZone.d.ts +1 -0
- package/dist/types/react/useTranslations.d.ts +12 -0
- package/dist/types/react/useTranslationsImpl.d.ts +9 -0
- package/dist/types/react.d.ts +1 -0
- package/package.json +18 -24
- package/react.d.ts +2 -1
- package/_IntlProvider.d.ts +0 -1
- package/_useLocale.d.ts +0 -1
- package/dist/_IntlProvider.js +0 -7
- package/dist/_useLocale.js +0 -7
- package/dist/core.js +0 -7
- package/dist/development/IntlContext-BKfsnzBx.js +0 -7
- package/dist/development/_IntlProvider.js +0 -61
- package/dist/development/_useLocale-0Rl9uR82.js +0 -19
- package/dist/development/_useLocale.js +0 -11
- package/dist/development/core.js +0 -69
- package/dist/development/index.js +0 -31
- package/dist/development/initializeConfig-BhfMSHP7.js +0 -185
- package/dist/development/react.js +0 -151
- package/dist/esm/IntlContext-DoS4CDM3.js +0 -1
- package/dist/esm/_IntlProvider.js +0 -1
- package/dist/esm/_useLocale-v-ZT5JoE.js +0 -1
- package/dist/esm/_useLocale.js +0 -1
- package/dist/esm/core.js +0 -1
- package/dist/esm/createFormatter-zqPbsiYR.js +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/initializeConfig-D2A8plWf.js +0 -1
- package/dist/esm/react.js +0 -1
- package/dist/index.js +0 -7
- package/dist/production/IntlContext-DcFt0tgW.js +0 -1
- package/dist/production/_IntlProvider.js +0 -1
- package/dist/production/_useLocale-CpTrqBDt.js +0 -1
- package/dist/production/_useLocale.js +0 -1
- package/dist/production/core.js +0 -1
- package/dist/production/createFormatter-CZeYe_QF.js +0 -1
- package/dist/production/index.js +0 -1
- package/dist/production/initializeConfig-AbYTngyP.js +0 -1
- package/dist/production/react.js +0 -1
- package/dist/react.js +0 -7
- package/dist/types/src/_IntlProvider.d.ts +0 -1
- package/dist/types/src/_useLocale.d.ts +0 -1
- package/dist/types/src/core/TranslationValues.d.ts +0 -6
- package/dist/types/src/core/createFormatter.d.ts +0 -27
- package/dist/types/src/core/createFormatter.test.d.ts +0 -1
- package/dist/types/src/core/createTranslator.d.ts +0 -71
- package/dist/types/src/core/createTranslator.test.d.ts +0 -1
- package/dist/types/src/core/createTranslatorImpl.d.ts +0 -17
- package/dist/types/src/core/index.d.ts +0 -18
- package/dist/types/src/core/utils/MessageKeys.d.ts +0 -5
- package/dist/types/src/core/utils/NamespaceKeys.d.ts +0 -5
- package/dist/types/src/core/utils/NestedKeyOf.d.ts +0 -4
- package/dist/types/src/core/utils/NestedValueOf.d.ts +0 -2
- package/dist/types/src/core.d.ts +0 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/react/IntlProvider.d.ts +0 -7
- package/dist/types/src/react/IntlProvider.test.d.ts +0 -1
- package/dist/types/src/react/index.d.ts +0 -7
- package/dist/types/src/react/index.test.d.ts +0 -1
- package/dist/types/src/react/useFormatter.test.d.ts +0 -1
- package/dist/types/src/react/useLocale.d.ts +0 -1
- package/dist/types/src/react/useLocale.test.d.ts +0 -1
- package/dist/types/src/react/useMessages.d.ts +0 -2
- package/dist/types/src/react/useMessages.test.d.ts +0 -1
- package/dist/types/src/react/useNow.d.ts +0 -23
- package/dist/types/src/react/useNow.test.d.ts +0 -1
- package/dist/types/src/react/useTimeZone.d.ts +0 -1
- package/dist/types/src/react/useTimeZone.test.d.ts +0 -1
- package/dist/types/src/react/useTranslations.d.ts +0 -62
- package/dist/types/src/react/useTranslations.test.d.ts +0 -1
- package/dist/types/src/react/useTranslationsImpl.d.ts +0 -9
- package/dist/types/src/react.d.ts +0 -1
- package/dist/types/test/setup.d.ts +0 -1
- /package/dist/types/{src/core → core}/NumberFormatOptions.d.ts +0 -0
- /package/dist/types/{src/core → core}/RelativeTimeFormatOptions.d.ts +0 -0
- /package/dist/types/{src/core → core}/TimeZone.d.ts +0 -0
- /package/dist/types/{src/core → core}/joinPath.d.ts +0 -0
- /package/dist/types/{src/core → core}/resolveNamespace.d.ts +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IntlContextValue } from './IntlContext';
|
|
1
|
+
import { type IntlContextValue } from './IntlContext.tsx';
|
|
2
2
|
export default function useIntlContext(): IntlContextValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTimeZone(): import("../core.tsx").Timezone | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Messages } from '../core/AppConfig.tsx';
|
|
2
|
+
import type { NamespaceKeys, NestedKeyOf } from '../core/MessageKeys.tsx';
|
|
3
|
+
import type createTranslator from '../core/createTranslator.tsx';
|
|
4
|
+
/**
|
|
5
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
6
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
7
|
+
*
|
|
8
|
+
* If no namespace is provided, all available messages are returned.
|
|
9
|
+
* The namespace can also indicate nesting by using a dot
|
|
10
|
+
* (e.g. `namespace.Component`).
|
|
11
|
+
*/
|
|
12
|
+
export default function useTranslations<NestedKey extends NamespaceKeys<Messages, NestedKeyOf<Messages>> = never>(namespace?: NestedKey): ReturnType<typeof createTranslator<Messages, NestedKey>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type AbstractIntlMessages from '../core/AbstractIntlMessages.tsx';
|
|
2
|
+
import type { NestedKeyOf } from '../core/MessageKeys.tsx';
|
|
3
|
+
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
|
|
4
|
+
<TargetKey extends unknown>(key: TargetKey, values?: import("../core.tsx").TranslationValues, formats?: import("../core.tsx").Formats): string;
|
|
5
|
+
rich: (key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode;
|
|
6
|
+
markup(key: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[0], values: import("../core.tsx").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[2]): string;
|
|
7
|
+
raw(key: string): any;
|
|
8
|
+
has(key: string): boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react/index.tsx';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-intl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta-00a79d4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "Internationalization (i18n) for React",
|
|
@@ -15,42 +15,35 @@
|
|
|
15
15
|
"test": "TZ=Europe/Berlin vitest",
|
|
16
16
|
"lint": "pnpm run lint:source && pnpm run lint:package",
|
|
17
17
|
"lint:source": "eslint src test && tsc --noEmit && pnpm run lint:prettier",
|
|
18
|
-
"lint:package": "publint && attw --pack",
|
|
18
|
+
"lint:package": "publint && attw --pack --ignore-rules=cjs-resolves-to-esm",
|
|
19
19
|
"lint:prettier": "prettier src --check",
|
|
20
20
|
"prepublishOnly": "turbo build",
|
|
21
21
|
"size": "size-limit"
|
|
22
22
|
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"typings": "./dist/types/
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/esm/production/index.js",
|
|
25
|
+
"typings": "./dist/types/index.d.ts",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
-
"types": "./dist/types/
|
|
29
|
-
"
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"development": "./dist/esm/development/index.js",
|
|
30
|
+
"default": "./dist/esm/production/index.js"
|
|
30
31
|
},
|
|
31
32
|
"./core": {
|
|
32
|
-
"types": "./core.d.ts",
|
|
33
|
-
"
|
|
33
|
+
"types": "./dist/types/core.d.ts",
|
|
34
|
+
"development": "./dist/esm/development/core.js",
|
|
35
|
+
"default": "./dist/esm/production/core.js"
|
|
34
36
|
},
|
|
35
37
|
"./react": {
|
|
36
|
-
"types": "./react.d.ts",
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"./_useLocale": {
|
|
40
|
-
"types": "./_useLocale.d.ts",
|
|
41
|
-
"default": "./dist/_useLocale.js"
|
|
42
|
-
},
|
|
43
|
-
"./_IntlProvider": {
|
|
44
|
-
"types": "./_IntlProvider.d.ts",
|
|
45
|
-
"default": "./dist/_IntlProvider.js"
|
|
38
|
+
"types": "./dist/types/react.d.ts",
|
|
39
|
+
"development": "./dist/esm/development/react.js",
|
|
40
|
+
"default": "./dist/esm/production/react.js"
|
|
46
41
|
}
|
|
47
42
|
},
|
|
48
43
|
"files": [
|
|
49
44
|
"dist",
|
|
50
45
|
"core.d.ts",
|
|
51
|
-
"react.d.ts"
|
|
52
|
-
"_useLocale.d.ts",
|
|
53
|
-
"_IntlProvider.d.ts"
|
|
46
|
+
"react.d.ts"
|
|
54
47
|
],
|
|
55
48
|
"keywords": [
|
|
56
49
|
"react",
|
|
@@ -65,10 +58,11 @@
|
|
|
65
58
|
],
|
|
66
59
|
"dependencies": {
|
|
67
60
|
"@formatjs/fast-memoize": "^2.2.0",
|
|
61
|
+
"@schummar/icu-type-parser": "1.21.5",
|
|
68
62
|
"intl-messageformat": "^10.5.14"
|
|
69
63
|
},
|
|
70
64
|
"peerDependencies": {
|
|
71
|
-
"react": "^
|
|
65
|
+
"react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0"
|
|
72
66
|
},
|
|
73
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "9c05cd576d214480f7459b2351f94cfa9e4aef85"
|
|
74
68
|
}
|
package/react.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// Needed for projects with `moduleResolution: 'node'`
|
|
2
|
+
export * from './dist/types/react.d.ts';
|
package/_IntlProvider.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dist/types/src/_IntlProvider';
|
package/_useLocale.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dist/types/src/_useLocale';
|
package/dist/_IntlProvider.js
DELETED
package/dist/_useLocale.js
DELETED
package/dist/core.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var React = require('react');
|
|
6
|
-
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
7
|
-
var IntlContext = require('./IntlContext-BKfsnzBx.js');
|
|
8
|
-
require('@formatjs/fast-memoize');
|
|
9
|
-
|
|
10
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
|
|
12
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
|
-
|
|
14
|
-
function IntlProvider(_ref) {
|
|
15
|
-
let {
|
|
16
|
-
children,
|
|
17
|
-
defaultTranslationValues,
|
|
18
|
-
formats,
|
|
19
|
-
getMessageFallback,
|
|
20
|
-
locale,
|
|
21
|
-
messages,
|
|
22
|
-
now,
|
|
23
|
-
onError,
|
|
24
|
-
timeZone
|
|
25
|
-
} = _ref;
|
|
26
|
-
// The formatter cache is released when the locale changes. For
|
|
27
|
-
// long-running apps with a persistent `IntlProvider` at the root,
|
|
28
|
-
// this can reduce the memory footprint (e.g. in React Native).
|
|
29
|
-
const cache = React.useMemo(() => {
|
|
30
|
-
return initializeConfig.createCache();
|
|
31
|
-
}, [locale]);
|
|
32
|
-
const formatters = React.useMemo(() => initializeConfig.createIntlFormatters(cache), [cache]);
|
|
33
|
-
|
|
34
|
-
// Memoizing this value helps to avoid triggering a re-render of all
|
|
35
|
-
// context consumers in case the configuration didn't change. However,
|
|
36
|
-
// if some of the non-primitive values change, a re-render will still
|
|
37
|
-
// be triggered. Note that there's no need to put `memo` on `IntlProvider`
|
|
38
|
-
// itself, because the `children` typically change on every render.
|
|
39
|
-
// There's some burden on the consumer side if it's important to reduce
|
|
40
|
-
// re-renders, put that's how React works.
|
|
41
|
-
// See: https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/#context-updates-and-render-optimizations
|
|
42
|
-
const value = React.useMemo(() => ({
|
|
43
|
-
...initializeConfig.initializeConfig({
|
|
44
|
-
locale,
|
|
45
|
-
defaultTranslationValues,
|
|
46
|
-
formats,
|
|
47
|
-
getMessageFallback,
|
|
48
|
-
messages,
|
|
49
|
-
now,
|
|
50
|
-
onError,
|
|
51
|
-
timeZone
|
|
52
|
-
}),
|
|
53
|
-
formatters,
|
|
54
|
-
cache
|
|
55
|
-
}), [cache, defaultTranslationValues, formats, formatters, getMessageFallback, locale, messages, now, onError, timeZone]);
|
|
56
|
-
return /*#__PURE__*/React__default.default.createElement(IntlContext.IntlContext.Provider, {
|
|
57
|
-
value: value
|
|
58
|
-
}, children);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
exports.IntlProvider = IntlProvider;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var IntlContext = require('./IntlContext-BKfsnzBx.js');
|
|
5
|
-
|
|
6
|
-
function useIntlContext() {
|
|
7
|
-
const context = React.useContext(IntlContext.IntlContext);
|
|
8
|
-
if (!context) {
|
|
9
|
-
throw new Error('No intl context found. Have you configured the provider? See https://next-intl-docs.vercel.app/docs/usage/configuration#client-server-components' );
|
|
10
|
-
}
|
|
11
|
-
return context;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function useLocale() {
|
|
15
|
-
return useIntlContext().locale;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.useIntlContext = useIntlContext;
|
|
19
|
-
exports.useLocale = useLocale;
|
package/dist/development/core.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
6
|
-
var createFormatter = require('./createFormatter-D2v4ATzl.js');
|
|
7
|
-
require('@formatjs/fast-memoize');
|
|
8
|
-
require('intl-messageformat');
|
|
9
|
-
require('react');
|
|
10
|
-
|
|
11
|
-
function createTranslatorImpl(_ref, namespacePrefix) {
|
|
12
|
-
let {
|
|
13
|
-
messages,
|
|
14
|
-
namespace,
|
|
15
|
-
...rest
|
|
16
|
-
} = _ref;
|
|
17
|
-
// The `namespacePrefix` is part of the type system.
|
|
18
|
-
// See the comment in the function invocation.
|
|
19
|
-
messages = messages[namespacePrefix];
|
|
20
|
-
namespace = createFormatter.resolveNamespace(namespace, namespacePrefix);
|
|
21
|
-
return createFormatter.createBaseTranslator({
|
|
22
|
-
...rest,
|
|
23
|
-
messages,
|
|
24
|
-
namespace
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Translates messages from the given namespace by using the ICU syntax.
|
|
30
|
-
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
31
|
-
*
|
|
32
|
-
* If no namespace is provided, all available messages are returned.
|
|
33
|
-
* The namespace can also indicate nesting by using a dot
|
|
34
|
-
* (e.g. `namespace.Component`).
|
|
35
|
-
*/
|
|
36
|
-
function createTranslator(_ref) {
|
|
37
|
-
let {
|
|
38
|
-
_cache = initializeConfig.createCache(),
|
|
39
|
-
_formatters = initializeConfig.createIntlFormatters(_cache),
|
|
40
|
-
getMessageFallback = initializeConfig.defaultGetMessageFallback,
|
|
41
|
-
messages,
|
|
42
|
-
namespace,
|
|
43
|
-
onError = initializeConfig.defaultOnError,
|
|
44
|
-
...rest
|
|
45
|
-
} = _ref;
|
|
46
|
-
// We have to wrap the actual function so the type inference for the optional
|
|
47
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
48
|
-
// The prefix ("!") is arbitrary.
|
|
49
|
-
return createTranslatorImpl({
|
|
50
|
-
...rest,
|
|
51
|
-
onError,
|
|
52
|
-
cache: _cache,
|
|
53
|
-
formatters: _formatters,
|
|
54
|
-
getMessageFallback,
|
|
55
|
-
// @ts-expect-error `messages` is allowed to be `undefined` here and will be handled internally
|
|
56
|
-
messages: {
|
|
57
|
-
'!': messages
|
|
58
|
-
},
|
|
59
|
-
namespace: namespace ? "!.".concat(namespace) : '!'
|
|
60
|
-
}, '!');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
exports.IntlError = initializeConfig.IntlError;
|
|
64
|
-
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
65
|
-
exports._createCache = initializeConfig.createCache;
|
|
66
|
-
exports._createIntlFormatters = initializeConfig.createIntlFormatters;
|
|
67
|
-
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
68
|
-
exports.createFormatter = createFormatter.createFormatter;
|
|
69
|
-
exports.createTranslator = createTranslator;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var initializeConfig = require('./initializeConfig-BhfMSHP7.js');
|
|
6
|
-
var core = require('./core.js');
|
|
7
|
-
var createFormatter = require('./createFormatter-D2v4ATzl.js');
|
|
8
|
-
var _IntlProvider = require('./_IntlProvider.js');
|
|
9
|
-
var react = require('./react.js');
|
|
10
|
-
var _useLocale = require('./_useLocale-0Rl9uR82.js');
|
|
11
|
-
require('@formatjs/fast-memoize');
|
|
12
|
-
require('intl-messageformat');
|
|
13
|
-
require('react');
|
|
14
|
-
require('./IntlContext-BKfsnzBx.js');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
exports.IntlError = initializeConfig.IntlError;
|
|
19
|
-
exports.IntlErrorCode = initializeConfig.IntlErrorCode;
|
|
20
|
-
exports._createCache = initializeConfig.createCache;
|
|
21
|
-
exports._createIntlFormatters = initializeConfig.createIntlFormatters;
|
|
22
|
-
exports.initializeConfig = initializeConfig.initializeConfig;
|
|
23
|
-
exports.createTranslator = core.createTranslator;
|
|
24
|
-
exports.createFormatter = createFormatter.createFormatter;
|
|
25
|
-
exports.IntlProvider = _IntlProvider.IntlProvider;
|
|
26
|
-
exports.useFormatter = react.useFormatter;
|
|
27
|
-
exports.useMessages = react.useMessages;
|
|
28
|
-
exports.useNow = react.useNow;
|
|
29
|
-
exports.useTimeZone = react.useTimeZone;
|
|
30
|
-
exports.useTranslations = react.useTranslations;
|
|
31
|
-
exports.useLocale = _useLocale.useLocale;
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fastMemoize = require('@formatjs/fast-memoize');
|
|
4
|
-
|
|
5
|
-
function _defineProperty(e, r, t) {
|
|
6
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
7
|
-
value: t,
|
|
8
|
-
enumerable: !0,
|
|
9
|
-
configurable: !0,
|
|
10
|
-
writable: !0
|
|
11
|
-
}) : e[r] = t, e;
|
|
12
|
-
}
|
|
13
|
-
function _toPrimitive(t, r) {
|
|
14
|
-
if ("object" != typeof t || !t) return t;
|
|
15
|
-
var e = t[Symbol.toPrimitive];
|
|
16
|
-
if (void 0 !== e) {
|
|
17
|
-
var i = e.call(t, r || "default");
|
|
18
|
-
if ("object" != typeof i) return i;
|
|
19
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
20
|
-
}
|
|
21
|
-
return ("string" === r ? String : Number)(t);
|
|
22
|
-
}
|
|
23
|
-
function _toPropertyKey(t) {
|
|
24
|
-
var i = _toPrimitive(t, "string");
|
|
25
|
-
return "symbol" == typeof i ? i : i + "";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let IntlErrorCode = /*#__PURE__*/function (IntlErrorCode) {
|
|
29
|
-
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
30
|
-
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
31
|
-
IntlErrorCode["ENVIRONMENT_FALLBACK"] = "ENVIRONMENT_FALLBACK";
|
|
32
|
-
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
33
|
-
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
34
|
-
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
35
|
-
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
36
|
-
return IntlErrorCode;
|
|
37
|
-
}({});
|
|
38
|
-
class IntlError extends Error {
|
|
39
|
-
constructor(code, originalMessage) {
|
|
40
|
-
let message = code;
|
|
41
|
-
if (originalMessage) {
|
|
42
|
-
message += ': ' + originalMessage;
|
|
43
|
-
}
|
|
44
|
-
super(message);
|
|
45
|
-
_defineProperty(this, "code", void 0);
|
|
46
|
-
_defineProperty(this, "originalMessage", void 0);
|
|
47
|
-
this.code = code;
|
|
48
|
-
if (originalMessage) {
|
|
49
|
-
this.originalMessage = originalMessage;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function joinPath() {
|
|
55
|
-
for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
56
|
-
parts[_key] = arguments[_key];
|
|
57
|
-
}
|
|
58
|
-
return parts.filter(Boolean).join('.');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Contains defaults that are used for all entry points into the core.
|
|
63
|
-
* See also `InitializedIntlConfiguration`.
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
function defaultGetMessageFallback(props) {
|
|
67
|
-
return joinPath(props.namespace, props.key);
|
|
68
|
-
}
|
|
69
|
-
function defaultOnError(error) {
|
|
70
|
-
console.error(error);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function createCache() {
|
|
74
|
-
return {
|
|
75
|
-
dateTime: {},
|
|
76
|
-
number: {},
|
|
77
|
-
message: {},
|
|
78
|
-
relativeTime: {},
|
|
79
|
-
pluralRules: {},
|
|
80
|
-
list: {},
|
|
81
|
-
displayNames: {}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function createMemoCache(store) {
|
|
85
|
-
return {
|
|
86
|
-
create() {
|
|
87
|
-
return {
|
|
88
|
-
get(key) {
|
|
89
|
-
return store[key];
|
|
90
|
-
},
|
|
91
|
-
set(key, value) {
|
|
92
|
-
store[key] = value;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function memoFn(fn, cache) {
|
|
99
|
-
return fastMemoize.memoize(fn, {
|
|
100
|
-
cache: createMemoCache(cache),
|
|
101
|
-
strategy: fastMemoize.strategies.variadic
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function memoConstructor(ConstructorFn, cache) {
|
|
105
|
-
return memoFn(function () {
|
|
106
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
107
|
-
args[_key] = arguments[_key];
|
|
108
|
-
}
|
|
109
|
-
return new ConstructorFn(...args);
|
|
110
|
-
}, cache);
|
|
111
|
-
}
|
|
112
|
-
function createIntlFormatters(cache) {
|
|
113
|
-
const getDateTimeFormat = memoConstructor(Intl.DateTimeFormat, cache.dateTime);
|
|
114
|
-
const getNumberFormat = memoConstructor(Intl.NumberFormat, cache.number);
|
|
115
|
-
const getPluralRules = memoConstructor(Intl.PluralRules, cache.pluralRules);
|
|
116
|
-
const getRelativeTimeFormat = memoConstructor(Intl.RelativeTimeFormat, cache.relativeTime);
|
|
117
|
-
const getListFormat = memoConstructor(Intl.ListFormat, cache.list);
|
|
118
|
-
const getDisplayNames = memoConstructor(Intl.DisplayNames, cache.displayNames);
|
|
119
|
-
return {
|
|
120
|
-
getDateTimeFormat,
|
|
121
|
-
getNumberFormat,
|
|
122
|
-
getPluralRules,
|
|
123
|
-
getRelativeTimeFormat,
|
|
124
|
-
getListFormat,
|
|
125
|
-
getDisplayNames
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
130
|
-
Object.entries(messages).forEach(_ref => {
|
|
131
|
-
let [key, messageOrMessages] = _ref;
|
|
132
|
-
if (key.includes('.')) {
|
|
133
|
-
let keyLabel = key;
|
|
134
|
-
if (parentPath) keyLabel += " (at ".concat(parentPath, ")");
|
|
135
|
-
invalidKeyLabels.push(keyLabel);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
139
|
-
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
140
|
-
validateMessagesSegment(messageOrMessages, invalidKeyLabels, joinPath(parentPath, key));
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
function validateMessages(messages, onError) {
|
|
145
|
-
const invalidKeyLabels = [];
|
|
146
|
-
validateMessagesSegment(messages, invalidKeyLabels);
|
|
147
|
-
if (invalidKeyLabels.length > 0) {
|
|
148
|
-
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 ".concat(invalidKeyLabels.length === 1 ? 'key' : 'keys', ": ").concat(invalidKeyLabels.join(', '), "\n\nIf you're migrating from a flat structure, you can convert your messages as follows:\n\nimport {set} from \"lodash\";\n\nconst input = {\n \"one.one\": \"1.1\",\n \"one.two\": \"1.2\",\n \"two.one.one\": \"2.1.1\"\n};\n\nconst output = Object.entries(input).reduce(\n (acc, [key, value]) => set(acc, key, value),\n {}\n);\n\n// Output:\n//\n// {\n// \"one\": {\n// \"one\": \"1.1\",\n// \"two\": \"1.2\"\n// },\n// \"two\": {\n// \"one\": {\n// \"one\": \"2.1.1\"\n// }\n// }\n// }\n") ));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Enhances the incoming props with defaults.
|
|
154
|
-
*/
|
|
155
|
-
function initializeConfig(_ref) {
|
|
156
|
-
let {
|
|
157
|
-
getMessageFallback,
|
|
158
|
-
messages,
|
|
159
|
-
onError,
|
|
160
|
-
...rest
|
|
161
|
-
} = _ref;
|
|
162
|
-
const finalOnError = onError || defaultOnError;
|
|
163
|
-
const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
164
|
-
{
|
|
165
|
-
if (messages) {
|
|
166
|
-
validateMessages(messages, finalOnError);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
...rest,
|
|
171
|
-
messages,
|
|
172
|
-
onError: finalOnError,
|
|
173
|
-
getMessageFallback: finalGetMessageFallback
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
exports.IntlError = IntlError;
|
|
178
|
-
exports.IntlErrorCode = IntlErrorCode;
|
|
179
|
-
exports.createCache = createCache;
|
|
180
|
-
exports.createIntlFormatters = createIntlFormatters;
|
|
181
|
-
exports.defaultGetMessageFallback = defaultGetMessageFallback;
|
|
182
|
-
exports.defaultOnError = defaultOnError;
|
|
183
|
-
exports.initializeConfig = initializeConfig;
|
|
184
|
-
exports.joinPath = joinPath;
|
|
185
|
-
exports.memoFn = memoFn;
|