use-intl 2.9.2-alpha.0 → 2.10.0-alpha.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/CHANGELOG.md +463 -0
- package/dist/core/use-intl.esm.js +140 -27
- package/dist/core/use-intl.esm.js.map +1 -1
- package/dist/core/use-intl.esm2.js +27 -140
- package/dist/core/use-intl.esm2.js.map +1 -1
- package/dist/core/use-intl.esm3.js +2 -2
- package/dist/core/use-intl.esm4.js +12 -56
- 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 +7 -29
- package/dist/core/use-intl.esm6.js.map +1 -1
- package/dist/core/use-intl.esm7.js +9 -9
- package/dist/core/use-intl.esm7.js.map +1 -1
- package/dist/core/use-intl.esm8.js +29 -7
- package/dist/core/use-intl.esm8.js.map +1 -1
- package/dist/react/IntlContext.d.ts +2 -19
- package/dist/react/IntlContextValue.d.ts +19 -0
- package/dist/react/IntlProvider.d.ts +2 -16
- package/dist/react/IntlProviderProps.d.ts +15 -0
- package/dist/react/getIntlContextValue.d.ts +18 -0
- package/dist/react/use-intl.esm.js +12 -21
- package/dist/react/use-intl.esm.js.map +1 -1
- package/dist/react/use-intl.esm10.js +44 -0
- package/dist/react/use-intl.esm10.js.map +1 -0
- package/dist/react/use-intl.esm2.js +2 -2
- package/dist/react/use-intl.esm3.js +20 -30
- package/dist/react/use-intl.esm3.js.map +1 -1
- package/dist/react/use-intl.esm4.js +46 -4
- package/dist/react/use-intl.esm4.js.map +1 -1
- package/dist/react/use-intl.esm5.js +1 -1
- package/dist/react/use-intl.esm6.js +4 -46
- package/dist/react/use-intl.esm6.js.map +1 -1
- package/dist/react/use-intl.esm7.js +3 -12
- package/dist/react/use-intl.esm7.js.map +1 -1
- package/dist/react/use-intl.esm8.js +30 -3
- package/dist/react/use-intl.esm8.js.map +1 -1
- package/dist/react/use-intl.esm9.js +9 -38
- package/dist/react/use-intl.esm9.js.map +1 -1
- package/dist/react/useIntlContext.d.ts +1 -1
- package/dist/src/core/AbstractIntlMessages.d.ts +9 -0
- package/dist/src/core/AbstractIntlMessages.js +2 -0
- package/dist/src/core/AbstractIntlMessages.js.map +1 -0
- package/dist/src/core/DateTimeFormatOptions.d.ts +72 -0
- package/dist/src/core/DateTimeFormatOptions.js +3 -0
- package/dist/src/core/DateTimeFormatOptions.js.map +1 -0
- package/dist/src/core/Formats.d.ts +7 -0
- package/dist/src/core/Formats.js +2 -0
- package/dist/src/core/Formats.js.map +1 -0
- package/dist/src/core/IntlConfiguration.d.ts +46 -0
- package/dist/src/core/IntlConfiguration.js +2 -0
- package/dist/src/core/IntlConfiguration.js.map +1 -0
- package/dist/src/core/IntlError.d.ts +13 -0
- package/dist/src/core/IntlError.js +23 -0
- package/dist/src/core/IntlError.js.map +1 -0
- package/dist/src/core/IntlMessages.d.ts +2 -0
- package/dist/src/core/IntlMessages.js +4 -0
- package/dist/src/core/IntlMessages.js.map +1 -0
- package/dist/src/core/NumberFormatOptions.d.ts +2 -0
- package/dist/src/core/NumberFormatOptions.js +2 -0
- package/dist/src/core/NumberFormatOptions.js.map +1 -0
- package/dist/src/core/TranslationValues.d.ts +5 -0
- package/dist/src/core/TranslationValues.js +2 -0
- package/dist/src/core/TranslationValues.js.map +1 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +10 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.js +31 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -0
- package/dist/src/core/createBaseTranslator.d.ts +26 -0
- package/dist/src/core/createBaseTranslator.js +185 -0
- package/dist/src/core/createBaseTranslator.js.map +1 -0
- package/dist/src/core/createIntl.d.ts +17 -0
- package/dist/src/core/createIntl.js +126 -0
- package/dist/src/core/createIntl.js.map +1 -0
- package/dist/src/core/createTranslator.d.ts +48 -0
- package/dist/src/core/createTranslator.js +24 -0
- package/dist/src/core/createTranslator.js.map +1 -0
- package/dist/src/core/createTranslatorImpl.d.ts +14 -0
- package/dist/src/core/createTranslatorImpl.js +43 -0
- package/dist/src/core/createTranslatorImpl.js.map +1 -0
- package/dist/src/core/defaults.d.ts +11 -0
- package/dist/src/core/defaults.js +11 -0
- package/dist/src/core/defaults.js.map +1 -0
- package/dist/src/core/index.d.ts +8 -0
- package/dist/src/core/index.js +4 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/resolveNamespace.d.ts +5 -0
- package/dist/src/core/resolveNamespace.js +10 -0
- package/dist/src/core/resolveNamespace.js.map +1 -0
- package/dist/src/core/utils/MessageKeys.d.ts +5 -0
- package/dist/src/core/utils/MessageKeys.js +2 -0
- package/dist/src/core/utils/MessageKeys.js.map +1 -0
- package/dist/src/core/utils/NamespaceKeys.d.ts +5 -0
- package/dist/src/core/utils/NamespaceKeys.js +2 -0
- package/dist/src/core/utils/NamespaceKeys.js.map +1 -0
- package/dist/src/core/utils/NestedKeyOf.d.ts +4 -0
- package/dist/src/core/utils/NestedKeyOf.js +2 -0
- package/dist/src/core/utils/NestedKeyOf.js.map +1 -0
- package/dist/src/core/utils/NestedValueOf.d.ts +2 -0
- package/dist/src/core/utils/NestedValueOf.js +2 -0
- package/dist/src/core/utils/NestedValueOf.js.map +1 -0
- package/dist/src/core/validateMessages.d.ts +3 -0
- package/dist/src/core/validateMessages.js +22 -0
- package/dist/src/core/validateMessages.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/react/IntlContext.d.ts +4 -0
- package/dist/src/react/IntlContext.js +4 -0
- package/dist/src/react/IntlContext.js.map +1 -0
- package/dist/src/react/IntlContextValue.d.ts +19 -0
- package/dist/src/react/IntlContextValue.js +2 -0
- package/dist/src/react/IntlContextValue.js.map +1 -0
- package/dist/src/react/IntlProvider.d.ts +2 -0
- package/dist/src/react/IntlProvider.js +7 -0
- package/dist/src/react/IntlProvider.js.map +1 -0
- package/dist/src/react/IntlProviderProps.d.ts +15 -0
- package/dist/src/react/IntlProviderProps.js +2 -0
- package/dist/src/react/IntlProviderProps.js.map +1 -0
- package/dist/src/react/getIntlContextValue.d.ts +18 -0
- package/dist/src/react/getIntlContextValue.js +21 -0
- package/dist/src/react/getIntlContextValue.js.map +1 -0
- package/dist/src/react/index.d.ts +6 -0
- package/dist/src/react/index.js +7 -0
- package/dist/src/react/index.js.map +1 -0
- package/dist/src/react/useIntl.d.ts +5 -0
- package/dist/src/react/useIntl.js +14 -0
- package/dist/src/react/useIntl.js.map +1 -0
- package/dist/src/react/useIntlContext.d.ts +1 -0
- package/dist/src/react/useIntlContext.js +12 -0
- package/dist/src/react/useIntlContext.js.map +1 -0
- package/dist/src/react/useLocale.d.ts +1 -0
- package/dist/src/react/useLocale.js +5 -0
- package/dist/src/react/useLocale.js.map +1 -0
- package/dist/src/react/useNow.d.ts +23 -0
- package/dist/src/react/useNow.js +40 -0
- package/dist/src/react/useNow.js.map +1 -0
- package/dist/src/react/useTimeZone.d.ts +1 -0
- package/dist/src/react/useTimeZone.js +5 -0
- package/dist/src/react/useTimeZone.js.map +1 -0
- package/dist/src/react/useTranslations.d.ts +44 -0
- package/dist/src/react/useTranslations.js +21 -0
- package/dist/src/react/useTranslations.js.map +1 -0
- package/dist/src/react/useTranslationsImpl.d.ts +8 -0
- package/dist/src/react/useTranslationsImpl.js +35 -0
- package/dist/src/react/useTranslationsImpl.js.map +1 -0
- package/dist/use-intl.cjs.development.js +37 -28
- 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/package.json +6 -5
- package/src/core/createBaseTranslator.tsx +11 -7
- package/src/core/createIntl.tsx +2 -2
- package/src/core/createTranslatorImpl.tsx +1 -1
- package/src/react/IntlContext.tsx +2 -20
- package/src/react/IntlContextValue.tsx +21 -0
- package/src/react/IntlProvider.tsx +5 -36
- package/src/react/IntlProviderProps.tsx +17 -0
- package/src/react/getIntlContextValue.tsx +30 -0
- package/src/react/useIntlContext.tsx +1 -1
- package/LICENSE +0 -21
|
@@ -1,44 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import resolveNamespace from '../core/use-intl.esm8.js';
|
|
4
|
-
import useIntlContext from './use-intl.esm7.js';
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import IntlContext from './use-intl.esm7.js';
|
|
5
3
|
|
|
6
|
-
function
|
|
7
|
-
var
|
|
8
|
-
defaultTranslationValues = _useIntlContext.defaultTranslationValues,
|
|
9
|
-
globalFormats = _useIntlContext.formats,
|
|
10
|
-
getMessageFallback = _useIntlContext.getMessageFallback,
|
|
11
|
-
locale = _useIntlContext.locale,
|
|
12
|
-
onError = _useIntlContext.onError,
|
|
13
|
-
timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
|
|
14
|
-
// See the comment in the hook invocation.
|
|
4
|
+
function useIntlContext() {
|
|
5
|
+
var context = useContext(IntlContext);
|
|
15
6
|
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? 'No intl context found. Have you configured the provider?' : undefined);
|
|
9
|
+
}
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
19
|
-
var cachedFormatsByLocaleRef = useRef({});
|
|
20
|
-
var messagesOrError = useMemo(function () {
|
|
21
|
-
return getMessagesOrError({
|
|
22
|
-
messages: allMessages,
|
|
23
|
-
namespace: namespace,
|
|
24
|
-
onError: onError
|
|
25
|
-
});
|
|
26
|
-
}, [allMessages, namespace, onError]);
|
|
27
|
-
var translate = useMemo(function () {
|
|
28
|
-
return createBaseTranslator({
|
|
29
|
-
cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
|
|
30
|
-
getMessageFallback: getMessageFallback,
|
|
31
|
-
messagesOrError: messagesOrError,
|
|
32
|
-
defaultTranslationValues: defaultTranslationValues,
|
|
33
|
-
namespace: namespace,
|
|
34
|
-
onError: onError,
|
|
35
|
-
formats: globalFormats,
|
|
36
|
-
locale: locale,
|
|
37
|
-
timeZone: timeZone
|
|
38
|
-
});
|
|
39
|
-
}, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
40
|
-
return translate;
|
|
11
|
+
return context;
|
|
41
12
|
}
|
|
42
13
|
|
|
43
|
-
export {
|
|
14
|
+
export { useIntlContext as default };
|
|
44
15
|
//# sourceMappingURL=use-intl.esm9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/
|
|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","process","env","NODE_ENV","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOP,OAAP,CAAA;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useIntlContext(): import("./
|
|
1
|
+
export default function useIntlContext(): import("./IntlContextValue").default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A generic type that describes the shape of messages.
|
|
2
|
+
*
|
|
3
|
+
* Optionally `IntlMessages` can be provided to get type safety for message
|
|
4
|
+
* namespaces and keys. See https://next-intl-docs.vercel.app/docs/usage/typescript
|
|
5
|
+
*/
|
|
6
|
+
declare type AbstractIntlMessages = {
|
|
7
|
+
[id: string]: AbstractIntlMessages | string;
|
|
8
|
+
};
|
|
9
|
+
export default AbstractIntlMessages;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractIntlMessages.js","sourceRoot":"","sources":["../../../src/core/AbstractIntlMessages.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
|
|
3
|
+
*/
|
|
4
|
+
declare type DateTimeFormatOptions = Intl.DateTimeFormatOptions & {
|
|
5
|
+
/**
|
|
6
|
+
* Examples:
|
|
7
|
+
* - numeric: "2021"
|
|
8
|
+
* - 2-digit: "21"
|
|
9
|
+
*/
|
|
10
|
+
year?: 'numeric' | '2-digit';
|
|
11
|
+
/** Examples:
|
|
12
|
+
* - numeric: "3"
|
|
13
|
+
* - 2-digit: "03"
|
|
14
|
+
* - long: "March"
|
|
15
|
+
* - short: "Mar"
|
|
16
|
+
* - narrow: "M"
|
|
17
|
+
*/
|
|
18
|
+
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
|
|
19
|
+
/** Examples:
|
|
20
|
+
* - numeric: "2"
|
|
21
|
+
* - 2-digit: "02"
|
|
22
|
+
*/
|
|
23
|
+
day?: 'numeric' | '2-digit';
|
|
24
|
+
/** Examples:
|
|
25
|
+
* - numeric: "2"
|
|
26
|
+
* - 2-digit: "02"
|
|
27
|
+
*/
|
|
28
|
+
hour?: 'numeric' | '2-digit';
|
|
29
|
+
/** Examples:
|
|
30
|
+
* - numeric: "2"
|
|
31
|
+
* - 2-digit: "02"
|
|
32
|
+
*/
|
|
33
|
+
minute?: 'numeric' | '2-digit';
|
|
34
|
+
/** Examples:
|
|
35
|
+
* - numeric: "2"
|
|
36
|
+
* - 2-digit: "02"
|
|
37
|
+
*/
|
|
38
|
+
second?: 'numeric' | '2-digit';
|
|
39
|
+
/** Examples:
|
|
40
|
+
* - long: "Thursday"
|
|
41
|
+
* - short: "Thu"
|
|
42
|
+
* - narrow: "T"
|
|
43
|
+
*/
|
|
44
|
+
weekday?: 'long' | 'short' | 'narrow';
|
|
45
|
+
/** Examples:
|
|
46
|
+
* - long: "Anno Domini"
|
|
47
|
+
* - short: "AD", narrow "A"
|
|
48
|
+
*/
|
|
49
|
+
era?: 'long' | 'short' | 'narrow';
|
|
50
|
+
/** If this is set to `true`, a 12-hour am/pm format is used. Otherwise a 24-hour time.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
hour12?: boolean;
|
|
54
|
+
/** Examples:
|
|
55
|
+
* - long: "Pacific Daylight Time"
|
|
56
|
+
* - short: "PDT"
|
|
57
|
+
*/
|
|
58
|
+
timeZoneName?: 'long' | 'short';
|
|
59
|
+
/**
|
|
60
|
+
* One of the [database names from the TZ database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
|
|
61
|
+
*/
|
|
62
|
+
timeZone?: string;
|
|
63
|
+
localeMatcher?: 'best fit' | 'lookup';
|
|
64
|
+
formatMatcher?: 'best fit' | 'basic';
|
|
65
|
+
dateStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
66
|
+
timeStyle?: 'full' | 'long' | 'medium' | 'short';
|
|
67
|
+
calendar?: 'buddhist' | 'chinese' | 'coptic' | 'ethiopia' | 'ethiopic' | 'gregory' | 'hebrew' | 'indian' | 'islamic' | 'iso8601' | 'japanese' | 'persian' | 'roc';
|
|
68
|
+
dayPeriod?: 'narrow' | 'short' | 'long';
|
|
69
|
+
numberingSystem?: 'arab' | 'arabext' | 'bali' | 'beng' | 'deva' | 'fullwide' | 'gujr' | 'guru' | 'hanidec' | 'khmr' | 'knda' | 'laoo' | 'latn' | 'limb' | 'mlym' | 'mong' | 'mymr' | 'orya' | 'tamldec' | 'telu' | 'thai' | 'tibt';
|
|
70
|
+
hourCycle?: 'h11' | 'h12' | 'h23' | 'h24';
|
|
71
|
+
};
|
|
72
|
+
export default DateTimeFormatOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateTimeFormatOptions.js","sourceRoot":"","sources":["../../../src/core/DateTimeFormatOptions.tsx"],"names":[],"mappings":"AAAA,uDAAuD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
2
|
+
import NumberFormatOptions from './NumberFormatOptions';
|
|
3
|
+
declare type Formats = {
|
|
4
|
+
number: Record<string, NumberFormatOptions>;
|
|
5
|
+
dateTime: Record<string, DateTimeFormatOptions>;
|
|
6
|
+
};
|
|
7
|
+
export default Formats;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Formats.js","sourceRoot":"","sources":["../../../src/core/Formats.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Formats from './Formats';
|
|
2
|
+
import IntlError from './IntlError';
|
|
3
|
+
/**
|
|
4
|
+
* Should be used for entry points that configure the library.
|
|
5
|
+
*/
|
|
6
|
+
declare type IntlConfiguration = {
|
|
7
|
+
/** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
|
|
8
|
+
locale: string;
|
|
9
|
+
/** Global formats can be provided to achieve consistent
|
|
10
|
+
* formatting across components. */
|
|
11
|
+
formats?: Partial<Formats>;
|
|
12
|
+
/** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */
|
|
13
|
+
timeZone?: string;
|
|
14
|
+
/** This callback will be invoked when an error is encountered during
|
|
15
|
+
* resolving a message or formatting it. This defaults to `console.error` to
|
|
16
|
+
* keep your app running. You can customize the handling by taking
|
|
17
|
+
* `error.code` into account. */
|
|
18
|
+
onError?(error: IntlError): void;
|
|
19
|
+
/** Will be called when a message couldn't be resolved or formatting it led to
|
|
20
|
+
* an error. This defaults to `${namespace}.${key}` You can use this to
|
|
21
|
+
* customize what will be rendered in this case. */
|
|
22
|
+
getMessageFallback?(info: {
|
|
23
|
+
error: IntlError;
|
|
24
|
+
key: string;
|
|
25
|
+
namespace?: string;
|
|
26
|
+
}): string;
|
|
27
|
+
/**
|
|
28
|
+
* Providing this value will have two effects:
|
|
29
|
+
* 1. It will be used as the default for the `now` argument of
|
|
30
|
+
* `useIntl().formatRelativeTime` if no explicit value is provided.
|
|
31
|
+
* 2. It will be returned as a static value from the `useNow` hook. Note
|
|
32
|
+
* however that when `updateInterval` is configured on the `useNow` hook,
|
|
33
|
+
* the global `now` value will only be used for the initial render, but
|
|
34
|
+
* afterwards the current date will be returned continuously.
|
|
35
|
+
*/
|
|
36
|
+
now?: Date;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A stricter set of the configuration that should be used internally
|
|
40
|
+
* once defaults are assigned to `IntlConfiguration`.
|
|
41
|
+
*/
|
|
42
|
+
export declare type InitializedIntlConfiguration = IntlConfiguration & {
|
|
43
|
+
onError: NonNullable<IntlConfiguration['onError']>;
|
|
44
|
+
getMessageFallback: NonNullable<IntlConfiguration['getMessageFallback']>;
|
|
45
|
+
};
|
|
46
|
+
export default IntlConfiguration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlConfiguration.js","sourceRoot":"","sources":["../../../src/core/IntlConfiguration.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum IntlErrorCode {
|
|
2
|
+
MISSING_MESSAGE = "MISSING_MESSAGE",
|
|
3
|
+
MISSING_FORMAT = "MISSING_FORMAT",
|
|
4
|
+
INSUFFICIENT_PATH = "INSUFFICIENT_PATH",
|
|
5
|
+
INVALID_MESSAGE = "INVALID_MESSAGE",
|
|
6
|
+
INVALID_KEY = "INVALID_KEY",
|
|
7
|
+
FORMATTING_ERROR = "FORMATTING_ERROR"
|
|
8
|
+
}
|
|
9
|
+
export default class IntlError extends Error {
|
|
10
|
+
readonly code: IntlErrorCode;
|
|
11
|
+
readonly originalMessage: string | undefined;
|
|
12
|
+
constructor(code: IntlErrorCode, originalMessage?: string);
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export var IntlErrorCode;
|
|
2
|
+
(function (IntlErrorCode) {
|
|
3
|
+
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
4
|
+
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
5
|
+
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
6
|
+
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
7
|
+
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
8
|
+
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
9
|
+
})(IntlErrorCode || (IntlErrorCode = {}));
|
|
10
|
+
export default class IntlError extends Error {
|
|
11
|
+
constructor(code, originalMessage) {
|
|
12
|
+
let message = code;
|
|
13
|
+
if (originalMessage) {
|
|
14
|
+
message += ': ' + originalMessage;
|
|
15
|
+
}
|
|
16
|
+
super(message);
|
|
17
|
+
this.code = code;
|
|
18
|
+
if (originalMessage) {
|
|
19
|
+
this.originalMessage = originalMessage;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=IntlError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlError.js","sourceRoot":"","sources":["../../../src/core/IntlError.tsx"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,oDAAmC,CAAA;IACnC,kDAAiC,CAAA;IACjC,wDAAuC,CAAA;IACvC,oDAAmC,CAAA;IACnC,4CAA2B,CAAA;IAC3B,sDAAqC,CAAA;AACvC,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,KAAK;IAI1C,YAAY,IAAmB,EAAE,eAAwB;QACvD,IAAI,OAAO,GAAW,IAAI,CAAC;QAC3B,IAAI,eAAe,EAAE;YACnB,OAAO,IAAI,IAAI,GAAG,eAAe,CAAC;SACnC;QACD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,eAAe,EAAE;YACnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;SACxC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlMessages.js","sourceRoot":"","sources":["../../../src/core/IntlMessages.tsx"],"names":[],"mappings":";AAAA,2CAA2C;AAC3C,2CAA2C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NumberFormatOptions.js","sourceRoot":"","sources":["../../../src/core/NumberFormatOptions.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export declare type TranslationValue = string | number | boolean | Date | null | undefined;
|
|
3
|
+
declare type TranslationValues = Record<string, TranslationValue>;
|
|
4
|
+
export declare type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
|
|
5
|
+
export default TranslationValues;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TranslationValues.js","sourceRoot":"","sources":["../../../src/core/TranslationValues.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Formats as IntlFormats } from 'intl-messageformat';
|
|
2
|
+
import Formats from './Formats';
|
|
3
|
+
/**
|
|
4
|
+
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
5
|
+
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
6
|
+
* include both a time and a date in a value, therefore the separation doesn't
|
|
7
|
+
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
8
|
+
* to convert the format before `intl-messageformat` can be used.
|
|
9
|
+
*/
|
|
10
|
+
export default function convertFormatsToIntlMessageFormat(formats: Partial<Formats>, timeZone?: string): Partial<IntlFormats>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function setTimeZoneInFormats(formats, timeZone) {
|
|
2
|
+
if (!formats)
|
|
3
|
+
return formats;
|
|
4
|
+
// The only way to set a time zone with `intl-messageformat` is to merge it into the formats
|
|
5
|
+
// https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
|
|
6
|
+
return Object.keys(formats).reduce((acc, key) => {
|
|
7
|
+
acc[key] = {
|
|
8
|
+
timeZone,
|
|
9
|
+
...formats[key]
|
|
10
|
+
};
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
16
|
+
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
17
|
+
* include both a time and a date in a value, therefore the separation doesn't
|
|
18
|
+
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
19
|
+
* to convert the format before `intl-messageformat` can be used.
|
|
20
|
+
*/
|
|
21
|
+
export default function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
22
|
+
const formatsWithTimeZone = timeZone
|
|
23
|
+
? { ...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone) }
|
|
24
|
+
: formats;
|
|
25
|
+
return {
|
|
26
|
+
...formatsWithTimeZone,
|
|
27
|
+
date: formatsWithTimeZone?.dateTime,
|
|
28
|
+
time: formatsWithTimeZone?.dateTime
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=convertFormatsToIntlMessageFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertFormatsToIntlMessageFormat.js","sourceRoot":"","sources":["../../../src/core/convertFormatsToIntlMessageFormat.tsx"],"names":[],"mappings":"AAIA,SAAS,oBAAoB,CAC3B,OAA0D,EAC1D,QAAgB;IAEhB,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAE7B,4FAA4F;IAC5F,sHAAsH;IACtH,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAChC,CAAC,GAA0C,EAAE,GAAG,EAAE,EAAE;QAClD,GAAG,CAAC,GAAG,CAAC,GAAG;YACT,QAAQ;YACR,GAAG,OAAO,CAAC,GAAG,CAAC;SAChB,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iCAAiC,CACvD,OAAyB,EACzB,QAAiB;IAEjB,MAAM,mBAAmB,GAAG,QAAQ;QAClC,CAAC,CAAC,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAC;QAC1E,CAAC,CAAC,OAAO,CAAC;IAEZ,OAAO;QACL,GAAG,mBAAmB;QACtB,IAAI,EAAE,mBAAmB,EAAE,QAAQ;QACnC,IAAI,EAAE,mBAAmB,EAAE,QAAQ;KACpC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import IntlMessageFormat from 'intl-messageformat';
|
|
2
|
+
import { ReactElement, ReactNodeArray } from 'react';
|
|
3
|
+
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
4
|
+
import Formats from './Formats';
|
|
5
|
+
import { InitializedIntlConfiguration } from './IntlConfiguration';
|
|
6
|
+
import IntlError from './IntlError';
|
|
7
|
+
import TranslationValues, { RichTranslationValues } from './TranslationValues';
|
|
8
|
+
import MessageKeys from './utils/MessageKeys';
|
|
9
|
+
import NestedKeyOf from './utils/NestedKeyOf';
|
|
10
|
+
import NestedValueOf from './utils/NestedValueOf';
|
|
11
|
+
export declare function getMessagesOrError<Messages extends AbstractIntlMessages>({ messages, namespace, onError }: {
|
|
12
|
+
messages: Messages;
|
|
13
|
+
namespace?: string;
|
|
14
|
+
onError?(error: IntlError): void;
|
|
15
|
+
}): AbstractIntlMessages | IntlError;
|
|
16
|
+
export declare type CreateBaseTranslatorProps<Messages> = InitializedIntlConfiguration & {
|
|
17
|
+
cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
|
|
18
|
+
defaultTranslationValues?: RichTranslationValues;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
messagesOrError: Messages | IntlError;
|
|
21
|
+
};
|
|
22
|
+
export default function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
|
|
23
|
+
<TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues | undefined, formats?: Partial<Formats> | undefined): string;
|
|
24
|
+
rich: (key: string, values?: RichTranslationValues | undefined, formats?: Partial<Formats> | undefined) => string | ReactElement | ReactNodeArray;
|
|
25
|
+
raw(key: string): any;
|
|
26
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import IntlMessageFormat from 'intl-messageformat';
|
|
2
|
+
import { cloneElement, isValidElement } from 'react';
|
|
3
|
+
import IntlError, { IntlErrorCode } from './IntlError';
|
|
4
|
+
import convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';
|
|
5
|
+
import { defaultGetMessageFallback, defaultOnError } from './defaults';
|
|
6
|
+
function resolvePath(messages, key, namespace) {
|
|
7
|
+
if (!messages) {
|
|
8
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
9
|
+
? `No messages available at \`${namespace}\`.`
|
|
10
|
+
: undefined);
|
|
11
|
+
}
|
|
12
|
+
let message = messages;
|
|
13
|
+
key.split('.').forEach((part) => {
|
|
14
|
+
const next = message[part];
|
|
15
|
+
if (part == null || next == null) {
|
|
16
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
17
|
+
? `Could not resolve \`${key}\` in ${namespace ? `\`${namespace}\`` : 'messages'}.`
|
|
18
|
+
: undefined);
|
|
19
|
+
}
|
|
20
|
+
message = next;
|
|
21
|
+
});
|
|
22
|
+
return message;
|
|
23
|
+
}
|
|
24
|
+
function prepareTranslationValues(values) {
|
|
25
|
+
if (Object.keys(values).length === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
// Workaround for https://github.com/formatjs/formatjs/issues/1467
|
|
28
|
+
const transformedValues = {};
|
|
29
|
+
Object.keys(values).forEach((key) => {
|
|
30
|
+
let index = 0;
|
|
31
|
+
const value = values[key];
|
|
32
|
+
let transformed;
|
|
33
|
+
if (typeof value === 'function') {
|
|
34
|
+
transformed = (chunks) => {
|
|
35
|
+
const result = value(chunks);
|
|
36
|
+
return isValidElement(result)
|
|
37
|
+
? cloneElement(result, { key: key + index++ })
|
|
38
|
+
: result;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
transformed = value;
|
|
43
|
+
}
|
|
44
|
+
transformedValues[key] = transformed;
|
|
45
|
+
});
|
|
46
|
+
return transformedValues;
|
|
47
|
+
}
|
|
48
|
+
export function getMessagesOrError({ messages, namespace, onError = defaultOnError }) {
|
|
49
|
+
try {
|
|
50
|
+
if (!messages) {
|
|
51
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
52
|
+
? `No messages were configured on the provider.`
|
|
53
|
+
: undefined);
|
|
54
|
+
}
|
|
55
|
+
const retrievedMessages = namespace
|
|
56
|
+
? resolvePath(messages, namespace)
|
|
57
|
+
: messages;
|
|
58
|
+
if (!retrievedMessages) {
|
|
59
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
60
|
+
? `No messages for namespace \`${namespace}\` found.`
|
|
61
|
+
: undefined);
|
|
62
|
+
}
|
|
63
|
+
return retrievedMessages;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
67
|
+
onError(intlError);
|
|
68
|
+
return intlError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export default function createBaseTranslator({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback = defaultGetMessageFallback, locale, messagesOrError, namespace, onError, timeZone }) {
|
|
72
|
+
function getFallbackFromErrorAndNotify(key, code, message) {
|
|
73
|
+
const error = new IntlError(code, message);
|
|
74
|
+
onError(error);
|
|
75
|
+
return getMessageFallback({ error, key, namespace });
|
|
76
|
+
}
|
|
77
|
+
function translateBaseFn(
|
|
78
|
+
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
79
|
+
key,
|
|
80
|
+
/** Key value pairs for values to interpolate into the message. */
|
|
81
|
+
values,
|
|
82
|
+
/** Provide custom formats for numbers, dates and times. */
|
|
83
|
+
formats) {
|
|
84
|
+
if (messagesOrError instanceof IntlError) {
|
|
85
|
+
// We have already warned about this during render
|
|
86
|
+
return getMessageFallback({
|
|
87
|
+
error: messagesOrError,
|
|
88
|
+
key,
|
|
89
|
+
namespace
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const messages = messagesOrError;
|
|
93
|
+
const cacheKey = [namespace, key].filter((part) => part != null).join('.');
|
|
94
|
+
let messageFormat;
|
|
95
|
+
if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {
|
|
96
|
+
messageFormat = cachedFormatsByLocale?.[locale][cacheKey];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
let message;
|
|
100
|
+
try {
|
|
101
|
+
message = resolvePath(messages, key, namespace);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
105
|
+
}
|
|
106
|
+
if (typeof message === 'object') {
|
|
107
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INSUFFICIENT_PATH, process.env.NODE_ENV !== 'production'
|
|
108
|
+
? `Insufficient path specified for \`${key}\` in \`${namespace ? `\`${namespace}\`` : 'messages'}\`.`
|
|
109
|
+
: undefined);
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat({ ...globalFormats, ...formats }, timeZone));
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
116
|
+
}
|
|
117
|
+
if (cachedFormatsByLocale) {
|
|
118
|
+
if (!cachedFormatsByLocale[locale]) {
|
|
119
|
+
cachedFormatsByLocale[locale] = {};
|
|
120
|
+
}
|
|
121
|
+
cachedFormatsByLocale[locale][cacheKey] = messageFormat;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const formattedMessage = messageFormat.format(
|
|
126
|
+
// @ts-ignore `intl-messageformat` expects a different format
|
|
127
|
+
// for rich text elements since a recent minor update. This
|
|
128
|
+
// needs to be evaluated in detail, possibly also in regards
|
|
129
|
+
// to be able to format to parts.
|
|
130
|
+
prepareTranslationValues({ ...defaultTranslationValues, ...values }));
|
|
131
|
+
if (formattedMessage == null) {
|
|
132
|
+
throw new Error(process.env.NODE_ENV !== 'production'
|
|
133
|
+
? `Unable to format \`${key}\` in ${namespace ? `namespace \`${namespace}\`` : 'messages'}`
|
|
134
|
+
: undefined);
|
|
135
|
+
}
|
|
136
|
+
// Limit the function signature to return strings or React elements
|
|
137
|
+
return isValidElement(formattedMessage) ||
|
|
138
|
+
// Arrays of React elements
|
|
139
|
+
Array.isArray(formattedMessage) ||
|
|
140
|
+
typeof formattedMessage === 'string'
|
|
141
|
+
? formattedMessage
|
|
142
|
+
: String(formattedMessage);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function translateFn(
|
|
149
|
+
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
150
|
+
key,
|
|
151
|
+
/** Key value pairs for values to interpolate into the message. */
|
|
152
|
+
values,
|
|
153
|
+
/** Provide custom formats for numbers, dates and times. */
|
|
154
|
+
formats) {
|
|
155
|
+
const result = translateBaseFn(key, values, formats);
|
|
156
|
+
if (typeof result !== 'string') {
|
|
157
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production'
|
|
158
|
+
? `The message \`${key}\` in ${namespace ? `namespace \`${namespace}\`` : 'messages'} didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`
|
|
159
|
+
: undefined);
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
translateFn.rich = translateBaseFn;
|
|
164
|
+
translateFn.raw = (
|
|
165
|
+
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
166
|
+
key) => {
|
|
167
|
+
if (messagesOrError instanceof IntlError) {
|
|
168
|
+
// We have already warned about this during render
|
|
169
|
+
return getMessageFallback({
|
|
170
|
+
error: messagesOrError,
|
|
171
|
+
key,
|
|
172
|
+
namespace
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const messages = messagesOrError;
|
|
176
|
+
try {
|
|
177
|
+
return resolvePath(messages, key, namespace);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return translateFn;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=createBaseTranslator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBaseTranslator.js","sourceRoot":"","sources":["../../../src/core/createBaseTranslator.tsx"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,cAAc,EAIf,MAAM,OAAO,CAAC;AAIf,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,iCAAiC,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAKrE,SAAS,WAAW,CAClB,QAA0C,EAC1C,GAAW,EACX,SAAkB;IAElB,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,8BAA8B,SAAS,KAAK;YAC9C,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,IAAI,OAAO,GAAG,QAAQ,CAAC;IAEvB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAI,OAAe,CAAC,IAAI,CAAC,CAAC;QAEpC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACnC,CAAC,CAAC,uBAAuB,GAAG,SACxB,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,UACnC,GAAG;gBACL,CA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E,OAAO,CAAC,CAAC;QAErD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO,6BAA6B,CAClC,GAAG,EACH,aAAa,CAAC,eAAe,EAC7B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACnC,CAAC,CAAC,iBAAiB,GAAG,SAClB,SAAS,CAAC,CAAC,CAAC,eAAe,SAAS,IAAI,CAAC,CAAC,CAAC,UAC7C,uFAAuF;gBACzF,CAAC,CAAC,SAAS,CACd,CAAC;SACH;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,WAAW,CAAC,IAAI,GAAG,eAAe,CAAC;IAEnC,WAAW,CAAC,GAAG,GAAG;IAChB,+EAA+E;IAC/E,GAAW,EACN,EAAE;QACP,IAAI,eAAe,YAAY,SAAS,EAAE;YACxC,kDAAkD;YAClD,OAAO,kBAAkB,CAAC;gBACxB,KAAK,EAAE,eAAe;gBACtB,GAAG;gBACH,SAAS;aACV,CAAC,CAAC;SACJ;QACD,MAAM,QAAQ,GAAG,eAAe,CAAC;QAEjC,IAAI;YACF,OAAO,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;SAC9C;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,6BAA6B,CAClC,GAAG,EACH,aAAa,CAAC,eAAe,EAC5B,KAAe,CAAC,OAAO,CACzB,CAAC;SACH;IACH,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions';
|
|
2
|
+
import Formats from './Formats';
|
|
3
|
+
import IntlError from './IntlError';
|
|
4
|
+
import NumberFormatOptions from './NumberFormatOptions';
|
|
5
|
+
declare type Props = {
|
|
6
|
+
locale: string;
|
|
7
|
+
timeZone?: string;
|
|
8
|
+
onError?(error: IntlError): void;
|
|
9
|
+
formats?: Partial<Formats>;
|
|
10
|
+
now?: Date;
|
|
11
|
+
};
|
|
12
|
+
export default function createIntl({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
13
|
+
formatDateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions | undefined) => string;
|
|
14
|
+
formatNumber: (value: number, formatOrOptions?: string | NumberFormatOptions | undefined) => string;
|
|
15
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
16
|
+
};
|
|
17
|
+
export {};
|