use-intl 0.0.0-package-boundaries.0
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/LICENSE +21 -0
- package/README.md +91 -0
- package/core.d.ts +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.esm.js +102 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
- package/dist/_virtual/use-intl.esm.js +102 -0
- package/dist/_virtual/use-intl.esm.js.map +1 -0
- package/dist/core/AbstractIntlMessages.d.ts +9 -0
- package/dist/core/DateTimeFormatOptions.d.ts +73 -0
- package/dist/core/Formats.d.ts +8 -0
- package/dist/core/IntlConfig.d.ts +54 -0
- package/dist/core/IntlError.d.ts +13 -0
- package/dist/core/IntlError.esm.js +33 -0
- package/dist/core/IntlError.esm.js.map +1 -0
- package/dist/core/NumberFormatOptions.d.ts +2 -0
- package/dist/core/TimeZone.d.ts +2 -0
- package/dist/core/TranslationValues.d.ts +6 -0
- package/dist/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
- package/dist/core/convertFormatsToIntlMessageFormat.esm.js +32 -0
- package/dist/core/convertFormatsToIntlMessageFormat.esm.js.map +1 -0
- package/dist/core/createBaseTranslator.d.ts +21 -0
- package/dist/core/createBaseTranslator.esm.js +201 -0
- package/dist/core/createBaseTranslator.esm.js.map +1 -0
- package/dist/core/createFormatter.d.ts +19 -0
- package/dist/core/createFormatter.esm.js +138 -0
- package/dist/core/createFormatter.esm.js.map +1 -0
- package/dist/core/createIntl.d.ts +7 -0
- package/dist/core/createIntl.esm.js +14 -0
- package/dist/core/createIntl.esm.js.map +1 -0
- package/dist/core/createTranslator.d.ts +47 -0
- package/dist/core/createTranslator.esm.js +37 -0
- package/dist/core/createTranslator.esm.js.map +1 -0
- package/dist/core/createTranslatorImpl.d.ts +13 -0
- package/dist/core/createTranslatorImpl.esm.js +50 -0
- package/dist/core/createTranslatorImpl.esm.js.map +1 -0
- package/dist/core/defaults.d.ts +11 -0
- package/dist/core/defaults.esm.js +15 -0
- package/dist/core/defaults.esm.js.map +1 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/initializeConfig.d.ts +13 -0
- package/dist/core/initializeConfig.esm.js +29 -0
- package/dist/core/initializeConfig.esm.js.map +1 -0
- package/dist/core/resolveNamespace.d.ts +5 -0
- package/dist/core/resolveNamespace.esm.js +10 -0
- package/dist/core/resolveNamespace.esm.js.map +1 -0
- package/dist/core/use-intl.esm.js +33 -0
- package/dist/core/use-intl.esm.js.map +1 -0
- package/dist/core/use-intl.esm10.js +28 -0
- package/dist/core/use-intl.esm10.js.map +1 -0
- package/dist/core/use-intl.esm11.js +10 -0
- package/dist/core/use-intl.esm11.js.map +1 -0
- package/dist/core/use-intl.esm2.js +201 -0
- package/dist/core/use-intl.esm2.js.map +1 -0
- package/dist/core/use-intl.esm3.js +14 -0
- package/dist/core/use-intl.esm3.js.map +1 -0
- package/dist/core/use-intl.esm4.js +138 -0
- package/dist/core/use-intl.esm4.js.map +1 -0
- package/dist/core/use-intl.esm5.js +37 -0
- package/dist/core/use-intl.esm5.js.map +1 -0
- package/dist/core/use-intl.esm6.js +29 -0
- package/dist/core/use-intl.esm6.js.map +1 -0
- package/dist/core/use-intl.esm7.js +15 -0
- package/dist/core/use-intl.esm7.js.map +1 -0
- package/dist/core/use-intl.esm8.js +32 -0
- package/dist/core/use-intl.esm8.js.map +1 -0
- package/dist/core/use-intl.esm9.js +50 -0
- package/dist/core/use-intl.esm9.js.map +1 -0
- package/dist/core/utils/MessageKeys.d.ts +5 -0
- package/dist/core/utils/NamespaceKeys.d.ts +5 -0
- package/dist/core/utils/NestedKeyOf.d.ts +4 -0
- package/dist/core/utils/NestedValueOf.d.ts +2 -0
- package/dist/core/validateMessages.d.ts +3 -0
- package/dist/core/validateMessages.esm.js +28 -0
- package/dist/core/validateMessages.esm.js.map +1 -0
- package/dist/core.cjs.development.js +93 -0
- package/dist/core.cjs.development.js.map +1 -0
- package/dist/core.cjs.production.min.js +2 -0
- package/dist/core.cjs.production.min.js.map +1 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.esm.js +7 -0
- package/dist/core.esm.js.map +1 -0
- package/dist/core.js +8 -0
- package/dist/createIntl-8a2b87eb.js +579 -0
- package/dist/createIntl-8a2b87eb.js.map +1 -0
- package/dist/createIntl-f7979de1.js +2 -0
- package/dist/createIntl-f7979de1.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/react/IntlContext.d.ts +4 -0
- package/dist/react/IntlContext.esm.js +6 -0
- package/dist/react/IntlContext.esm.js.map +1 -0
- package/dist/react/IntlProvider.d.ts +7 -0
- package/dist/react/IntlProvider.esm.js +16 -0
- package/dist/react/IntlProvider.esm.js.map +1 -0
- package/dist/react/getInitializedConfig.d.ts +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/use-intl.esm.js +16 -0
- package/dist/react/use-intl.esm.js.map +1 -0
- package/dist/react/use-intl.esm10.js +13 -0
- package/dist/react/use-intl.esm10.js.map +1 -0
- package/dist/react/use-intl.esm11.js +36 -0
- package/dist/react/use-intl.esm11.js.map +1 -0
- package/dist/react/use-intl.esm2.js +8 -0
- package/dist/react/use-intl.esm2.js.map +1 -0
- package/dist/react/use-intl.esm3.js +8 -0
- package/dist/react/use-intl.esm3.js.map +1 -0
- package/dist/react/use-intl.esm4.js +26 -0
- package/dist/react/use-intl.esm4.js.map +1 -0
- package/dist/react/use-intl.esm5.js +45 -0
- package/dist/react/use-intl.esm5.js.map +1 -0
- package/dist/react/use-intl.esm6.js +30 -0
- package/dist/react/use-intl.esm6.js.map +1 -0
- package/dist/react/use-intl.esm7.js +8 -0
- package/dist/react/use-intl.esm7.js.map +1 -0
- package/dist/react/use-intl.esm8.js +24 -0
- package/dist/react/use-intl.esm8.js.map +1 -0
- package/dist/react/use-intl.esm9.js +6 -0
- package/dist/react/use-intl.esm9.js.map +1 -0
- package/dist/react/useFormatter.d.ts +6 -0
- package/dist/react/useFormatter.esm.js +24 -0
- package/dist/react/useFormatter.esm.js.map +1 -0
- package/dist/react/useIntl.d.ts +6 -0
- package/dist/react/useIntl.esm.js +30 -0
- package/dist/react/useIntl.esm.js.map +1 -0
- package/dist/react/useIntlContext.d.ts +1 -0
- package/dist/react/useIntlContext.esm.js +13 -0
- package/dist/react/useIntlContext.esm.js.map +1 -0
- package/dist/react/useLocale.d.ts +1 -0
- package/dist/react/useLocale.esm.js +8 -0
- package/dist/react/useLocale.esm.js.map +1 -0
- package/dist/react/useMessages.d.ts +1 -0
- package/dist/react/useMessages.esm.js +8 -0
- package/dist/react/useMessages.esm.js.map +1 -0
- package/dist/react/useNow.d.ts +23 -0
- package/dist/react/useNow.esm.js +45 -0
- package/dist/react/useNow.esm.js.map +1 -0
- package/dist/react/useTimeZone.d.ts +1 -0
- package/dist/react/useTimeZone.esm.js +8 -0
- package/dist/react/useTimeZone.esm.js.map +1 -0
- package/dist/react/useTranslations.d.ts +44 -0
- package/dist/react/useTranslations.esm.js +26 -0
- package/dist/react/useTranslations.esm.js.map +1 -0
- package/dist/react/useTranslationsImpl.d.ts +8 -0
- package/dist/react/useTranslationsImpl.esm.js +36 -0
- package/dist/react/useTranslationsImpl.esm.js.map +1 -0
- package/dist/react.cjs.development.js +184 -0
- package/dist/react.cjs.development.js.map +1 -0
- package/dist/react.cjs.production.min.js +2 -0
- package/dist/react.cjs.production.min.js.map +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.esm.js +9 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/react.js +8 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/use-intl.cjs.development.js +823 -0
- package/dist/use-intl.cjs.development.js.map +1 -0
- package/dist/use-intl.cjs.production.min.js +2 -0
- package/dist/use-intl.cjs.production.min.js.map +1 -0
- package/dist/use-intl.esm.js +15 -0
- package/dist/use-intl.esm.js.map +1 -0
- package/package.json +78 -0
- package/react.d.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
|
|
2
|
+
import IntlError, { IntlErrorCode } from './IntlError.esm.js';
|
|
3
|
+
import createBaseTranslator from './createBaseTranslator.esm.js';
|
|
4
|
+
import resolveNamespace from './resolveNamespace.esm.js';
|
|
5
|
+
|
|
6
|
+
var _excluded = ["getMessageFallback", "messages", "namespace", "onError"];
|
|
7
|
+
function createTranslatorImpl(_ref, namespacePrefix) {
|
|
8
|
+
var getMessageFallback = _ref.getMessageFallback,
|
|
9
|
+
messages = _ref.messages,
|
|
10
|
+
namespace = _ref.namespace,
|
|
11
|
+
onError = _ref.onError,
|
|
12
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
// The `namespacePrefix` is part of the type system.
|
|
14
|
+
// See the comment in the function invocation.
|
|
15
|
+
messages = messages[namespacePrefix];
|
|
16
|
+
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
17
|
+
var translator = createBaseTranslator(_extends({}, rest, {
|
|
18
|
+
onError: onError,
|
|
19
|
+
getMessageFallback: getMessageFallback,
|
|
20
|
+
messages: messages,
|
|
21
|
+
namespace: namespace
|
|
22
|
+
}));
|
|
23
|
+
var originalRich = translator.rich;
|
|
24
|
+
function base() {
|
|
25
|
+
return translator.apply(void 0, arguments);
|
|
26
|
+
}
|
|
27
|
+
// Augment `t.rich` to return plain strings
|
|
28
|
+
base.rich = function (key, /** Key value pairs for values to interpolate into the message. */
|
|
29
|
+
values, formats) {
|
|
30
|
+
// `chunks` is returned as a string when no React element
|
|
31
|
+
// is used, therefore it's safe to cast this type.
|
|
32
|
+
var result = originalRich(key, values, formats);
|
|
33
|
+
// When only string chunks are provided to the parser, only strings should be returned here.
|
|
34
|
+
if (typeof result !== 'string') {
|
|
35
|
+
var error = new IntlError(IntlErrorCode.FORMATTING_ERROR, process.env.NODE_ENV !== 'production' ? "`createTranslator` only accepts functions for rich text formatting that receive and return strings.\n\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})" : undefined);
|
|
36
|
+
onError(error);
|
|
37
|
+
return getMessageFallback({
|
|
38
|
+
error: error,
|
|
39
|
+
key: key,
|
|
40
|
+
namespace: namespace
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
base.raw = translator.raw;
|
|
46
|
+
return base;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { createTranslatorImpl as default };
|
|
50
|
+
//# sourceMappingURL=createTranslatorImpl.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTranslatorImpl.esm.js","sources":["../../src/core/createTranslatorImpl.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport {\n RichTranslationValues,\n RichTranslationValuesPlain\n} from './TranslationValues';\nimport createBaseTranslator from './createBaseTranslator';\nimport resolveNamespace from './resolveNamespace';\nimport NestedKeyOf from './utils/NestedKeyOf';\n\nexport type CreateTranslatorImplProps<Messages> = Omit<\n InitializedIntlConfig,\n 'messages'\n> & {\n namespace: string;\n messages: Messages;\n};\n\nexport default function createTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(\n {\n getMessageFallback,\n messages,\n namespace,\n onError,\n ...rest\n }: CreateTranslatorImplProps<Messages>,\n namespacePrefix: string\n) {\n // The `namespacePrefix` is part of the type system.\n // See the comment in the function invocation.\n messages = messages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const translator = createBaseTranslator<Messages, NestedKey>({\n ...rest,\n onError,\n getMessageFallback,\n messages,\n namespace\n });\n\n const originalRich = translator.rich;\n\n function base(...args: Parameters<typeof translator>) {\n return translator(...args);\n }\n\n // Augment `t.rich` to return plain strings\n base.rich = (\n key: Parameters<typeof originalRich>[0],\n /** Key value pairs for values to interpolate into the message. */\n values: RichTranslationValuesPlain,\n formats?: Parameters<typeof originalRich>[2]\n ): string => {\n // `chunks` is returned as a string when no React element\n // is used, therefore it's safe to cast this type.\n const result = originalRich(key, values as RichTranslationValues, formats);\n\n // When only string chunks are provided to the parser, only strings should be returned here.\n if (typeof result !== 'string') {\n const error = new IntlError(\n IntlErrorCode.FORMATTING_ERROR,\n process.env.NODE_ENV !== 'production'\n ? \"`createTranslator` only accepts functions for rich text formatting that receive and return strings.\\n\\nE.g. t.rich('rich', {b: (chunks) => `<b>${chunks}</b>`})\"\n : undefined\n );\n\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n return result;\n };\n\n base.raw = translator.raw;\n\n return base;\n}\n"],"names":["createTranslatorImpl","_ref","namespacePrefix","getMessageFallback","messages","namespace","onError","rest","_objectWithoutPropertiesLoose","_excluded","resolveNamespace","translator","createBaseTranslator","_extends","originalRich","rich","base","apply","arguments","key","values","formats","result","error","IntlError","IntlErrorCode","FORMATTING_ERROR","process","env","NODE_ENV","undefined","raw"],"mappings":";;;;;;AAmBc,SAAUA,oBAAoBA,CAAAC,IAAA,EAW1CC,eAAuB,EAAA;AAAA,EAAA,IANrBC,kBAAkB,GAAAF,IAAA,CAAlBE,kBAAkB;IAClBC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,SAAS,GAAAJ,IAAA,CAATI,SAAS;IACTC,OAAO,GAAAL,IAAA,CAAPK,OAAO;AACJC,IAAAA,IAAI,GAAAC,6BAAA,CAAAP,IAAA,EAAAQ,SAAA,CAAA,CAAA;AAIT;AACA;AACAL,EAAAA,QAAQ,GAAGA,QAAQ,CAACF,eAAe,CAAa,CAAA;AAChDG,EAAAA,SAAS,GAAGK,gBAAgB,CAACL,SAAS,EAAEH,eAAe,CAAc,CAAA;AAErE,EAAA,IAAMS,UAAU,GAAGC,oBAAoB,CAAAC,QAAA,KAClCN,IAAI,EAAA;AACPD,IAAAA,OAAO,EAAPA,OAAO;AACPH,IAAAA,kBAAkB,EAAlBA,kBAAkB;AAClBC,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,SAAS,EAATA,SAAAA;AAAS,GAAA,CACV,CAAC,CAAA;AAEF,EAAA,IAAMS,YAAY,GAAGH,UAAU,CAACI,IAAI,CAAA;EAEpC,SAASC,IAAIA,GAAuC;AAClD,IAAA,OAAOL,UAAU,CAAAM,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;AAC5B,GAAA;AAEA;AACAF,EAAAA,IAAI,CAACD,IAAI,GAAG,UACVI,GAAuC;EAEvCC,MAAkC,EAClCC,OAA4C,EAClC;AACV;AACA;IACA,IAAMC,MAAM,GAAGR,YAAY,CAACK,GAAG,EAAEC,MAA+B,EAAEC,OAAO,CAAC,CAAA;AAE1E;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,QAAQ,EAAE;MAC9B,IAAMC,KAAK,GAAG,IAAIC,SAAS,CACzBC,aAAa,CAACC,gBAAgB,EAC9BC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GACjC,iKAAiK,GACjKC,SAAS,CACd,CAAA;MAEDxB,OAAO,CAACiB,KAAK,CAAC,CAAA;AACd,MAAA,OAAOpB,kBAAkB,CAAC;AAACoB,QAAAA,KAAK,EAALA,KAAK;AAAEJ,QAAAA,GAAG,EAAHA,GAAG;AAAEd,QAAAA,SAAS,EAATA,SAAAA;AAAU,OAAA,CAAC,CAAA;AACnD,KAAA;AAED,IAAA,OAAOiB,MAAM,CAAA;GACd,CAAA;AAEDN,EAAAA,IAAI,CAACe,GAAG,GAAGpB,UAAU,CAACoB,GAAG,CAAA;AAEzB,EAAA,OAAOf,IAAI,CAAA;AACb;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import IntlError from './IntlError';
|
|
2
|
+
/**
|
|
3
|
+
* Contains defaults that are used for all entry points into the core.
|
|
4
|
+
* See also `InitializedIntlConfiguration`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function defaultGetMessageFallback(props: {
|
|
7
|
+
error: IntlError;
|
|
8
|
+
key: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function defaultOnError(error: IntlError): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains defaults that are used for all entry points into the core.
|
|
3
|
+
* See also `InitializedIntlConfiguration`.
|
|
4
|
+
*/
|
|
5
|
+
function defaultGetMessageFallback(props) {
|
|
6
|
+
return [props.namespace, props.key].filter(function (part) {
|
|
7
|
+
return part != null;
|
|
8
|
+
}).join('.');
|
|
9
|
+
}
|
|
10
|
+
function defaultOnError(error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { defaultGetMessageFallback, defaultOnError };
|
|
15
|
+
//# sourceMappingURL=defaults.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.esm.js","sources":["../../src/core/defaults.tsx"],"sourcesContent":["import IntlError from './IntlError';\n\n/**\n * Contains defaults that are used for all entry points into the core.\n * See also `InitializedIntlConfiguration`.\n */\n\nexport function defaultGetMessageFallback(props: {\n error: IntlError;\n key: string;\n namespace?: string;\n}) {\n return [props.namespace, props.key].filter((part) => part != null).join('.');\n}\n\nexport function defaultOnError(error: IntlError) {\n console.error(error);\n}\n"],"names":["defaultGetMessageFallback","props","namespace","key","filter","part","join","defaultOnError","error","console"],"mappings":"AAEA;;;AAGG;AAEG,SAAUA,yBAAyBA,CAACC,KAIzC,EAAA;AACC,EAAA,OAAO,CAACA,KAAK,CAACC,SAAS,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,MAAM,CAAC,UAACC,IAAI,EAAA;IAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,GAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9E,CAAA;AAEM,SAAUC,cAAcA,CAACC,KAAgB,EAAA;AAC7CC,EAAAA,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC,CAAA;AACtB;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { default as AbstractIntlMessages } from './AbstractIntlMessages';
|
|
2
|
+
export type { default as TranslationValues, RichTranslationValues, RichTranslationValuesPlain } from './TranslationValues';
|
|
3
|
+
export type { default as Formats } from './Formats';
|
|
4
|
+
export type { default as IntlConfig } from './IntlConfig';
|
|
5
|
+
export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
|
|
6
|
+
export type { default as NumberFormatOptions } from './NumberFormatOptions';
|
|
7
|
+
export { default as IntlError, IntlErrorCode } from './IntlError';
|
|
8
|
+
export { default as createTranslator } from './createTranslator';
|
|
9
|
+
export { default as createBaseTranslator } from './createBaseTranslator';
|
|
10
|
+
export { default as createFormatter } from './createFormatter';
|
|
11
|
+
export { default as initializeConfig } from './initializeConfig';
|
|
12
|
+
export { default as MessageKeys } from './utils/MessageKeys';
|
|
13
|
+
export { default as NamespaceKeys } from './utils/NamespaceKeys';
|
|
14
|
+
export { default as NestedKeyOf } from './utils/NestedKeyOf';
|
|
15
|
+
export { default as NestedValueOf } from './utils/NestedValueOf';
|
|
16
|
+
export { default as createIntl } from './createIntl';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import IntlConfig from './IntlConfig';
|
|
2
|
+
/**
|
|
3
|
+
* Enhances the incoming props with defaults.
|
|
4
|
+
*/
|
|
5
|
+
export default function initializeConfig<Props extends Omit<IntlConfig, 'children'>>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
|
|
6
|
+
messages: import("./AbstractIntlMessages").default | undefined;
|
|
7
|
+
onError: (error: import("./IntlError").default) => void;
|
|
8
|
+
getMessageFallback: (info: {
|
|
9
|
+
error: import("./IntlError").default;
|
|
10
|
+
key: string;
|
|
11
|
+
namespace?: string | undefined;
|
|
12
|
+
}) => string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.esm.js';
|
|
2
|
+
import { defaultOnError, defaultGetMessageFallback } from './defaults.esm.js';
|
|
3
|
+
import validateMessages from './validateMessages.esm.js';
|
|
4
|
+
|
|
5
|
+
var _excluded = ["getMessageFallback", "messages", "onError"];
|
|
6
|
+
/**
|
|
7
|
+
* Enhances the incoming props with defaults.
|
|
8
|
+
*/
|
|
9
|
+
function initializeConfig(_ref) {
|
|
10
|
+
var getMessageFallback = _ref.getMessageFallback,
|
|
11
|
+
messages = _ref.messages,
|
|
12
|
+
onError = _ref.onError,
|
|
13
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
14
|
+
var finalOnError = onError || defaultOnError;
|
|
15
|
+
var finalGetMessageFallback = getMessageFallback || defaultGetMessageFallback;
|
|
16
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
17
|
+
if (messages) {
|
|
18
|
+
validateMessages(messages, finalOnError);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return _extends({}, rest, {
|
|
22
|
+
messages: messages,
|
|
23
|
+
onError: finalOnError,
|
|
24
|
+
getMessageFallback: finalGetMessageFallback
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { initializeConfig as default };
|
|
29
|
+
//# sourceMappingURL=initializeConfig.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeConfig.esm.js","sources":["../../src/core/initializeConfig.tsx"],"sourcesContent":["import IntlConfig from './IntlConfig';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport validateMessages from './validateMessages';\n\n/**\n * Enhances the incoming props with defaults.\n */\nexport default function initializeConfig<\n // This is a generic to allow for stricter typing. E.g.\n // the RSC integration always provides a `now` value.\n Props extends Omit<IntlConfig, 'children'>\n>({getMessageFallback, messages, onError, ...rest}: Props) {\n const finalOnError = onError || defaultOnError;\n const finalGetMessageFallback =\n getMessageFallback || defaultGetMessageFallback;\n\n if (process.env.NODE_ENV !== 'production') {\n if (messages) {\n validateMessages(messages, finalOnError);\n }\n }\n\n return {\n ...rest,\n messages,\n onError: finalOnError,\n getMessageFallback: finalGetMessageFallback\n };\n}\n"],"names":["initializeConfig","_ref","getMessageFallback","messages","onError","rest","_objectWithoutPropertiesLoose","_excluded","finalOnError","defaultOnError","finalGetMessageFallback","defaultGetMessageFallback","process","env","NODE_ENV","validateMessages","_extends"],"mappings":";;;;;AAIA;;AAEG;AACqB,SAAAA,gBAAgBA,CAAAC,IAAA,EAIiB;AAAA,EAAA,IAAtDC,kBAAkB,GAAAD,IAAA,CAAlBC,kBAAkB;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAAEC,OAAO,GAAAH,IAAA,CAAPG,OAAO;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAC/C,EAAA,IAAMC,YAAY,GAAGJ,OAAO,IAAIK,cAAc,CAAA;AAC9C,EAAA,IAAMC,uBAAuB,GAC3BR,kBAAkB,IAAIS,yBAAyB,CAAA;AAEjD,EAAA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;AACzC,IAAA,IAAIX,QAAQ,EAAE;AACZY,MAAAA,gBAAgB,CAACZ,QAAQ,EAAEK,YAAY,CAAC,CAAA;AACzC,KAAA;AACF,GAAA;EAED,OAAAQ,QAAA,KACKX,IAAI,EAAA;AACPF,IAAAA,QAAQ,EAARA,QAAQ;AACRC,IAAAA,OAAO,EAAEI,YAAY;AACrBN,IAAAA,kBAAkB,EAAEQ,uBAAAA;AAAuB,GAAA,CAAA,CAAA;AAE/C;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
function resolveNamespace(namespace, namespacePrefix) {
|
|
6
|
+
return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { resolveNamespace as default };
|
|
10
|
+
//# sourceMappingURL=resolveNamespace.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveNamespace.esm.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { inheritsLoose as _inheritsLoose, wrapNativeSuper as _wrapNativeSuper } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
|
|
3
|
+
var IntlErrorCode;
|
|
4
|
+
(function (IntlErrorCode) {
|
|
5
|
+
IntlErrorCode["MISSING_MESSAGE"] = "MISSING_MESSAGE";
|
|
6
|
+
IntlErrorCode["MISSING_FORMAT"] = "MISSING_FORMAT";
|
|
7
|
+
IntlErrorCode["INSUFFICIENT_PATH"] = "INSUFFICIENT_PATH";
|
|
8
|
+
IntlErrorCode["INVALID_MESSAGE"] = "INVALID_MESSAGE";
|
|
9
|
+
IntlErrorCode["INVALID_KEY"] = "INVALID_KEY";
|
|
10
|
+
IntlErrorCode["FORMATTING_ERROR"] = "FORMATTING_ERROR";
|
|
11
|
+
})(IntlErrorCode || (IntlErrorCode = {}));
|
|
12
|
+
var IntlError = /*#__PURE__*/function (_Error) {
|
|
13
|
+
_inheritsLoose(IntlError, _Error);
|
|
14
|
+
function IntlError(code, originalMessage) {
|
|
15
|
+
var _this;
|
|
16
|
+
var message = code;
|
|
17
|
+
if (originalMessage) {
|
|
18
|
+
message += ': ' + originalMessage;
|
|
19
|
+
}
|
|
20
|
+
_this = _Error.call(this, message) || this;
|
|
21
|
+
_this.code = void 0;
|
|
22
|
+
_this.originalMessage = void 0;
|
|
23
|
+
_this.code = code;
|
|
24
|
+
if (originalMessage) {
|
|
25
|
+
_this.originalMessage = originalMessage;
|
|
26
|
+
}
|
|
27
|
+
return _this;
|
|
28
|
+
}
|
|
29
|
+
return IntlError;
|
|
30
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
31
|
+
|
|
32
|
+
export { IntlErrorCode, IntlError as default };
|
|
33
|
+
//# sourceMappingURL=use-intl.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm.js","sources":["../../src/core/IntlError.tsx"],"sourcesContent":["export enum IntlErrorCode {\n MISSING_MESSAGE = 'MISSING_MESSAGE',\n MISSING_FORMAT = 'MISSING_FORMAT',\n INSUFFICIENT_PATH = 'INSUFFICIENT_PATH',\n INVALID_MESSAGE = 'INVALID_MESSAGE',\n INVALID_KEY = 'INVALID_KEY',\n FORMATTING_ERROR = 'FORMATTING_ERROR'\n}\n\nexport default class IntlError extends Error {\n public readonly code: IntlErrorCode;\n public readonly originalMessage: string | undefined;\n\n constructor(code: IntlErrorCode, originalMessage?: string) {\n let message: string = code;\n if (originalMessage) {\n message += ': ' + originalMessage;\n }\n super(message);\n\n this.code = code;\n if (originalMessage) {\n this.originalMessage = originalMessage;\n }\n }\n}\n"],"names":["IntlErrorCode","IntlError","_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A;AAAC,EAAA,OAAAL,SAAA,CAAA;AAAA,CAAAQ,eAAAA,gBAAA,CAfoCC,KAAK,CAAA;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
2
|
+
|
|
3
|
+
function validateMessagesSegment(messages, invalidKeyLabels, parentPath) {
|
|
4
|
+
Object.entries(messages).forEach(function (_ref) {
|
|
5
|
+
var key = _ref[0],
|
|
6
|
+
messageOrMessages = _ref[1];
|
|
7
|
+
if (key.includes('.')) {
|
|
8
|
+
var keyLabel = key;
|
|
9
|
+
if (parentPath) keyLabel += " (at " + parentPath + ")";
|
|
10
|
+
invalidKeyLabels.push(keyLabel);
|
|
11
|
+
}
|
|
12
|
+
if (messageOrMessages != null && typeof messageOrMessages === 'object') {
|
|
13
|
+
validateMessagesSegment(messageOrMessages, invalidKeyLabels, [parentPath, key].filter(function (part) {
|
|
14
|
+
return part != null;
|
|
15
|
+
}).join('.'));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function validateMessages(messages, onError) {
|
|
20
|
+
var invalidKeyLabels = [];
|
|
21
|
+
validateMessagesSegment(messages, invalidKeyLabels);
|
|
22
|
+
if (invalidKeyLabels.length > 0) {
|
|
23
|
+
onError(new IntlError(IntlErrorCode.INVALID_KEY, process.env.NODE_ENV !== 'production' ? "Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid " + (invalidKeyLabels.length === 1 ? 'key' : 'keys') + ": " + invalidKeyLabels.join(', ') + "\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" : undefined));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { validateMessages as default };
|
|
28
|
+
//# sourceMappingURL=use-intl.esm10.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm10.js","sources":["../../src/core/validateMessages.tsx"],"sourcesContent":["import AbstractIntlMessages from './AbstractIntlMessages';\nimport IntlError, {IntlErrorCode} from './IntlError';\n\nfunction validateMessagesSegment(\n messages: AbstractIntlMessages,\n invalidKeyLabels: Array<string>,\n parentPath?: string\n) {\n Object.entries(messages).forEach(([key, messageOrMessages]) => {\n if (key.includes('.')) {\n let keyLabel = key;\n if (parentPath) keyLabel += ` (at ${parentPath})`;\n invalidKeyLabels.push(keyLabel);\n }\n\n if (messageOrMessages != null && typeof messageOrMessages === 'object') {\n validateMessagesSegment(\n messageOrMessages,\n invalidKeyLabels,\n [parentPath, key].filter((part) => part != null).join('.')\n );\n }\n });\n}\n\nexport default function validateMessages(\n messages: AbstractIntlMessages,\n onError: (error: IntlError) => void\n) {\n const invalidKeyLabels: Array<string> = [];\n validateMessagesSegment(messages, invalidKeyLabels);\n\n if (invalidKeyLabels.length > 0) {\n onError(\n new IntlError(\n IntlErrorCode.INVALID_KEY,\n process.env.NODE_ENV !== 'production'\n ? `Namespace keys can not contain the character \".\" as this is used to express nesting. Please remove it or replace it with another character.\n\nInvalid ${\n invalidKeyLabels.length === 1 ? 'key' : 'keys'\n }: ${invalidKeyLabels.join(', ')}\n\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`\n : undefined\n )\n );\n }\n}\n"],"names":["validateMessagesSegment","messages","invalidKeyLabels","parentPath","Object","entries","forEach","_ref","key","messageOrMessages","includes","keyLabel","push","filter","part","join","validateMessages","onError","length","IntlError","IntlErrorCode","INVALID_KEY","process","env","NODE_ENV","undefined"],"mappings":";;AAGA,SAASA,uBAAuBA,CAC9BC,QAA8B,EAC9BC,gBAA+B,EAC/BC,UAAmB,EAAA;EAEnBC,MAAM,CAACC,OAAO,CAACJ,QAAQ,CAAC,CAACK,OAAO,CAAC,UAAAC,IAAA,EAA6B;IAAA,IAA3BC,GAAG,GAAAD,IAAA,CAAA,CAAA,CAAA;AAAEE,MAAAA,iBAAiB,GAAAF,IAAA,CAAA,CAAA,CAAA,CAAA;AACvD,IAAA,IAAIC,GAAG,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACrB,IAAIC,QAAQ,GAAGH,GAAG,CAAA;AAClB,MAAA,IAAIL,UAAU,EAAEQ,QAAQ,IAAA,OAAA,GAAYR,UAAU,GAAG,GAAA,CAAA;AACjDD,MAAAA,gBAAgB,CAACU,IAAI,CAACD,QAAQ,CAAC,CAAA;AAChC,KAAA;IAED,IAAIF,iBAAiB,IAAI,IAAI,IAAI,OAAOA,iBAAiB,KAAK,QAAQ,EAAE;AACtET,MAAAA,uBAAuB,CACrBS,iBAAiB,EACjBP,gBAAgB,EAChB,CAACC,UAAU,EAAEK,GAAG,CAAC,CAACK,MAAM,CAAC,UAACC,IAAI,EAAA;QAAA,OAAKA,IAAI,IAAI,IAAI,CAAA;AAAA,OAAA,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,CAC3D,CAAA;AACF,KAAA;AACH,GAAC,CAAC,CAAA;AACJ,CAAA;AAEc,SAAUC,gBAAgBA,CACtCf,QAA8B,EAC9BgB,OAAmC,EAAA;EAEnC,IAAMf,gBAAgB,GAAkB,EAAE,CAAA;AAC1CF,EAAAA,uBAAuB,CAACC,QAAQ,EAAEC,gBAAgB,CAAC,CAAA;AAEnD,EAAA,IAAIA,gBAAgB,CAACgB,MAAM,GAAG,CAAC,EAAE;AAC/BD,IAAAA,OAAO,CACL,IAAIE,SAAS,CACXC,aAAa,CAACC,WAAW,EACzBC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAI/BtB,2JAAAA,IAAAA,gBAAgB,CAACgB,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,MAC1C,CAAKhB,GAAAA,IAAAA,GAAAA,gBAAgB,CAACa,IAAI,CAAC,IAAI,CAAC,GA+BhCU,4gBAAAA,GAAAA,SAAS,CACd,CACF,CAAA;AACF,GAAA;AACH;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
function resolveNamespace(namespace, namespacePrefix) {
|
|
6
|
+
return namespace === namespacePrefix ? undefined : namespace.slice((namespacePrefix + '.').length);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { resolveNamespace as default };
|
|
10
|
+
//# sourceMappingURL=use-intl.esm11.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm11.js","sources":["../../src/core/resolveNamespace.tsx"],"sourcesContent":["/**\n * For the strictly typed messages to work we have to wrap the namespace into\n * a mandatory prefix. See https://stackoverflow.com/a/71529575/343045\n */\nexport default function resolveNamespace(\n namespace: string,\n namespacePrefix: string\n) {\n return namespace === namespacePrefix\n ? undefined\n : namespace.slice((namespacePrefix + '.').length);\n}\n"],"names":["resolveNamespace","namespace","namespacePrefix","undefined","slice","length"],"mappings":"AAAA;;;AAGG;AACW,SAAUA,gBAAgBA,CACtCC,SAAiB,EACjBC,eAAuB,EAAA;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAe,GAChCC,SAAS,GACTF,SAAS,CAACG,KAAK,CAAC,CAACF,eAAe,GAAG,GAAG,EAAEG,MAAM,CAAC,CAAA;AACrD;;;;"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
import IntlMessageFormat from 'intl-messageformat';
|
|
3
|
+
import { isValidElement, cloneElement } from 'react';
|
|
4
|
+
import IntlError, { IntlErrorCode } from './use-intl.esm.js';
|
|
5
|
+
import convertFormatsToIntlMessageFormat from './use-intl.esm8.js';
|
|
6
|
+
import { defaultOnError, defaultGetMessageFallback } from './use-intl.esm7.js';
|
|
7
|
+
|
|
8
|
+
function resolvePath(messages, key, namespace) {
|
|
9
|
+
if (!messages) {
|
|
10
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages available at `" + namespace + "`." : undefined);
|
|
11
|
+
}
|
|
12
|
+
var message = messages;
|
|
13
|
+
key.split('.').forEach(function (part) {
|
|
14
|
+
var next = message[part];
|
|
15
|
+
if (part == null || next == null) {
|
|
16
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "Could not resolve `" + key + "` in " + (namespace ? "`" + namespace + "`" : 'messages') + "." : undefined);
|
|
17
|
+
}
|
|
18
|
+
message = next;
|
|
19
|
+
});
|
|
20
|
+
return message;
|
|
21
|
+
}
|
|
22
|
+
function prepareTranslationValues(values) {
|
|
23
|
+
if (Object.keys(values).length === 0) return undefined;
|
|
24
|
+
// Workaround for https://github.com/formatjs/formatjs/issues/1467
|
|
25
|
+
var transformedValues = {};
|
|
26
|
+
Object.keys(values).forEach(function (key) {
|
|
27
|
+
var index = 0;
|
|
28
|
+
var value = values[key];
|
|
29
|
+
var transformed;
|
|
30
|
+
if (typeof value === 'function') {
|
|
31
|
+
transformed = function transformed(chunks) {
|
|
32
|
+
var result = value(chunks);
|
|
33
|
+
return isValidElement(result) ? cloneElement(result, {
|
|
34
|
+
key: key + index++
|
|
35
|
+
}) : result;
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
transformed = value;
|
|
39
|
+
}
|
|
40
|
+
transformedValues[key] = transformed;
|
|
41
|
+
});
|
|
42
|
+
return transformedValues;
|
|
43
|
+
}
|
|
44
|
+
function getMessagesOrError(_ref) {
|
|
45
|
+
var messages = _ref.messages,
|
|
46
|
+
namespace = _ref.namespace,
|
|
47
|
+
_ref$onError = _ref.onError,
|
|
48
|
+
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError;
|
|
49
|
+
try {
|
|
50
|
+
if (!messages) {
|
|
51
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages were configured on the provider." : undefined);
|
|
52
|
+
}
|
|
53
|
+
var retrievedMessages = namespace ? resolvePath(messages, namespace) : messages;
|
|
54
|
+
if (!retrievedMessages) {
|
|
55
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "No messages for namespace `" + namespace + "` found." : undefined);
|
|
56
|
+
}
|
|
57
|
+
return retrievedMessages;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
var intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
60
|
+
onError(intlError);
|
|
61
|
+
return intlError;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createBaseTranslator(config) {
|
|
65
|
+
var messagesOrError = getMessagesOrError({
|
|
66
|
+
messages: config.messages,
|
|
67
|
+
namespace: config.namespace,
|
|
68
|
+
onError: config.onError
|
|
69
|
+
});
|
|
70
|
+
return createBaseTranslatorImpl(_extends({}, config, {
|
|
71
|
+
messagesOrError: messagesOrError
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
function createBaseTranslatorImpl(_ref2) {
|
|
75
|
+
var cachedFormatsByLocale = _ref2.cachedFormatsByLocale,
|
|
76
|
+
defaultTranslationValues = _ref2.defaultTranslationValues,
|
|
77
|
+
globalFormats = _ref2.formats,
|
|
78
|
+
_ref2$getMessageFallb = _ref2.getMessageFallback,
|
|
79
|
+
getMessageFallback = _ref2$getMessageFallb === void 0 ? defaultGetMessageFallback : _ref2$getMessageFallb,
|
|
80
|
+
locale = _ref2.locale,
|
|
81
|
+
messagesOrError = _ref2.messagesOrError,
|
|
82
|
+
namespace = _ref2.namespace,
|
|
83
|
+
onError = _ref2.onError,
|
|
84
|
+
timeZone = _ref2.timeZone;
|
|
85
|
+
function getFallbackFromErrorAndNotify(key, code, message) {
|
|
86
|
+
var error = new IntlError(code, message);
|
|
87
|
+
onError(error);
|
|
88
|
+
return getMessageFallback({
|
|
89
|
+
error: error,
|
|
90
|
+
key: key,
|
|
91
|
+
namespace: namespace
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function translateBaseFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
95
|
+
key, /** Key value pairs for values to interpolate into the message. */
|
|
96
|
+
values, /** Provide custom formats for numbers, dates and times. */
|
|
97
|
+
formats) {
|
|
98
|
+
var _cachedFormatsByLocal;
|
|
99
|
+
if (messagesOrError instanceof IntlError) {
|
|
100
|
+
// We have already warned about this during render
|
|
101
|
+
return getMessageFallback({
|
|
102
|
+
error: messagesOrError,
|
|
103
|
+
key: key,
|
|
104
|
+
namespace: namespace
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
var messages = messagesOrError;
|
|
108
|
+
var message;
|
|
109
|
+
try {
|
|
110
|
+
message = resolvePath(messages, key, namespace);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
113
|
+
}
|
|
114
|
+
function joinPath(parts) {
|
|
115
|
+
return parts.filter(function (part) {
|
|
116
|
+
return part != null;
|
|
117
|
+
}).join('.');
|
|
118
|
+
}
|
|
119
|
+
var cacheKey = joinPath([namespace, key, String(message)]);
|
|
120
|
+
var messageFormat;
|
|
121
|
+
if (cachedFormatsByLocale != null && (_cachedFormatsByLocal = cachedFormatsByLocale[locale]) != null && _cachedFormatsByLocal[cacheKey]) {
|
|
122
|
+
messageFormat = cachedFormatsByLocale == null ? void 0 : cachedFormatsByLocale[locale][cacheKey];
|
|
123
|
+
} else {
|
|
124
|
+
if (typeof message === 'object') {
|
|
125
|
+
var code, errorMessage;
|
|
126
|
+
if (Array.isArray(message)) {
|
|
127
|
+
code = IntlErrorCode.INVALID_MESSAGE;
|
|
128
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
129
|
+
errorMessage = "Message at `" + joinPath([namespace, key]) + "` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages";
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
code = IntlErrorCode.INSUFFICIENT_PATH;
|
|
133
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
134
|
+
errorMessage = "Message at `" + joinPath([namespace, key]) + "` resolved to an object, but only strings are supported. Use a `.` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return getFallbackFromErrorAndNotify(key, code, errorMessage);
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat(_extends({}, globalFormats, formats), timeZone));
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
143
|
+
}
|
|
144
|
+
if (cachedFormatsByLocale) {
|
|
145
|
+
if (!cachedFormatsByLocale[locale]) {
|
|
146
|
+
cachedFormatsByLocale[locale] = {};
|
|
147
|
+
}
|
|
148
|
+
cachedFormatsByLocale[locale][cacheKey] = messageFormat;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
var formattedMessage = messageFormat.format(
|
|
153
|
+
// @ts-ignore `intl-messageformat` expects a different format
|
|
154
|
+
// for rich text elements since a recent minor update. This
|
|
155
|
+
// needs to be evaluated in detail, possibly also in regards
|
|
156
|
+
// to be able to format to parts.
|
|
157
|
+
prepareTranslationValues(_extends({}, defaultTranslationValues, values)));
|
|
158
|
+
if (formattedMessage == null) {
|
|
159
|
+
throw new Error(process.env.NODE_ENV !== 'production' ? "Unable to format `" + key + "` in " + (namespace ? "namespace `" + namespace + "`" : 'messages') : undefined);
|
|
160
|
+
}
|
|
161
|
+
// Limit the function signature to return strings or React elements
|
|
162
|
+
return isValidElement(formattedMessage) ||
|
|
163
|
+
// Arrays of React elements
|
|
164
|
+
Array.isArray(formattedMessage) || typeof formattedMessage === 'string' ? formattedMessage : String(formattedMessage);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function translateFn( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
170
|
+
key, /** Key value pairs for values to interpolate into the message. */
|
|
171
|
+
values, /** Provide custom formats for numbers, dates and times. */
|
|
172
|
+
formats) {
|
|
173
|
+
var result = translateBaseFn(key, values, formats);
|
|
174
|
+
if (typeof result !== 'string') {
|
|
175
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production' ? "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." : undefined);
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
translateFn.rich = translateBaseFn;
|
|
180
|
+
translateFn.raw = function ( /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
181
|
+
key) {
|
|
182
|
+
if (messagesOrError instanceof IntlError) {
|
|
183
|
+
// We have already warned about this during render
|
|
184
|
+
return getMessageFallback({
|
|
185
|
+
error: messagesOrError,
|
|
186
|
+
key: key,
|
|
187
|
+
namespace: namespace
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
var messages = messagesOrError;
|
|
191
|
+
try {
|
|
192
|
+
return resolvePath(messages, key, namespace);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
return translateFn;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { createBaseTranslator as default };
|
|
201
|
+
//# sourceMappingURL=use-intl.esm2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm2.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["// eslint-disable-next-line import/no-named-as-default -- False positive\nimport IntlMessageFormat from 'intl-messageformat';\nimport {\n cloneElement,\n isValidElement,\n ReactElement,\n ReactNode,\n ReactNodeArray\n} from 'react';\nimport AbstractIntlMessages from './AbstractIntlMessages';\nimport Formats from './Formats';\nimport {InitializedIntlConfig} from './IntlConfig';\nimport IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\nimport {defaultGetMessageFallback, defaultOnError} from './defaults';\nimport MessageKeys from './utils/MessageKeys';\nimport NestedKeyOf from './utils/NestedKeyOf';\nimport NestedValueOf from './utils/NestedValueOf';\n\nfunction resolvePath(\n messages: AbstractIntlMessages | undefined,\n key: string,\n namespace?: string\n) {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages available at \\`${namespace}\\`.`\n : undefined\n );\n }\n\n let message = messages;\n\n key.split('.').forEach((part) => {\n const next = (message as any)[part];\n\n if (part == null || next == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Could not resolve \\`${key}\\` in ${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }.`\n : undefined\n );\n }\n\n message = next;\n });\n\n return message;\n}\n\nfunction prepareTranslationValues(values: RichTranslationValues) {\n if (Object.keys(values).length === 0) return undefined;\n\n // Workaround for https://github.com/formatjs/formatjs/issues/1467\n const transformedValues: RichTranslationValues = {};\n Object.keys(values).forEach((key) => {\n let index = 0;\n const value = values[key];\n\n let transformed;\n if (typeof value === 'function') {\n transformed = (chunks: ReactNode) => {\n const result = value(chunks);\n\n return isValidElement(result)\n ? cloneElement(result, {key: key + index++})\n : result;\n };\n } else {\n transformed = value;\n }\n\n transformedValues[key] = transformed;\n });\n\n return transformedValues;\n}\n\nfunction getMessagesOrError<Messages extends AbstractIntlMessages>({\n messages,\n namespace,\n onError = defaultOnError\n}: {\n messages?: Messages;\n namespace?: string;\n onError?(error: IntlError): void;\n}) {\n try {\n if (!messages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages were configured on the provider.`\n : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `No messages for namespace \\`${namespace}\\` found.`\n : undefined\n );\n }\n\n return retrievedMessages;\n } catch (error) {\n const intlError = new IntlError(\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n onError(intlError);\n return intlError;\n }\n}\n\nexport type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {\n cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;\n defaultTranslationValues?: RichTranslationValues;\n namespace?: string;\n messagesOrError: Messages | IntlError;\n};\n\nexport default function createBaseTranslator<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(config: Omit<CreateBaseTranslatorProps<Messages>, 'messagesOrError'>) {\n const messagesOrError = getMessagesOrError({\n messages: config.messages,\n namespace: config.namespace,\n onError: config.onError\n }) as Messages | IntlError;\n\n return createBaseTranslatorImpl<Messages, NestedKey>({\n ...config,\n messagesOrError\n });\n}\n\nfunction createBaseTranslatorImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>({\n cachedFormatsByLocale,\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback = defaultGetMessageFallback,\n locale,\n messagesOrError,\n namespace,\n onError,\n timeZone\n}: CreateBaseTranslatorProps<Messages>) {\n function getFallbackFromErrorAndNotify(\n key: string,\n code: IntlErrorCode,\n message?: string\n ) {\n const error = new IntlError(code, message);\n onError(error);\n return getMessageFallback({error, key, namespace});\n }\n\n function translateBaseFn(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string,\n /** Key value pairs for values to interpolate into the message. */\n values?: RichTranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n let message;\n try {\n message = resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n\n function joinPath(parts: Array<string | undefined>) {\n return parts.filter((part) => part != null).join('.');\n }\n\n const cacheKey = joinPath([namespace, key, String(message)]);\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\n if (typeof message === 'object') {\n let code, errorMessage;\n if (Array.isArray(message)) {\n code = IntlErrorCode.INVALID_MESSAGE;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;\n }\n } else {\n code = IntlErrorCode.INSUFFICIENT_PATH;\n if (process.env.NODE_ENV !== 'production') {\n errorMessage = `Message at \\`${joinPath([\n namespace,\n key\n ])}\\` resolved to an object, but only strings are supported. Use a \\`.\\` to retrieve nested messages. See https://next-intl-docs.vercel.app/docs/usage/messages#structuring-messages`;\n }\n }\n\n return getFallbackFromErrorAndNotify(key, code, errorMessage);\n }\n\n try {\n messageFormat = new IntlMessageFormat(\n message,\n locale,\n convertFormatsToIntlMessageFormat(\n {...globalFormats, ...formats},\n timeZone\n )\n );\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n (error as Error).message\n );\n }\n\n if (cachedFormatsByLocale) {\n if (!cachedFormatsByLocale[locale]) {\n cachedFormatsByLocale[locale] = {};\n }\n cachedFormatsByLocale[locale][cacheKey] = messageFormat;\n }\n }\n\n try {\n const formattedMessage = messageFormat.format(\n // @ts-ignore `intl-messageformat` expects a different format\n // for rich text elements since a recent minor update. This\n // needs to be evaluated in detail, possibly also in regards\n // to be able to format to parts.\n prepareTranslationValues({...defaultTranslationValues, ...values})\n );\n\n if (formattedMessage == null) {\n throw new Error(\n process.env.NODE_ENV !== 'production'\n ? `Unable to format \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n }`\n : undefined\n );\n }\n\n // Limit the function signature to return strings or React elements\n return isValidElement(formattedMessage) ||\n // Arrays of React elements\n Array.isArray(formattedMessage) ||\n typeof formattedMessage === 'string'\n ? formattedMessage\n : String(formattedMessage);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.FORMATTING_ERROR,\n (error as Error).message\n );\n }\n }\n\n function translateFn<\n TargetKey extends MessageKeys<\n NestedValueOf<Messages, NestedKey>,\n NestedKeyOf<NestedValueOf<Messages, NestedKey>>\n >\n >(\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: TargetKey,\n /** Key value pairs for values to interpolate into the message. */\n values?: TranslationValues,\n /** Provide custom formats for numbers, dates and times. */\n formats?: Partial<Formats>\n ): string {\n const result = translateBaseFn(key, values, formats);\n\n if (typeof result !== 'string') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INVALID_MESSAGE,\n process.env.NODE_ENV !== 'production'\n ? `The message \\`${key}\\` in ${\n namespace ? `namespace \\`${namespace}\\`` : 'messages'\n } didn't resolve to a string. If you want to format rich text, use \\`t.rich\\` instead.`\n : undefined\n );\n }\n\n return result;\n }\n\n translateFn.rich = translateBaseFn;\n\n translateFn.raw = (\n /** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */\n key: string\n ): any => {\n if (messagesOrError instanceof IntlError) {\n // We have already warned about this during render\n return getMessageFallback({\n error: messagesOrError,\n key,\n namespace\n });\n }\n const messages = messagesOrError;\n\n try {\n return resolvePath(messages, key, namespace);\n } catch (error) {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.MISSING_MESSAGE,\n (error as Error).message\n );\n }\n };\n\n return translateFn;\n}\n"],"names":["resolvePath","messages","key","namespace","Error","process","env","NODE_ENV","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","_ref","_ref$onError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","createBaseTranslator","config","messagesOrError","createBaseTranslatorImpl","_extends","_ref2","cachedFormatsByLocale","defaultTranslationValues","globalFormats","formats","_ref2$getMessageFallb","getMessageFallback","defaultGetMessageFallback","locale","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","_cachedFormatsByLocal","joinPath","parts","filter","join","cacheKey","String","messageFormat","errorMessage","Array","isArray","INVALID_MESSAGE","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","formattedMessage","format","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAoBA,SAASA,WAAWA,CAClBC,QAA0C,EAC1CC,GAAW,EACXC,SAAkB,EAAA;EAElB,IAAI,CAACF,QAAQ,EAAE;AACb,IAAA,MAAM,IAAIG,KAAK,CACbC,OAAO,CAACC,GAAG,CAACC,QAA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ecated Switch to `createFormatter` */
|
|
4
|
+
function createIntl() {
|
|
5
|
+
var formatter = createFormatter.apply(void 0, arguments);
|
|
6
|
+
return {
|
|
7
|
+
formatDateTime: formatter.dateTime,
|
|
8
|
+
formatNumber: formatter.number,
|
|
9
|
+
formatRelativeTime: formatter.relativeTime
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { createIntl as default };
|
|
14
|
+
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/core/createIntl.tsx"],"sourcesContent":["import createFormatter from './createFormatter';\n\n/** @deprecated Switch to `createFormatter` */\nexport default function createIntl(\n ...args: Parameters<typeof createFormatter>\n) {\n const formatter = createFormatter(...args);\n return {\n formatDateTime: formatter.dateTime,\n formatNumber: formatter.number,\n formatRelativeTime: formatter.relativeTime\n };\n}\n"],"names":["createIntl","formatter","createFormatter","apply","arguments","formatDateTime","dateTime","formatNumber","number","formatRelativeTime","relativeTime"],"mappings":";;AAEA;AACc,SAAUA,UAAUA,GACW;AAE3C,EAAA,IAAMC,SAAS,GAAGC,eAAe,CAAAC,KAAA,CAAA,KAAA,CAAA,EAAAC,SAAQ,CAAC,CAAA;EAC1C,OAAO;IACLC,cAAc,EAAEJ,SAAS,CAACK,QAAQ;IAClCC,YAAY,EAAEN,SAAS,CAACO,MAAM;IAC9BC,kBAAkB,EAAER,SAAS,CAACS,YAAAA;GAC/B,CAAA;AACH;;;;"}
|