use-intl 2.22.0 → 2.22.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/README.md +1 -1
- package/_IntlProvider.d.ts +1 -0
- package/_useLocale.d.ts +1 -0
- package/core.d.ts +1 -0
- package/dist/_IntlProvider.js +7 -0
- package/dist/_useLocale.js +7 -0
- package/dist/core.js +7 -0
- package/dist/development/IntlContext-b5cc6be8.js +8 -0
- package/dist/development/_IntlProvider.js +53 -0
- package/dist/development/_useLocale-321e619f.js +19 -0
- package/dist/development/_useLocale.js +11 -0
- package/dist/development/core.js +66 -0
- package/dist/development/createFormatter-4848f6c8.js +453 -0
- package/dist/development/index.js +28 -0
- package/dist/development/initializeConfig-0a0b87a7.js +120 -0
- package/dist/development/react.js +145 -0
- package/dist/esm/IntlContext-381f3ce4.js +1 -0
- package/dist/esm/_IntlProvider.js +1 -0
- package/dist/esm/_useLocale-89b32eb9.js +1 -0
- package/dist/esm/_useLocale.js +1 -0
- package/dist/esm/core.js +1 -0
- package/dist/esm/createFormatter-c871a8ce.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/initializeConfig-29e7ba4c.js +1 -0
- package/dist/esm/react.js +1 -0
- package/dist/index.js +3 -4
- package/dist/production/IntlContext-381f3ce4.js +1 -0
- package/dist/production/_IntlProvider.js +1 -0
- package/dist/production/_useLocale-8e23751a.js +1 -0
- package/dist/production/_useLocale.js +1 -0
- package/dist/production/core.js +1 -0
- package/dist/production/createFormatter-7a8c6f36.js +1 -0
- package/dist/production/index.js +1 -0
- package/dist/production/initializeConfig-984a566d.js +1 -0
- package/dist/production/react.js +1 -0
- package/dist/react.js +7 -0
- package/dist/types/src/_IntlProvider.d.ts +1 -0
- package/dist/types/src/_useLocale.d.ts +1 -0
- package/dist/{src → types/src}/core/IntlConfig.d.ts +1 -1
- package/dist/{core → types/src/core}/TranslationValues.d.ts +6 -5
- package/dist/{src → types/src}/core/createBaseTranslator.d.ts +5 -9
- package/dist/{src → types/src}/core/createTranslator.d.ts +16 -4
- package/dist/types/src/core/createTranslatorImpl.d.ts +16 -0
- package/dist/{core → types/src/core}/index.d.ts +14 -9
- package/dist/types/src/core/initializeConfig.d.ts +14 -0
- package/dist/types/src/core.d.ts +1 -0
- package/dist/types/src/react/IntlProvider.d.ts +7 -0
- package/dist/{src → types/src}/react/index.d.ts +0 -1
- package/dist/types/src/react/useMessages.d.ts +2 -0
- package/dist/{src → types/src}/react/useTranslations.d.ts +10 -1
- package/dist/{src → types/src}/react/useTranslationsImpl.d.ts +2 -1
- package/dist/types/src/react.d.ts +1 -0
- package/dist/types/test/core/createFormatter.test.d.ts +1 -0
- package/dist/types/test/core/createTranslator.test.d.ts +1 -0
- package/dist/types/test/react/IntlProvider.test.d.ts +1 -0
- package/dist/types/test/react/useFormatter.test.d.ts +1 -0
- package/dist/types/test/react/useLocale.test.d.ts +1 -0
- package/dist/types/test/react/useMessages.test.d.ts +1 -0
- package/dist/types/test/react/useNow.test.d.ts +1 -0
- package/dist/types/test/react/useTimeZone.test.d.ts +1 -0
- package/dist/types/test/react/useTranslations.test.d.ts +1 -0
- package/dist/types/test/setup.d.ts +1 -0
- package/package.json +38 -21
- package/react.d.ts +1 -0
- package/dist/_virtual/use-intl.esm.js +0 -102
- package/dist/_virtual/use-intl.esm.js.map +0 -1
- package/dist/core/AbstractIntlMessages.d.ts +0 -9
- package/dist/core/DateTimeFormatOptions.d.ts +0 -73
- package/dist/core/Formats.d.ts +0 -8
- package/dist/core/IntlConfig.d.ts +0 -54
- package/dist/core/IntlError.d.ts +0 -14
- package/dist/core/MessageFormatCache.d.ts +0 -5
- package/dist/core/NumberFormatOptions.d.ts +0 -2
- package/dist/core/RelativeTimeFormatOptions.d.ts +0 -5
- package/dist/core/TimeZone.d.ts +0 -2
- package/dist/core/convertFormatsToIntlMessageFormat.d.ts +0 -11
- package/dist/core/createBaseTranslator.d.ts +0 -26
- package/dist/core/createFormatter.d.ts +0 -20
- package/dist/core/createIntl.d.ts +0 -7
- package/dist/core/createTranslator.d.ts +0 -48
- package/dist/core/createTranslatorImpl.d.ts +0 -14
- package/dist/core/defaults.d.ts +0 -11
- package/dist/core/resolveNamespace.d.ts +0 -5
- package/dist/core/use-intl.esm.js +0 -34
- package/dist/core/use-intl.esm.js.map +0 -1
- package/dist/core/use-intl.esm10.js +0 -37
- package/dist/core/use-intl.esm10.js.map +0 -1
- package/dist/core/use-intl.esm2.js +0 -36
- package/dist/core/use-intl.esm2.js.map +0 -1
- package/dist/core/use-intl.esm3.js +0 -161
- package/dist/core/use-intl.esm3.js.map +0 -1
- package/dist/core/use-intl.esm4.js +0 -14
- package/dist/core/use-intl.esm4.js.map +0 -1
- package/dist/core/use-intl.esm5.js +0 -53
- package/dist/core/use-intl.esm5.js.map +0 -1
- package/dist/core/use-intl.esm6.js +0 -15
- package/dist/core/use-intl.esm6.js.map +0 -1
- package/dist/core/use-intl.esm7.js +0 -10
- package/dist/core/use-intl.esm7.js.map +0 -1
- package/dist/core/use-intl.esm8.js +0 -200
- package/dist/core/use-intl.esm8.js.map +0 -1
- package/dist/core/use-intl.esm9.js +0 -28
- package/dist/core/use-intl.esm9.js.map +0 -1
- package/dist/core/utils/MessageKeys.d.ts +0 -5
- package/dist/core/utils/NamespaceKeys.d.ts +0 -5
- package/dist/core/utils/NestedKeyOf.d.ts +0 -4
- package/dist/core/utils/NestedValueOf.d.ts +0 -2
- package/dist/core/validateMessages.d.ts +0 -3
- package/dist/index.d.ts +0 -2
- package/dist/react/IntlContext.d.ts +0 -13
- package/dist/react/IntlProvider.d.ts +0 -7
- package/dist/react/getInitializedConfig.d.ts +0 -13
- package/dist/react/index.d.ts +0 -8
- package/dist/react/use-intl.esm.js +0 -22
- package/dist/react/use-intl.esm.js.map +0 -1
- package/dist/react/use-intl.esm10.js +0 -29
- package/dist/react/use-intl.esm10.js.map +0 -1
- package/dist/react/use-intl.esm11.js +0 -13
- package/dist/react/use-intl.esm11.js.map +0 -1
- package/dist/react/use-intl.esm12.js +0 -43
- package/dist/react/use-intl.esm12.js.map +0 -1
- package/dist/react/use-intl.esm2.js +0 -26
- package/dist/react/use-intl.esm2.js.map +0 -1
- package/dist/react/use-intl.esm3.js +0 -8
- package/dist/react/use-intl.esm3.js.map +0 -1
- package/dist/react/use-intl.esm4.js +0 -45
- package/dist/react/use-intl.esm4.js.map +0 -1
- package/dist/react/use-intl.esm5.js +0 -8
- package/dist/react/use-intl.esm5.js.map +0 -1
- package/dist/react/use-intl.esm6.js +0 -8
- package/dist/react/use-intl.esm6.js.map +0 -1
- package/dist/react/use-intl.esm7.js +0 -24
- package/dist/react/use-intl.esm7.js.map +0 -1
- package/dist/react/use-intl.esm8.js +0 -30
- package/dist/react/use-intl.esm8.js.map +0 -1
- package/dist/react/use-intl.esm9.js +0 -6
- package/dist/react/use-intl.esm9.js.map +0 -1
- package/dist/react/useFormatter.d.ts +0 -6
- package/dist/react/useIntl.d.ts +0 -6
- package/dist/react/useIntlContext.d.ts +0 -10
- package/dist/react/useLocale.d.ts +0 -1
- package/dist/react/useMessages.d.ts +0 -1
- package/dist/react/useNow.d.ts +0 -23
- package/dist/react/useTimeZone.d.ts +0 -1
- package/dist/react/useTranslations.d.ts +0 -44
- package/dist/react/useTranslationsImpl.d.ts +0 -8
- package/dist/src/core/AbstractIntlMessages.js +0 -2
- package/dist/src/core/AbstractIntlMessages.js.map +0 -1
- package/dist/src/core/DateTimeFormatOptions.js +0 -3
- package/dist/src/core/DateTimeFormatOptions.js.map +0 -1
- package/dist/src/core/Formats.js +0 -2
- package/dist/src/core/Formats.js.map +0 -1
- package/dist/src/core/IntlConfig.js +0 -2
- package/dist/src/core/IntlConfig.js.map +0 -1
- package/dist/src/core/IntlError.js +0 -24
- package/dist/src/core/IntlError.js.map +0 -1
- package/dist/src/core/MessageFormatCache.js +0 -2
- package/dist/src/core/MessageFormatCache.js.map +0 -1
- package/dist/src/core/NumberFormatOptions.js +0 -2
- package/dist/src/core/NumberFormatOptions.js.map +0 -1
- package/dist/src/core/RelativeTimeFormatOptions.js +0 -2
- package/dist/src/core/RelativeTimeFormatOptions.js.map +0 -1
- package/dist/src/core/TimeZone.js +0 -2
- package/dist/src/core/TimeZone.js.map +0 -1
- package/dist/src/core/TranslationValues.d.ts +0 -5
- package/dist/src/core/TranslationValues.js +0 -2
- package/dist/src/core/TranslationValues.js.map +0 -1
- package/dist/src/core/convertFormatsToIntlMessageFormat.js +0 -47
- package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +0 -1
- package/dist/src/core/createBaseTranslator.js +0 -218
- package/dist/src/core/createBaseTranslator.js.map +0 -1
- package/dist/src/core/createFormatter.js +0 -163
- package/dist/src/core/createFormatter.js.map +0 -1
- package/dist/src/core/createIntl.d.ts +0 -7
- package/dist/src/core/createIntl.js +0 -11
- package/dist/src/core/createIntl.js.map +0 -1
- package/dist/src/core/createTranslator.js +0 -23
- package/dist/src/core/createTranslator.js.map +0 -1
- package/dist/src/core/createTranslatorImpl.d.ts +0 -14
- package/dist/src/core/createTranslatorImpl.js +0 -43
- package/dist/src/core/createTranslatorImpl.js.map +0 -1
- package/dist/src/core/defaults.js +0 -11
- package/dist/src/core/defaults.js.map +0 -1
- package/dist/src/core/index.d.ts +0 -9
- package/dist/src/core/index.js +0 -6
- package/dist/src/core/index.js.map +0 -1
- package/dist/src/core/resolveNamespace.js +0 -10
- package/dist/src/core/resolveNamespace.js.map +0 -1
- package/dist/src/core/utils/MessageKeys.js +0 -2
- package/dist/src/core/utils/MessageKeys.js.map +0 -1
- package/dist/src/core/utils/NamespaceKeys.js +0 -2
- package/dist/src/core/utils/NamespaceKeys.js.map +0 -1
- package/dist/src/core/utils/NestedKeyOf.js +0 -2
- package/dist/src/core/utils/NestedKeyOf.js.map +0 -1
- package/dist/src/core/utils/NestedValueOf.js +0 -2
- package/dist/src/core/utils/NestedValueOf.js.map +0 -1
- package/dist/src/core/validateMessages.js +0 -56
- package/dist/src/core/validateMessages.js.map +0 -1
- package/dist/src/index.js +0 -3
- package/dist/src/index.js.map +0 -1
- package/dist/src/react/IntlContext.js +0 -4
- package/dist/src/react/IntlContext.js.map +0 -1
- package/dist/src/react/IntlProvider.d.ts +0 -7
- package/dist/src/react/IntlProvider.js +0 -11
- package/dist/src/react/IntlProvider.js.map +0 -1
- package/dist/src/react/getInitializedConfig.d.ts +0 -13
- package/dist/src/react/getInitializedConfig.js +0 -21
- package/dist/src/react/getInitializedConfig.js.map +0 -1
- package/dist/src/react/index.js +0 -10
- package/dist/src/react/index.js.map +0 -1
- package/dist/src/react/useFormatter.js +0 -14
- package/dist/src/react/useFormatter.js.map +0 -1
- package/dist/src/react/useIntl.d.ts +0 -6
- package/dist/src/react/useIntl.js +0 -20
- package/dist/src/react/useIntl.js.map +0 -1
- package/dist/src/react/useIntlContext.js +0 -12
- package/dist/src/react/useIntlContext.js.map +0 -1
- package/dist/src/react/useLocale.js +0 -5
- package/dist/src/react/useLocale.js.map +0 -1
- package/dist/src/react/useMessages.d.ts +0 -1
- package/dist/src/react/useMessages.js +0 -5
- package/dist/src/react/useMessages.js.map +0 -1
- package/dist/src/react/useNow.js +0 -40
- package/dist/src/react/useNow.js.map +0 -1
- package/dist/src/react/useTimeZone.js +0 -5
- package/dist/src/react/useTimeZone.js.map +0 -1
- package/dist/src/react/useTranslations.js +0 -21
- package/dist/src/react/useTranslations.js.map +0 -1
- package/dist/src/react/useTranslationsImpl.js +0 -35
- package/dist/src/react/useTranslationsImpl.js.map +0 -1
- package/dist/use-intl.cjs.development.js +0 -863
- package/dist/use-intl.cjs.development.js.map +0 -1
- package/dist/use-intl.cjs.production.min.js +0 -2
- package/dist/use-intl.cjs.production.min.js.map +0 -1
- package/dist/use-intl.esm.js +0 -13
- package/dist/use-intl.esm.js.map +0 -1
- package/src/core/AbstractIntlMessages.tsx +0 -10
- package/src/core/DateTimeFormatOptions.tsx +0 -130
- package/src/core/Formats.tsx +0 -10
- package/src/core/IntlConfig.tsx +0 -59
- package/src/core/IntlError.tsx +0 -27
- package/src/core/MessageFormatCache.tsx +0 -10
- package/src/core/NumberFormatOptions.tsx +0 -3
- package/src/core/RelativeTimeFormatOptions.tsx +0 -6
- package/src/core/TimeZone.tsx +0 -426
- package/src/core/TranslationValues.tsx +0 -22
- package/src/core/convertFormatsToIntlMessageFormat.tsx +0 -63
- package/src/core/createBaseTranslator.tsx +0 -352
- package/src/core/createFormatter.tsx +0 -242
- package/src/core/createIntl.tsx +0 -13
- package/src/core/createTranslator.tsx +0 -111
- package/src/core/createTranslatorImpl.tsx +0 -87
- package/src/core/defaults.tsx +0 -18
- package/src/core/index.tsx +0 -14
- package/src/core/resolveNamespace.tsx +0 -12
- package/src/core/utils/MessageKeys.tsx +0 -9
- package/src/core/utils/NamespaceKeys.tsx +0 -9
- package/src/core/utils/NestedKeyOf.tsx +0 -9
- package/src/core/utils/NestedValueOf.tsx +0 -12
- package/src/core/validateMessages.tsx +0 -77
- package/src/index.tsx +0 -2
- package/src/react/IntlContext.tsx +0 -12
- package/src/react/IntlProvider.tsx +0 -23
- package/src/react/getInitializedConfig.tsx +0 -29
- package/src/react/index.tsx +0 -10
- package/src/react/useFormatter.tsx +0 -19
- package/src/react/useIntl.tsx +0 -29
- package/src/react/useIntlContext.tsx +0 -16
- package/src/react/useLocale.tsx +0 -5
- package/src/react/useMessages.tsx +0 -5
- package/src/react/useNow.tsx +0 -49
- package/src/react/useTimeZone.tsx +0 -5
- package/src/react/useTranslations.tsx +0 -103
- package/src/react/useTranslationsImpl.tsx +0 -61
- /package/dist/{src → types/src}/core/AbstractIntlMessages.d.ts +0 -0
- /package/dist/{src → types/src}/core/DateTimeFormatOptions.d.ts +0 -0
- /package/dist/{src → types/src}/core/Formats.d.ts +0 -0
- /package/dist/{src → types/src}/core/IntlError.d.ts +0 -0
- /package/dist/{src → types/src}/core/MessageFormatCache.d.ts +0 -0
- /package/dist/{src → types/src}/core/NumberFormatOptions.d.ts +0 -0
- /package/dist/{src → types/src}/core/RelativeTimeFormatOptions.d.ts +0 -0
- /package/dist/{src → types/src}/core/TimeZone.d.ts +0 -0
- /package/dist/{src → types/src}/core/convertFormatsToIntlMessageFormat.d.ts +0 -0
- /package/dist/{src → types/src}/core/createFormatter.d.ts +0 -0
- /package/dist/{src → types/src}/core/defaults.d.ts +0 -0
- /package/dist/{src → types/src}/core/resolveNamespace.d.ts +0 -0
- /package/dist/{src → types/src}/core/utils/MessageKeys.d.ts +0 -0
- /package/dist/{src → types/src}/core/utils/NamespaceKeys.d.ts +0 -0
- /package/dist/{src → types/src}/core/utils/NestedKeyOf.d.ts +0 -0
- /package/dist/{src → types/src}/core/utils/NestedValueOf.d.ts +0 -0
- /package/dist/{src → types/src}/core/validateMessages.d.ts +0 -0
- /package/dist/{src → types/src}/index.d.ts +0 -0
- /package/dist/{src → types/src}/react/IntlContext.d.ts +0 -0
- /package/dist/{src → types/src}/react/useFormatter.d.ts +0 -0
- /package/dist/{src → types/src}/react/useIntlContext.d.ts +0 -0
- /package/dist/{src → types/src}/react/useLocale.d.ts +0 -0
- /package/dist/{src → types/src}/react/useNow.d.ts +0 -0
- /package/dist/{src → types/src}/react/useTimeZone.d.ts +0 -0
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import createTranslatorImpl from './createTranslatorImpl';
|
|
2
|
-
import { defaultGetMessageFallback, defaultOnError } from './defaults';
|
|
3
|
-
/**
|
|
4
|
-
* Translates messages from the given namespace by using the ICU syntax.
|
|
5
|
-
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
6
|
-
*
|
|
7
|
-
* If no namespace is provided, all available messages are returned.
|
|
8
|
-
* The namespace can also indicate nesting by using a dot
|
|
9
|
-
* (e.g. `namespace.Component`).
|
|
10
|
-
*/
|
|
11
|
-
export default function createTranslator({ getMessageFallback = defaultGetMessageFallback, messages, namespace, onError = defaultOnError, ...rest }) {
|
|
12
|
-
// We have to wrap the actual function so the type inference for the optional
|
|
13
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
14
|
-
// The prefix ("!") is arbitrary.
|
|
15
|
-
return createTranslatorImpl({
|
|
16
|
-
...rest,
|
|
17
|
-
onError,
|
|
18
|
-
getMessageFallback,
|
|
19
|
-
messages: { '!': messages },
|
|
20
|
-
namespace: namespace ? `!.${namespace}` : '!'
|
|
21
|
-
}, '!');
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=createTranslator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslator.js","sourceRoot":"","sources":["../../../src/core/createTranslator.tsx"],"names":[],"mappings":"AAGA,OAAO,oBAEN,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAMrE;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAKtC,EACA,kBAAkB,GAAG,yBAAyB,EAC9C,QAAQ,EACR,SAAS,EACT,OAAO,GAAG,cAAc,EACxB,GAAG,IAAI,EAIR;IA4DC,6EAA6E;IAC7E,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,oBAAoB,CAIzB;QACE,GAAG,IAAI;QACP,OAAO;QACP,kBAAkB;QAClB,QAAQ,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC;QACzB,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG;KAC9C,EACD,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
2
|
-
import { InitializedIntlConfig } from './IntlConfig';
|
|
3
|
-
import { TranslationValue } from './TranslationValues';
|
|
4
|
-
import NestedKeyOf from './utils/NestedKeyOf';
|
|
5
|
-
export type CoreRichTranslationValues = Record<string, TranslationValue | ((chunks: string) => string)>;
|
|
6
|
-
export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
7
|
-
namespace: string;
|
|
8
|
-
messages: Messages;
|
|
9
|
-
};
|
|
10
|
-
export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ getMessageFallback, messages, namespace, onError, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
|
|
11
|
-
(key: import("./utils/MessageKeys").default<import("./utils/NestedValueOf").default<Messages, NestedKey>, NestedKeyOf<import("./utils/NestedValueOf").default<Messages, NestedKey>>>, values?: import("./TranslationValues").default | undefined, formats?: Partial<import("./Formats").default> | undefined): string;
|
|
12
|
-
rich(key: string, values: CoreRichTranslationValues, formats?: Partial<import("./Formats").default> | undefined): string;
|
|
13
|
-
raw: (key: string) => any;
|
|
14
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import IntlError, { IntlErrorCode } from './IntlError';
|
|
2
|
-
import createBaseTranslator, { getMessagesOrError } from './createBaseTranslator';
|
|
3
|
-
import resolveNamespace from './resolveNamespace';
|
|
4
|
-
export default function createTranslatorImpl({ getMessageFallback, messages, namespace, onError, ...rest }, namespacePrefix) {
|
|
5
|
-
// The `namespacePrefix` is part of the type system.
|
|
6
|
-
// See the comment in the function invocation.
|
|
7
|
-
messages = messages[namespacePrefix];
|
|
8
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
9
|
-
const translator = createBaseTranslator({
|
|
10
|
-
...rest,
|
|
11
|
-
onError,
|
|
12
|
-
getMessageFallback,
|
|
13
|
-
messagesOrError: getMessagesOrError({
|
|
14
|
-
messages,
|
|
15
|
-
namespace,
|
|
16
|
-
onError
|
|
17
|
-
})
|
|
18
|
-
});
|
|
19
|
-
const originalRich = translator.rich;
|
|
20
|
-
function base(...args) {
|
|
21
|
-
return translator(...args);
|
|
22
|
-
}
|
|
23
|
-
// Augment `t.rich` to return plain strings
|
|
24
|
-
base.rich = (key,
|
|
25
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
26
|
-
values, formats) => {
|
|
27
|
-
// `chunks` is returned as a string when no React element
|
|
28
|
-
// is used, therefore it's safe to cast this type.
|
|
29
|
-
const result = originalRich(key, values, formats);
|
|
30
|
-
// When only string chunks are provided to the parser, only strings should be returned here.
|
|
31
|
-
if (typeof result !== 'string') {
|
|
32
|
-
const error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production'
|
|
33
|
-
? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})"
|
|
34
|
-
: undefined);
|
|
35
|
-
onError(error);
|
|
36
|
-
return getMessageFallback({ error, key, namespace });
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
base.raw = translator.raw;
|
|
41
|
-
return base;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=createTranslatorImpl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTranslatorImpl.js","sourceRoot":"","sources":["../../../src/core/createTranslatorImpl.tsx"],"names":[],"mappings":"AAEA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,oBAAoB,EAAE,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAChF,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAgBlD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAI1C,EACE,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,OAAO,EACP,GAAG,IAAI,EAC6B,EACtC,eAAuB;IAEvB,oDAAoD;IACpD,8CAA8C;IAC9C,QAAQ,GAAG,QAAQ,CAAC,eAAe,CAAa,CAAC;IACjD,SAAS,GAAG,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAc,CAAC;IAEtE,MAAM,UAAU,GAAG,oBAAoB,CAAsB;QAC3D,GAAG,IAAI;QACP,OAAO;QACP,kBAAkB;QAClB,eAAe,EAAE,kBAAkB,CAAC;YAClC,QAAQ;YACR,SAAS;YACT,OAAO;SACR,CAAyB;KAC3B,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC;IAErC,SAAS,IAAI,CAAC,GAAG,IAAmC;QAClD,OAAO,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,2CAA2C;IAC3C,IAAI,CAAC,IAAI,GAAG,CACV,GAAuC;IACvC,kEAAkE;IAClE,MAAiC,EACjC,OAA4C,EACpC,EAAE;QACV,yDAAyD;QACzD,kDAAkD;QAClD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,EAAE,MAA+B,EAAE,OAAO,CAAC,CAAC;QAE3E,4FAA4F;QAC5F,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,KAAK,GAAG,IAAI,SAAS,CACzB,aAAa,CAAC,gBAAgB,EAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACnC,CAAC,CAAC,iKAAiK;gBACnK,CAAC,CAAC,SAAS,CACd,CAAC;YAEF,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,kBAAkB,CAAC,EAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAC,CAAC,CAAC;SACpD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAE1B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contains defaults that are used for all entry points into the core.
|
|
3
|
-
* See also `InitializedIntlConfiguration`.
|
|
4
|
-
*/
|
|
5
|
-
export function defaultGetMessageFallback(props) {
|
|
6
|
-
return [props.namespace, props.key].filter((part) => part != null).join('.');
|
|
7
|
-
}
|
|
8
|
-
export function defaultOnError(error) {
|
|
9
|
-
console.error(error);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/core/defaults.tsx"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,MAAM,UAAU,yBAAyB,CAAC,KAIzC;IACC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAgB;IAC7C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/src/core/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type { default as AbstractIntlMessages } from './AbstractIntlMessages';
|
|
2
|
-
export type { default as TranslationValues, RichTranslationValues } from './TranslationValues';
|
|
3
|
-
export type { default as Formats } from './Formats';
|
|
4
|
-
export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
|
|
5
|
-
export type { default as NumberFormatOptions } from './NumberFormatOptions';
|
|
6
|
-
export { default as IntlError, IntlErrorCode } from './IntlError';
|
|
7
|
-
export { default as createTranslator } from './createTranslator';
|
|
8
|
-
export { default as createFormatter } from './createFormatter';
|
|
9
|
-
export { default as createIntl } from './createIntl';
|
package/dist/src/core/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { default as IntlError, IntlErrorCode } from './IntlError';
|
|
2
|
-
export { default as createTranslator } from './createTranslator';
|
|
3
|
-
export { default as createFormatter } from './createFormatter';
|
|
4
|
-
// TODO: Remove in next major version
|
|
5
|
-
export { default as createIntl } from './createIntl';
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAC,OAAO,IAAI,SAAS,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAChE,OAAO,EAAC,OAAO,IAAI,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAE7D,qCAAqC;AACrC,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For the strictly typed messages to work we have to wrap the namespace into
|
|
3
|
-
* a mandatory prefix. See https://stackoverflow.com/a/71529575/343045
|
|
4
|
-
*/
|
|
5
|
-
export default function resolveNamespace(namespace, namespacePrefix) {
|
|
6
|
-
return namespace === namespacePrefix
|
|
7
|
-
? undefined
|
|
8
|
-
: namespace.slice((namespacePrefix + '.').length);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=resolveNamespace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveNamespace.js","sourceRoot":"","sources":["../../../src/core/resolveNamespace.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,SAAiB,EACjB,eAAuB;IAEvB,OAAO,SAAS,KAAK,eAAe;QAClC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,eAAe,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageKeys.js","sourceRoot":"","sources":["../../../../src/core/utils/MessageKeys.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NamespaceKeys.js","sourceRoot":"","sources":["../../../../src/core/utils/NamespaceKeys.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NestedKeyOf.js","sourceRoot":"","sources":["../../../../src/core/utils/NestedKeyOf.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NestedValueOf.js","sourceRoot":"","sources":["../../../../src/core/utils/NestedValueOf.tsx"],"names":[],"mappings":""}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import IntlError, { IntlErrorCode } from './IntlError';
|
|
2
|
-
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
3
|
-
Object.entries(messages).forEach(([key, messageOrMessages]) => {
|
|
4
|
-
if (key.includes('.')) {
|
|
5
|
-
let keyLabel = key;
|
|
6
|
-
if (parentPath)
|
|
7
|
-
keyLabel += ` (at ${parentPath})`;
|
|
8
|
-
invalidKeyLabels.push(keyLabel);
|
|
9
|
-
}
|
|
10
|
-
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
11
|
-
validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter((part) => part != null).join('.'));
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export default function validateMessages(messages, onError) {
|
|
16
|
-
const invalidKeyLabels = [];
|
|
17
|
-
validateMessagesSegment(messages, invalidKeyLabels);
|
|
18
|
-
if (invalidKeyLabels.length > 0) {
|
|
19
|
-
onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production'
|
|
20
|
-
? `Namespace keys can not contain the character "." as this is used to express nesting. Please remove it or replace it with another character.
|
|
21
|
-
|
|
22
|
-
Invalid ${invalidKeyLabels.length === 1 ? 'key' : 'keys'}: ${invalidKeyLabels.join(', ')}
|
|
23
|
-
|
|
24
|
-
If you're migrating from a flat structure, you can convert your messages as follows:
|
|
25
|
-
|
|
26
|
-
import {set} from "lodash";
|
|
27
|
-
|
|
28
|
-
const input = {
|
|
29
|
-
"one.one": "1.1",
|
|
30
|
-
"one.two": "1.2",
|
|
31
|
-
"two.one.one": "2.1.1"
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const output = Object.entries(input).reduce(
|
|
35
|
-
(acc, [key, value]) => set(acc, key, value),
|
|
36
|
-
{}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// Output:
|
|
40
|
-
//
|
|
41
|
-
// {
|
|
42
|
-
// "one": {
|
|
43
|
-
// "one": "1.1",
|
|
44
|
-
// "two": "1.2"
|
|
45
|
-
// },
|
|
46
|
-
// "two": {
|
|
47
|
-
// "one": {
|
|
48
|
-
// "one": "2.1.1"
|
|
49
|
-
// }
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
|
-
`
|
|
53
|
-
: undefined));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=validateMessages.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateMessages.js","sourceRoot":"","sources":["../../../src/core/validateMessages.tsx"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,SAAS,uBAAuB,CAC9B,QAA8B,EAC9B,gBAA+B,EAC/B,UAAmB;IAEnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,iBAAiB,CAAC,EAAE,EAAE;QAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACrB,IAAI,QAAQ,GAAG,GAAG,CAAC;YACnB,IAAI,UAAU;gBAAE,QAAQ,IAAI,QAAQ,UAAU,GAAG,CAAC;YAClD,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,iBAAiB,IAAI,IAAI,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE;YACtE,uBAAuB,CACrB,iBAAiB,EACjB,gBAAgB,EAChB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAC;SACH;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,QAA8B,EAC9B,OAAmC;IAEnC,MAAM,gBAAgB,GAAkB,EAAE,CAAC;IAC3C,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAEpD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,CACL,IAAI,SAAS,CACX,aAAa,CAAC,WAAW,EACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC;;UAGE,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAC1C,KAAK,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B3C;YACS,CAAC,CAAC,SAAS,CACd,CACF,CAAC;KACH;AACH,CAAC"}
|
package/dist/src/index.js
DELETED
package/dist/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlContext.js","sourceRoot":"","sources":["../../../src/react/IntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAIpC,MAAM,WAAW,GAAG,aAAa,CAK/B,SAAS,CAAC,CAAC;AAEb,eAAe,WAAW,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import IntlContext from './IntlContext';
|
|
3
|
-
import getInitializedConfig from './getInitializedConfig';
|
|
4
|
-
export default function IntlProvider({ children, ...props }) {
|
|
5
|
-
const [messageFormatCache] = useState(() => new Map());
|
|
6
|
-
return (React.createElement(IntlContext.Provider, { value: {
|
|
7
|
-
...getInitializedConfig(props),
|
|
8
|
-
messageFormatCache
|
|
9
|
-
} }, children));
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=IntlProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntlProvider.js","sourceRoot":"","sources":["../../../src/react/IntlProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAY,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEjD,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAM1D,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EAAC,QAAQ,EAAE,GAAG,KAAK,EAAQ;IAC9D,MAAM,CAAC,kBAAkB,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAEvD,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IACnB,KAAK,EAAE;YACL,GAAG,oBAAoB,CAAC,KAAK,CAAC;YAC9B,kBAAkB;SACnB,IAEA,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import IntlConfig from '../core/IntlConfig';
|
|
2
|
-
/**
|
|
3
|
-
* Enhances the incoming props with defaults.
|
|
4
|
-
*/
|
|
5
|
-
export default function getInitializedConfig<Props extends Omit<IntlConfig, 'children'>>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
|
|
6
|
-
messages: import("../core/AbstractIntlMessages").default | undefined;
|
|
7
|
-
onError: (error: import("..").IntlError) => void;
|
|
8
|
-
getMessageFallback: (info: {
|
|
9
|
-
error: import("..").IntlError;
|
|
10
|
-
key: string;
|
|
11
|
-
namespace?: string | undefined;
|
|
12
|
-
}) => string;
|
|
13
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defaultGetMessageFallback, defaultOnError } from '../core/defaults';
|
|
2
|
-
import validateMessages from '../core/validateMessages';
|
|
3
|
-
/**
|
|
4
|
-
* Enhances the incoming props with defaults.
|
|
5
|
-
*/
|
|
6
|
-
export default function getInitializedConfig({ getMessageFallback, messages, onError, ...rest }) {
|
|
7
|
-
const finalOnError = onError || defaultOnError;
|
|
8
|
-
const finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
9
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
10
|
-
if (messages) {
|
|
11
|
-
validateMessages(messages, finalOnError);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
...rest,
|
|
16
|
-
messages,
|
|
17
|
-
onError: finalOnError,
|
|
18
|
-
getMessageFallback: finalGetMessageFallback
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=getInitializedConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getInitializedConfig.js","sourceRoot":"","sources":["../../../src/react/getInitializedConfig.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC3E,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAI1C,EAAC,kBAAkB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,EAAQ;IACvD,MAAM,YAAY,GAAG,OAAO,IAAI,cAAc,CAAC;IAC/C,MAAM,uBAAuB,GAC3B,kBAAkB,IAAI,yBAAyB,CAAC;IAElD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,IAAI,QAAQ,EAAE;YACZ,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;SAC1C;KACF;IAED,OAAO;QACL,GAAG,IAAI;QACP,QAAQ;QACR,OAAO,EAAE,YAAY;QACrB,kBAAkB,EAAE,uBAAuB;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/src/react/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as IntlProvider } from './IntlProvider';
|
|
2
|
-
export { default as useTranslations } from './useTranslations';
|
|
3
|
-
export { default as useLocale } from './useLocale';
|
|
4
|
-
export { default as useNow } from './useNow';
|
|
5
|
-
export { default as useTimeZone } from './useTimeZone';
|
|
6
|
-
export { default as useMessages } from './useMessages';
|
|
7
|
-
export { default as useFormatter } from './useFormatter';
|
|
8
|
-
// TODO: Remove in next major version
|
|
9
|
-
export { default as useIntl } from './useIntl';
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,OAAO,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAEvD,qCAAqC;AACrC,OAAO,EAAC,OAAO,IAAI,OAAO,EAAC,MAAM,WAAW,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import createFormatter from '../core/createFormatter';
|
|
3
|
-
import useIntlContext from './useIntlContext';
|
|
4
|
-
export default function useFormatter() {
|
|
5
|
-
const { formats, locale, now: globalNow, onError, timeZone } = useIntlContext();
|
|
6
|
-
return useMemo(() => createFormatter({
|
|
7
|
-
formats,
|
|
8
|
-
locale,
|
|
9
|
-
now: globalNow,
|
|
10
|
-
onError,
|
|
11
|
-
timeZone
|
|
12
|
-
}), [formats, globalNow, locale, onError, timeZone]);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=useFormatter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormatter.js","sourceRoot":"","sources":["../../../src/react/useFormatter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,eAAe,CAAC;QACd,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/** @deprecated Switch to `useFormatter` instead. */
|
|
2
|
-
export default function useIntl(): {
|
|
3
|
-
formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
4
|
-
formatNumber: (value: number | bigint, formatOrOptions?: string | import("@formatjs/ecma402-abstract/types/number").NumberFormatOptions | undefined) => string;
|
|
5
|
-
formatRelativeTime: (date: number | Date, nowOrOptions?: number | Date | import("../core/RelativeTimeFormatOptions").default | undefined) => string;
|
|
6
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import createIntl from '../core/createIntl';
|
|
3
|
-
import useIntlContext from './useIntlContext';
|
|
4
|
-
let hasWarned = false;
|
|
5
|
-
/** @deprecated Switch to `useFormatter` instead. */
|
|
6
|
-
export default function useIntl() {
|
|
7
|
-
const { formats, locale, now: globalNow, onError, timeZone } = useIntlContext();
|
|
8
|
-
if (!hasWarned) {
|
|
9
|
-
hasWarned = true;
|
|
10
|
-
console.warn('`useIntl()` is deprecated and will be removed in the next major version. Please switch to `useFormatter()`.');
|
|
11
|
-
}
|
|
12
|
-
return useMemo(() => createIntl({
|
|
13
|
-
formats,
|
|
14
|
-
locale,
|
|
15
|
-
now: globalNow,
|
|
16
|
-
onError,
|
|
17
|
-
timeZone
|
|
18
|
-
}), [formats, globalNow, locale, onError, timeZone]);
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=useIntl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.js","sourceRoot":"","sources":["../../../src/react/useIntl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,oDAAoD;AACpD,MAAM,CAAC,OAAO,UAAU,OAAO;IAC7B,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,cAAc,EAAE,CAAC;IAE9E,IAAI,CAAC,SAAS,EAAE;QACd,SAAS,GAAG,IAAI,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,6GAA6G,CAC9G,CAAC;KACH;IAED,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,UAAU,CAAC;QACT,OAAO;QACP,MAAM;QACN,GAAG,EAAE,SAAS;QACd,OAAO;QACP,QAAQ;KACT,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
import IntlContext from './IntlContext';
|
|
3
|
-
export default function useIntlContext() {
|
|
4
|
-
const context = useContext(IntlContext);
|
|
5
|
-
if (!context) {
|
|
6
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
7
|
-
? 'No intl context found. Have you configured the provider?'
|
|
8
|
-
: undefined);
|
|
9
|
-
}
|
|
10
|
-
return context;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=useIntlContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlContext.js","sourceRoot":"","sources":["../../../src/react/useIntlContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,cAAc;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,0DAA0D;YAC5D,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.js","sourceRoot":"","sources":["../../../src/react/useLocale.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,OAAO,cAAc,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function useMessages(): import("../core/AbstractIntlMessages").default | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMessages.js","sourceRoot":"","sources":["../../../src/react/useMessages.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,OAAO,cAAc,EAAE,CAAC,QAAQ,CAAC;AACnC,CAAC"}
|
package/dist/src/react/useNow.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
import useIntlContext from './useIntlContext';
|
|
3
|
-
function getNow() {
|
|
4
|
-
return new Date();
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Reading the current date via `new Date()` in components should be avoided, as
|
|
8
|
-
* it causes components to be impure and can lead to flaky tests. Instead, this
|
|
9
|
-
* hook can be used.
|
|
10
|
-
*
|
|
11
|
-
* By default, it returns the time when the component mounts. If `updateInterval`
|
|
12
|
-
* is specified, the value will be updated based on the interval.
|
|
13
|
-
*
|
|
14
|
-
* You can however also return a static value from this hook, if you
|
|
15
|
-
* configure the `now` parameter on the context provider. Note however,
|
|
16
|
-
* that if `updateInterval` is configured in this case, the component
|
|
17
|
-
* will initialize with the global value, but will afterwards update
|
|
18
|
-
* continuously based on the interval.
|
|
19
|
-
*
|
|
20
|
-
* For unit tests, this can be mocked to a constant value. For end-to-end
|
|
21
|
-
* testing, an environment parameter can be passed to the `now` parameter
|
|
22
|
-
* of the provider to mock this to a static value.
|
|
23
|
-
*/
|
|
24
|
-
export default function useNow(options) {
|
|
25
|
-
const updateInterval = options?.updateInterval;
|
|
26
|
-
const { now: globalNow } = useIntlContext();
|
|
27
|
-
const [now, setNow] = useState(globalNow || getNow());
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!updateInterval)
|
|
30
|
-
return;
|
|
31
|
-
const intervalId = setInterval(() => {
|
|
32
|
-
setNow(getNow());
|
|
33
|
-
}, updateInterval);
|
|
34
|
-
return () => {
|
|
35
|
-
clearInterval(intervalId);
|
|
36
|
-
};
|
|
37
|
-
}, [globalNow, updateInterval]);
|
|
38
|
-
return now;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=useNow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useNow.js","sourceRoot":"","sources":["../../../src/react/useNow.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAM9C,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAiB;IAC9C,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,CAAC;IAE/C,MAAM,EAAC,GAAG,EAAE,SAAS,EAAC,GAAG,cAAc,EAAE,CAAC;IAC1C,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,cAAc;YAAE,OAAO;QAE5B,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;YAClC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACnB,CAAC,EAAE,cAAc,CAAC,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,aAAa,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAEhC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTimeZone.js","sourceRoot":"","sources":["../../../src/react/useTimeZone.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,WAAW;IACjC,OAAO,cAAc,EAAE,CAAC,QAAQ,CAAC;AACnC,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import useIntlContext from './useIntlContext';
|
|
2
|
-
import useTranslationsImpl from './useTranslationsImpl';
|
|
3
|
-
/**
|
|
4
|
-
* Translates messages from the given namespace by using the ICU syntax.
|
|
5
|
-
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
6
|
-
*
|
|
7
|
-
* If no namespace is provided, all available messages are returned.
|
|
8
|
-
* The namespace can also indicate nesting by using a dot
|
|
9
|
-
* (e.g. `namespace.Component`).
|
|
10
|
-
*/
|
|
11
|
-
export default function useTranslations(namespace) {
|
|
12
|
-
const context = useIntlContext();
|
|
13
|
-
const messages = context.messages;
|
|
14
|
-
// We have to wrap the actual hook so the type inference for the optional
|
|
15
|
-
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
16
|
-
// The prefix ("!") is arbitrary.
|
|
17
|
-
return useTranslationsImpl({ '!': messages },
|
|
18
|
-
// @ts-expect-error
|
|
19
|
-
namespace ? `!.${namespace}` : '!', '!');
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=useTranslations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslations.js","sourceRoot":"","sources":["../../../src/react/useTranslations.tsx"],"names":[],"mappings":"AASA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAMrC,SAAqB;IA6DrB,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAwB,CAAC;IAElD,yEAAyE;IACzE,6EAA6E;IAC7E,iCAAiC;IACjC,OAAO,mBAAmB,CAIxB,EAAC,GAAG,EAAE,QAAQ,EAAC;IACf,mBAAmB;IACnB,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,EAClC,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import createBaseTranslator, { getMessagesOrError } from '../core/createBaseTranslator';
|
|
3
|
-
import resolveNamespace from '../core/resolveNamespace';
|
|
4
|
-
import useIntlContext from './useIntlContext';
|
|
5
|
-
export default function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
6
|
-
const { defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messageFormatCache, onError, timeZone } = useIntlContext();
|
|
7
|
-
// The `namespacePrefix` is part of the type system.
|
|
8
|
-
// See the comment in the hook invocation.
|
|
9
|
-
allMessages = allMessages[namespacePrefix];
|
|
10
|
-
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
11
|
-
const messagesOrError = useMemo(() => getMessagesOrError({ messages: allMessages, namespace, onError }), [allMessages, namespace, onError]);
|
|
12
|
-
const translate = useMemo(() => createBaseTranslator({
|
|
13
|
-
messageFormatCache,
|
|
14
|
-
getMessageFallback,
|
|
15
|
-
messagesOrError,
|
|
16
|
-
defaultTranslationValues,
|
|
17
|
-
namespace,
|
|
18
|
-
onError,
|
|
19
|
-
formats: globalFormats,
|
|
20
|
-
locale,
|
|
21
|
-
timeZone
|
|
22
|
-
}), [
|
|
23
|
-
messageFormatCache,
|
|
24
|
-
getMessageFallback,
|
|
25
|
-
messagesOrError,
|
|
26
|
-
defaultTranslationValues,
|
|
27
|
-
namespace,
|
|
28
|
-
onError,
|
|
29
|
-
globalFormats,
|
|
30
|
-
locale,
|
|
31
|
-
timeZone
|
|
32
|
-
]);
|
|
33
|
-
return translate;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=useTranslationsImpl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTranslationsImpl.js","sourceRoot":"","sources":["../../../src/react/useTranslationsImpl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAE9B,OAAO,oBAAoB,EAAE,EAC3B,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AAExD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAGzC,WAAqB,EAAE,SAAoB,EAAE,eAAuB;IACpE,MAAM,EACJ,wBAAwB,EACxB,OAAO,EAAE,aAAa,EACtB,kBAAkB,EAClB,MAAM,EACN,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACT,GAAG,cAAc,EAAE,CAAC;IAErB,oDAAoD;IACpD,0CAA0C;IAC1C,WAAW,GAAG,WAAW,CAAC,eAAe,CAAa,CAAC;IACvD,SAAS,GAAG,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAc,CAAC;IAEtE,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAC,CAAC,EACrE,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,CAClC,CAAC;IAEF,MAAM,SAAS,GAAG,OAAO,CACvB,GAAG,EAAE,CACH,oBAAoB,CAAC;QACnB,kBAAkB;QAClB,kBAAkB;QAClB,eAAe;QACf,wBAAwB;QACxB,SAAS;QACT,OAAO;QACP,OAAO,EAAE,aAAa;QACtB,MAAM;QACN,QAAQ;KACT,CAAC,EACJ;QACE,kBAAkB;QAClB,kBAAkB;QAClB,eAAe;QACf,wBAAwB;QACxB,SAAS;QACT,OAAO;QACP,aAAa;QACb,MAAM;QACN,QAAQ;KACT,CACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|