use-intl 2.7.5 → 2.7.7-alpha.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/dist/{AbstractIntlMessages.d.ts → core/AbstractIntlMessages.d.ts} +0 -0
- package/dist/{DateTimeFormatOptions.d.ts → core/DateTimeFormatOptions.d.ts} +0 -0
- package/dist/{Formats.d.ts → core/Formats.d.ts} +0 -0
- package/dist/{IntlError.d.ts → core/IntlError.d.ts} +0 -0
- package/dist/{IntlMessages.d.ts → core/IntlMessages.d.ts} +0 -0
- package/dist/{NumberFormatOptions.d.ts → core/NumberFormatOptions.d.ts} +0 -0
- package/dist/{TranslationValues.d.ts → core/TranslationValues.d.ts} +2 -2
- package/dist/core/config.d.ts +6 -0
- package/dist/{convertFormatsToIntlMessageFormat.d.ts → core/convertFormatsToIntlMessageFormat.d.ts} +0 -0
- package/dist/core/createBaseTranslator.d.ts +34 -0
- package/dist/{useIntl.d.ts → core/createIntl.d.ts} +11 -1
- package/dist/core/createTranslator.d.ts +47 -0
- package/dist/core/createTranslatorImpl.d.ts +21 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/resolveNamespace.d.ts +5 -0
- package/dist/core/use-intl.esm.js +32 -0
- package/dist/core/use-intl.esm.js.map +1 -0
- package/dist/{use-intl.esm8.js → core/use-intl.esm2.js} +2 -2
- package/dist/core/use-intl.esm2.js.map +1 -0
- package/dist/{use-intl.esm4.js → core/use-intl.esm3.js} +12 -12
- package/dist/core/use-intl.esm3.js.map +1 -0
- package/dist/core/use-intl.esm4.js +61 -0
- package/dist/core/use-intl.esm4.js.map +1 -0
- package/dist/core/use-intl.esm5.js +13 -0
- package/dist/core/use-intl.esm5.js.map +1 -0
- package/dist/{use-intl.esm10.js → core/use-intl.esm6.js} +2 -2
- package/dist/core/use-intl.esm6.js.map +1 -0
- package/dist/core/use-intl.esm7.js +213 -0
- package/dist/core/use-intl.esm7.js.map +1 -0
- package/dist/core/use-intl.esm8.js +10 -0
- package/dist/core/use-intl.esm8.js.map +1 -0
- package/dist/{use-intl.esm13.js → core/use-intl.esm9.js} +2 -2
- package/dist/core/use-intl.esm9.js.map +1 -0
- package/dist/{utils → core/utils}/MessageKeys.d.ts +0 -0
- package/dist/{utils → core/utils}/NamespaceKeys.d.ts +0 -0
- package/dist/{utils → core/utils}/NestedKeyOf.d.ts +0 -0
- package/dist/{utils → core/utils}/NestedValueOf.d.ts +0 -0
- package/dist/{validateMessages.d.ts → core/validateMessages.d.ts} +0 -0
- package/dist/index.d.ts +2 -12
- package/dist/{IntlContext.d.ts → react/IntlContext.d.ts} +4 -4
- package/dist/{IntlProvider.d.ts → react/IntlProvider.d.ts} +4 -4
- package/dist/react/index.d.ts +6 -0
- package/dist/react/use-intl.esm.js +25 -0
- package/dist/react/use-intl.esm.js.map +1 -0
- package/dist/{use-intl.esm3.js → react/use-intl.esm2.js} +4 -4
- package/dist/react/use-intl.esm2.js.map +1 -0
- package/dist/{use-intl.esm7.js → react/use-intl.esm3.js} +2 -2
- package/dist/react/use-intl.esm3.js.map +1 -0
- package/dist/{use-intl.esm6.js → react/use-intl.esm4.js} +2 -2
- package/dist/react/use-intl.esm4.js.map +1 -0
- package/dist/react/use-intl.esm5.js +36 -0
- package/dist/react/use-intl.esm5.js.map +1 -0
- package/dist/{use-intl.esm5.js → react/use-intl.esm6.js} +2 -2
- package/dist/react/use-intl.esm6.js.map +1 -0
- package/dist/{use-intl.esm11.js → react/use-intl.esm7.js} +1 -1
- package/dist/react/use-intl.esm7.js.map +1 -0
- package/dist/react/use-intl.esm8.js +44 -0
- package/dist/react/use-intl.esm8.js.map +1 -0
- package/dist/{use-intl.esm9.js → react/use-intl.esm9.js} +0 -0
- package/dist/react/use-intl.esm9.js.map +1 -0
- package/dist/react/useIntl.d.ts +5 -0
- package/dist/{useIntlContext.d.ts → react/useIntlContext.d.ts} +0 -0
- package/dist/{useLocale.d.ts → react/useLocale.d.ts} +0 -0
- package/dist/{useNow.d.ts → react/useNow.d.ts} +0 -0
- package/dist/{useTimeZone.d.ts → react/useTimeZone.d.ts} +0 -0
- package/dist/{useTranslations.d.ts → react/useTranslations.d.ts} +6 -6
- package/dist/react/useTranslationsImpl.d.ts +8 -0
- package/dist/use-intl.cjs.development.js +363 -218
- package/dist/use-intl.cjs.development.js.map +1 -1
- package/dist/use-intl.cjs.production.min.js +1 -1
- package/dist/use-intl.cjs.production.min.js.map +1 -1
- package/dist/use-intl.esm.js +9 -7
- package/dist/use-intl.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/{AbstractIntlMessages.tsx → core/AbstractIntlMessages.tsx} +0 -0
- package/src/{DateTimeFormatOptions.tsx → core/DateTimeFormatOptions.tsx} +0 -0
- package/src/{Formats.tsx → core/Formats.tsx} +0 -0
- package/src/{IntlError.tsx → core/IntlError.tsx} +0 -0
- package/src/{IntlMessages.tsx → core/IntlMessages.tsx} +0 -0
- package/src/{NumberFormatOptions.tsx → core/NumberFormatOptions.tsx} +0 -0
- package/src/{TranslationValues.tsx → core/TranslationValues.tsx} +8 -2
- package/src/core/config.tsx +15 -0
- package/src/{convertFormatsToIntlMessageFormat.tsx → core/convertFormatsToIntlMessageFormat.tsx} +0 -0
- package/src/core/createBaseTranslator.tsx +323 -0
- package/src/{useIntl.tsx → core/createIntl.tsx} +17 -4
- package/src/core/createTranslator.tsx +110 -0
- package/src/core/createTranslatorImpl.tsx +95 -0
- package/src/core/index.tsx +11 -0
- package/src/core/resolveNamespace.tsx +12 -0
- package/src/{utils → core/utils}/MessageKeys.tsx +0 -0
- package/src/{utils → core/utils}/NamespaceKeys.tsx +0 -0
- package/src/{utils → core/utils}/NestedKeyOf.tsx +0 -0
- package/src/{utils → core/utils}/NestedValueOf.tsx +0 -0
- package/src/{validateMessages.tsx → core/validateMessages.tsx} +0 -0
- package/src/index.tsx +2 -15
- package/src/{IntlContext.tsx → react/IntlContext.tsx} +4 -4
- package/src/{IntlProvider.tsx → react/IntlProvider.tsx} +6 -19
- package/src/react/index.tsx +6 -0
- package/src/react/useIntl.tsx +19 -0
- package/src/{useIntlContext.tsx → react/useIntlContext.tsx} +0 -0
- package/src/{useLocale.tsx → react/useLocale.tsx} +0 -0
- package/src/{useNow.tsx → react/useNow.tsx} +0 -0
- package/src/{useTimeZone.tsx → react/useTimeZone.tsx} +0 -0
- package/src/{useTranslations.tsx → react/useTranslations.tsx} +9 -7
- package/src/react/useTranslationsImpl.tsx +64 -0
- package/dist/use-intl.esm10.js.map +0 -1
- package/dist/use-intl.esm11.js.map +0 -1
- package/dist/use-intl.esm12.js +0 -213
- package/dist/use-intl.esm12.js.map +0 -1
- package/dist/use-intl.esm13.js.map +0 -1
- package/dist/use-intl.esm2.js +0 -48
- package/dist/use-intl.esm2.js.map +0 -1
- package/dist/use-intl.esm3.js.map +0 -1
- package/dist/use-intl.esm4.js.map +0 -1
- package/dist/use-intl.esm5.js.map +0 -1
- package/dist/use-intl.esm6.js.map +0 -1
- package/dist/use-intl.esm7.js.map +0 -1
- package/dist/use-intl.esm8.js.map +0 -1
- package/dist/use-intl.esm9.js.map +0 -1
- package/dist/useTranslationsImpl.d.ts +0 -12
- package/src/useTranslationsImpl.tsx +0 -328
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/core/createBaseTranslator.tsx"],"sourcesContent":["import 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 IntlError, {IntlErrorCode} from './IntlError';\nimport TranslationValues, {RichTranslationValues} from './TranslationValues';\nimport {defaultGetMessageFallback, defaultOnError} from './config';\nimport convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';\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 __DEV__ ? `No messages available at \\`${namespace}\\`.` : 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 __DEV__\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\nexport function 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 __DEV__ ? `No messages were configured on the provider.` : undefined\n );\n }\n\n const retrievedMessages = namespace\n ? resolvePath(messages, namespace)\n : messages;\n\n if (!retrievedMessages) {\n throw new Error(\n __DEV__\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> = {\n cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;\n defaultTranslationValues?: RichTranslationValues;\n formats?: Partial<Formats>;\n getMessageFallback?(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n locale: string;\n messagesOrError: Messages | IntlError;\n namespace?: string;\n onError(error: IntlError): void;\n timeZone?: string;\n};\n\nexport default function createBaseTranslator<\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 const cacheKey = [namespace, key].filter((part) => part != null).join('.');\n\n let messageFormat;\n if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {\n messageFormat = cachedFormatsByLocale?.[locale][cacheKey];\n } else {\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 if (typeof message === 'object') {\n return getFallbackFromErrorAndNotify(\n key,\n IntlErrorCode.INSUFFICIENT_PATH,\n __DEV__\n ? `Insufficient path specified for \\`${key}\\` in \\`${\n namespace ? `\\`${namespace}\\`` : 'messages'\n }\\`.`\n : undefined\n );\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 __DEV__\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 __DEV__\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","undefined","message","split","forEach","part","next","prepareTranslationValues","values","Object","keys","length","transformedValues","index","value","transformed","chunks","result","isValidElement","cloneElement","getMessagesOrError","onError","defaultOnError","retrievedMessages","error","intlError","IntlError","IntlErrorCode","MISSING_MESSAGE","createBaseTranslator","cachedFormatsByLocale","defaultTranslationValues","globalFormats","formats","getMessageFallback","defaultGetMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","cacheKey","filter","join","messageFormat","INSUFFICIENT_PATH","IntlMessageFormat","convertFormatsToIntlMessageFormat","INVALID_MESSAGE","formattedMessage","format","Array","isArray","String","FORMATTING_ERROR","translateFn","rich","raw"],"mappings":";;;;;;;AAkBA,SAASA,WAAT,CACEC,QADF,EAEEC,GAFF,EAGEC,SAHF,EAGoB;AAElB,EAAI,IAAA,CAACF,QAAL,EAAe;AACb,IAAA,MAAM,IAAIG,KAAJ,CACJ,uEAAwCD,SAAxC,GAAA,IAAA,GAAyDE,SADrD,CAAN,CAAA;AAGD,GAAA;;AAED,EAAIC,IAAAA,OAAO,GAAGL,QAAd,CAAA;AAEAC,EAAAA,GAAG,CAACK,KAAJ,CAAU,GAAV,EAAeC,OAAf,CAAuB,UAACC,IAAD,EAAS;AAC9B,IAAA,IAAMC,IAAI,GAAIJ,OAAe,CAACG,IAAD,CAA7B,CAAA;;AAEA,IAAA,IAAIA,IAAI,IAAI,IAAR,IAAgBC,IAAI,IAAI,IAA5B,EAAkC;AAChC,MAAA,MAAM,IAAIN,KAAJ,CACJ,OAAA,CAAA,GAAA,CAAA,QA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ACD;;;;"}
|
|
@@ -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.esm8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.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,gBAAV,CACZC,SADY,EAEZC,eAFY,EAEW;AAEvB,EAAA,OAAOD,SAAS,KAAKC,eAAd,GACHC,SADG,GAEHF,SAAS,CAACG,KAAV,CAAgB,CAACF,eAAe,GAAG,GAAnB,EAAwBG,MAAxC,CAFJ,CAAA;AAGD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extends as _extends } from '
|
|
1
|
+
import { extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
2
|
|
|
3
3
|
function setTimeZoneInFormats(formats, timeZone) {
|
|
4
4
|
if (!formats) return formats; // The only way to set a time zone with `intl-messageformat` is to merge it into the formats
|
|
@@ -31,4 +31,4 @@ function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export { convertFormatsToIntlMessageFormat as default };
|
|
34
|
-
//# sourceMappingURL=use-intl.
|
|
34
|
+
//# sourceMappingURL=use-intl.esm9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: string\n) {\n if (!formats) return formats;\n\n // The only way to set a time zone with `intl-messageformat` is to merge it into the formats\n // https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15\n return Object.keys(formats).reduce(\n (acc: Record<string, DateTimeFormatOptions>, key) => {\n acc[key] = {\n timeZone,\n ...formats[key]\n };\n return acc;\n },\n {}\n );\n}\n\n/**\n * `intl-messageformat` uses separate keys for `date` and `time`, but there's\n * only one native API: `Intl.DateTimeFormat`. Additionally you might want to\n * include both a time and a date in a value, therefore the separation doesn't\n * seem so useful. We offer a single `dateTime` namespace instead, but we have\n * to convert the format before `intl-messageformat` can be used.\n */\nexport default function convertFormatsToIntlMessageFormat(\n formats: Partial<Formats>,\n timeZone?: string\n): Partial<IntlFormats> {\n const formatsWithTimeZone = timeZone\n ? {...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone)}\n : formats;\n\n return {\n ...formatsWithTimeZone,\n date: formatsWithTimeZone?.dateTime,\n time: formatsWithTimeZone?.dateTime\n };\n}\n"],"names":["setTimeZoneInFormats","formats","timeZone","Object","keys","reduce","acc","key","convertFormatsToIntlMessageFormat","formatsWithTimeZone","dateTime","date","time"],"mappings":";;AAIA,SAASA,oBAAT,CACEC,OADF,EAEEC,QAFF,EAEkB;AAEhB,EAAA,IAAI,CAACD,OAAL,EAAc,OAAOA,OAAP,CAFE;AAKhB;;AACA,EAAA,OAAOE,MAAM,CAACC,IAAP,CAAYH,OAAZ,CAAA,CAAqBI,MAArB,CACL,UAACC,GAAD,EAA6CC,GAA7C,EAAoD;AAClDD,IAAAA,GAAG,CAACC,GAAD,CAAH,GAAA,QAAA,CAAA;AACEL,MAAAA,QAAQ,EAARA,QAAAA;AADF,KAEKD,EAAAA,OAAO,CAACM,GAAD,CAFZ,CAAA,CAAA;AAIA,IAAA,OAAOD,GAAP,CAAA;AACD,GAPI,EAQL,EARK,CAAP,CAAA;AAUD,CAAA;AAED;;;;;;AAMG;;;AACW,SAAUE,iCAAV,CACZP,OADY,EAEZC,QAFY,EAEK;AAEjB,EAAA,IAAMO,mBAAmB,GAAGP,QAAQ,GAAA,QAAA,CAAA,EAAA,EAC5BD,OAD4B,EAAA;AACnBS,IAAAA,QAAQ,EAAEV,oBAAoB,CAACC,OAAO,CAACS,QAAT,EAAmBR,QAAnB,CAAA;AADX,GAAA,CAAA,GAEhCD,OAFJ,CAAA;AAIA,EAAA,OAAA,QAAA,CAAA,EAAA,EACKQ,mBADL,EAAA;AAEEE,IAAAA,IAAI,EAAEF,mBAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,mBAAmB,CAAEC,QAF7B;AAGEE,IAAAA,IAAI,EAAEH,mBAAF,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEA,mBAAmB,CAAEC,QAAAA;AAH7B,GAAA,CAAA,CAAA;AAKD;;;;"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export { default as useTranslations } from './useTranslations';
|
|
4
|
-
export { default as TranslationValues, RichTranslationValues } from './TranslationValues';
|
|
5
|
-
export { default as useIntl } from './useIntl';
|
|
6
|
-
export { default as useLocale } from './useLocale';
|
|
7
|
-
export { default as useNow } from './useNow';
|
|
8
|
-
export { default as useTimeZone } from './useTimeZone';
|
|
9
|
-
export { default as Formats } from './Formats';
|
|
10
|
-
export { default as DateTimeFormatOptions } from './DateTimeFormatOptions';
|
|
11
|
-
export { default as NumberFormatOptions } from './NumberFormatOptions';
|
|
12
|
-
export { default as IntlError, IntlErrorCode } from './IntlError';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './react';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import AbstractIntlMessages from '
|
|
3
|
-
import Formats from '
|
|
4
|
-
import IntlError from '
|
|
5
|
-
import { RichTranslationValues } from '
|
|
2
|
+
import AbstractIntlMessages from '../core/AbstractIntlMessages';
|
|
3
|
+
import Formats from '../core/Formats';
|
|
4
|
+
import IntlError from '../core/IntlError';
|
|
5
|
+
import { RichTranslationValues } from '../core/TranslationValues';
|
|
6
6
|
export declare type IntlContextShape = {
|
|
7
7
|
messages?: AbstractIntlMessages;
|
|
8
8
|
locale: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import AbstractIntlMessages from '
|
|
3
|
-
import Formats from '
|
|
4
|
-
import IntlError from '
|
|
5
|
-
import { RichTranslationValues } from '
|
|
2
|
+
import AbstractIntlMessages from '../core/AbstractIntlMessages';
|
|
3
|
+
import Formats from '../core/Formats';
|
|
4
|
+
import IntlError from '../core/IntlError';
|
|
5
|
+
import { RichTranslationValues } from '../core/TranslationValues';
|
|
6
6
|
declare type Props = {
|
|
7
7
|
/** All messages that will be available in your components. */
|
|
8
8
|
messages?: AbstractIntlMessages;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as IntlProvider } from './IntlProvider';
|
|
2
|
+
export { default as useTranslations } from './useTranslations';
|
|
3
|
+
export { default as useIntl } from './useIntl';
|
|
4
|
+
export { default as useLocale } from './useLocale';
|
|
5
|
+
export { default as useNow } from './useNow';
|
|
6
|
+
export { default as useTimeZone } from './useTimeZone';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import createIntl from '../core/use-intl.esm3.js';
|
|
3
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
4
|
+
|
|
5
|
+
function useIntl() {
|
|
6
|
+
var _useIntlContext = useIntlContext(),
|
|
7
|
+
formats = _useIntlContext.formats,
|
|
8
|
+
locale = _useIntlContext.locale,
|
|
9
|
+
globalNow = _useIntlContext.now,
|
|
10
|
+
onError = _useIntlContext.onError,
|
|
11
|
+
timeZone = _useIntlContext.timeZone;
|
|
12
|
+
|
|
13
|
+
return useMemo(function () {
|
|
14
|
+
return createIntl({
|
|
15
|
+
formats: formats,
|
|
16
|
+
locale: locale,
|
|
17
|
+
now: globalNow,
|
|
18
|
+
onError: onError,
|
|
19
|
+
timeZone: timeZone
|
|
20
|
+
});
|
|
21
|
+
}, [formats, globalNow, locale, onError, timeZone]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { useIntl as default };
|
|
25
|
+
//# sourceMappingURL=use-intl.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm.js","sources":["../../src/react/useIntl.tsx"],"sourcesContent":["import {useMemo} from 'react';\nimport createIntl from '../core/createIntl';\nimport useIntlContext from './useIntlContext';\n\nexport default function useIntl() {\n const {formats, locale, now: globalNow, onError, timeZone} = useIntlContext();\n\n return useMemo(\n () =>\n createIntl({\n formats,\n locale,\n now: globalNow,\n onError,\n timeZone\n }),\n [formats, globalNow, locale, onError, timeZone]\n );\n}\n"],"names":["useIntl","useIntlContext","formats","locale","globalNow","now","onError","timeZone","useMemo","createIntl"],"mappings":";;;;AAIc,SAAUA,OAAV,GAAiB;AAC7B,EAAA,IAAA,eAAA,GAA6DC,cAAc,EAA3E;AAAA,MAAOC,OAAP,mBAAOA,OAAP;AAAA,MAAgBC,MAAhB,mBAAgBA,MAAhB;AAAA,MAA6BC,SAA7B,mBAAwBC,GAAxB;AAAA,MAAwCC,OAAxC,mBAAwCA,OAAxC;AAAA,MAAiDC,QAAjD,mBAAiDA,QAAjD,CAAA;;AAEA,EAAA,OAAOC,OAAO,CACZ,YAAA;AAAA,IAAA,OACEC,UAAU,CAAC;AACTP,MAAAA,OAAO,EAAPA,OADS;AAETC,MAAAA,MAAM,EAANA,MAFS;AAGTE,MAAAA,GAAG,EAAED,SAHI;AAITE,MAAAA,OAAO,EAAPA,OAJS;AAKTC,MAAAA,QAAQ,EAARA,QAAAA;AALS,KAAD,CADZ,CAAA;AAAA,GADY,EASZ,CAACL,OAAD,EAAUE,SAAV,EAAqBD,MAArB,EAA6BG,OAA7B,EAAsCC,QAAtC,CATY,CAAd,CAAA;AAWD;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import useIntlContext from './use-intl.
|
|
2
|
-
import useTranslationsImpl from './use-intl.
|
|
1
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
2
|
+
import useTranslationsImpl from './use-intl.esm8.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Translates messages from the given namespace by using the ICU syntax.
|
|
@@ -14,7 +14,7 @@ function useTranslations(namespace) {
|
|
|
14
14
|
var context = useIntlContext();
|
|
15
15
|
var messages = context.messages; // We have to wrap the actual hook so the type inference for the optional
|
|
16
16
|
// namespace works correctly. See https://stackoverflow.com/a/71529575/343045
|
|
17
|
-
// The prefix ("!"
|
|
17
|
+
// The prefix ("!") is arbitrary.
|
|
18
18
|
|
|
19
19
|
return useTranslationsImpl({
|
|
20
20
|
'!': messages
|
|
@@ -23,4 +23,4 @@ function useTranslations(namespace) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export { useTranslations as default };
|
|
26
|
-
//# sourceMappingURL=use-intl.
|
|
26
|
+
//# sourceMappingURL=use-intl.esm2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm2.js","sources":["../../src/react/useTranslations.tsx"],"sourcesContent":["import {ReactElement, ReactNodeArray} from 'react';\nimport Formats from '../core/Formats';\nimport TranslationValues, {\n RichTranslationValues\n} from '../core/TranslationValues';\nimport MessageKeys from '../core/utils/MessageKeys';\nimport NamespaceKeys from '../core/utils/NamespaceKeys';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport NestedValueOf from '../core/utils/NestedValueOf';\nimport useIntlContext from './useIntlContext';\nimport useTranslationsImpl from './useTranslationsImpl';\n\n/**\n * Translates messages from the given namespace by using the ICU syntax.\n * See https://formatjs.io/docs/core-concepts/icu-syntax.\n *\n * If no namespace is provided, all available messages are returned.\n * The namespace can also indicate nesting by using a dot\n * (e.g. `namespace.Component`).\n */\nexport default function useTranslations<\n NestedKey extends NamespaceKeys<\n IntlMessages,\n NestedKeyOf<IntlMessages>\n > = never\n>(\n namespace?: NestedKey\n): // Explicitly defining the return type is necessary as TypeScript would get it wrong\n{\n // Default invocation\n <\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: TranslationValues,\n formats?: Partial<Formats>\n ): string;\n\n // `rich`\n rich<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey,\n values?: RichTranslationValues,\n formats?: Partial<Formats>\n ): string | ReactElement | ReactNodeArray;\n\n // `raw`\n raw<\n TargetKey extends MessageKeys<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >,\n NestedKeyOf<\n NestedValueOf<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >\n >\n >\n >(\n key: TargetKey\n ): any;\n} {\n const context = useIntlContext();\n const messages = context.messages as IntlMessages;\n\n // We have to wrap the actual hook so the type inference for the optional\n // namespace works correctly. See https://stackoverflow.com/a/71529575/343045\n // The prefix (\"!\") is arbitrary.\n return useTranslationsImpl<\n {'!': IntlMessages},\n [NestedKey] extends [never] ? '!' : `!.${NestedKey}`\n >(\n {'!': messages},\n // @ts-ignore\n namespace ? `!.${namespace}` : '!',\n '!'\n );\n}\n"],"names":["useTranslations","namespace","context","useIntlContext","messages","useTranslationsImpl"],"mappings":";;;AAYA;;;;;;;AAOG;;AACqB,SAAAA,eAAA,CAMtBC,SANsB,EAMD;AA6DrB,EAAMC,IAAAA,OAAO,GAAGC,cAAc,EAA9B,CAAA;AACA,EAAA,IAAMC,QAAQ,GAAGF,OAAO,CAACE,QAAzB,CA9DqB;AAiErB;AACA;;AACA,EAAA,OAAOC,mBAAmB,CAIxB;AAAC,IAAKD,GAAAA,EAAAA,QAAAA;AAAN,GAJwB;AAMxBH,EAAAA,SAAS,GAAQA,IAAAA,GAAAA,SAAR,GAAsB,GANP,EAOxB,GAPwB,CAA1B,CAAA;AASD;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import useIntlContext from './use-intl.
|
|
1
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
2
2
|
|
|
3
3
|
function useTimeZone() {
|
|
4
4
|
return useIntlContext().timeZone;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export { useTimeZone as default };
|
|
8
|
-
//# sourceMappingURL=use-intl.
|
|
8
|
+
//# sourceMappingURL=use-intl.esm3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm3.js","sources":["../../src/react/useTimeZone.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useTimeZone() {\n return useIntlContext().timeZone;\n}\n"],"names":["useTimeZone","useIntlContext","timeZone"],"mappings":";;AAEc,SAAUA,WAAV,GAAqB;AACjC,EAAOC,OAAAA,cAAc,GAAGC,QAAxB,CAAA;AACD;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import useIntlContext from './use-intl.
|
|
2
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
3
3
|
|
|
4
4
|
function getNow() {
|
|
5
5
|
return new Date();
|
|
@@ -47,4 +47,4 @@ function useNow(options) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export { useNow as default };
|
|
50
|
-
//# sourceMappingURL=use-intl.
|
|
50
|
+
//# sourceMappingURL=use-intl.esm4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm4.js","sources":["../../src/react/useNow.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\nimport useIntlContext from './useIntlContext';\n\ntype Options = {\n updateInterval?: number;\n};\n\nfunction getNow() {\n return new Date();\n}\n\n/**\n * Reading the current date via `new Date()` in components should be avoided, as\n * it causes components to be impure and can lead to flaky tests. Instead, this\n * hook can be used.\n *\n * By default, it returns the time when the component mounts. If `updateInterval`\n * is specified, the value will be updated based on the interval.\n *\n * You can however also return a static value from this hook, if you\n * configure the `now` parameter on the context provider. Note however,\n * that if `updateInterval` is configured in this case, the component\n * will initialize with the global value, but will afterwards update\n * continuously based on the interval.\n *\n * For unit tests, this can be mocked to a constant value. For end-to-end\n * testing, an environment parameter can be passed to the `now` parameter\n * of the provider to mock this to a static value.\n */\nexport default function useNow(options?: Options) {\n const updateInterval = options?.updateInterval;\n\n const {now: globalNow} = useIntlContext();\n const [now, setNow] = useState(globalNow || getNow());\n\n useEffect(() => {\n if (!updateInterval) return;\n\n const intervalId = setInterval(() => {\n setNow(getNow());\n }, updateInterval);\n\n return () => {\n clearInterval(intervalId);\n };\n }, [globalNow, updateInterval]);\n\n return now;\n}\n"],"names":["getNow","Date","useNow","options","updateInterval","useIntlContext","globalNow","now","useState","setNow","useEffect","intervalId","setInterval","clearInterval"],"mappings":";;;AAOA,SAASA,MAAT,GAAe;AACb,EAAO,OAAA,IAAIC,IAAJ,EAAP,CAAA;AACD,CAAA;AAED;;;;;;;;;;;;;;;;;AAiBG;;;AACqB,SAAAC,MAAA,CAAOC,OAAP,EAAwB;AAC9C,EAAA,IAAMC,cAAc,GAAGD,OAAH,IAAGA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,OAAO,CAAEC,cAAhC,CAAA;;AAEA,EAAA,IAAA,eAAA,GAAyBC,cAAc,EAAvC;AAAA,MAAYC,SAAZ,mBAAOC,GAAP,CAAA;;AACA,EAAA,IAAA,SAAA,GAAsBC,QAAQ,CAACF,SAAS,IAAIN,MAAM,EAApB,CAA9B;AAAA,MAAOO,GAAP,GAAA,SAAA,CAAA,CAAA,CAAA;AAAA,MAAYE,MAAZ,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;;AAEAC,EAAAA,SAAS,CAAC,YAAK;AACb,IAAI,IAAA,CAACN,cAAL,EAAqB,OAAA;AAErB,IAAA,IAAMO,UAAU,GAAGC,WAAW,CAAC,YAAK;AAClCH,MAAAA,MAAM,CAACT,MAAM,EAAP,CAAN,CAAA;AACD,KAF6B,EAE3BI,cAF2B,CAA9B,CAAA;AAIA,IAAA,OAAO,YAAK;AACVS,MAAAA,aAAa,CAACF,UAAD,CAAb,CAAA;AACD,KAFD,CAAA;AAGD,GAVQ,EAUN,CAACL,SAAD,EAAYF,cAAZ,CAVM,CAAT,CAAA;AAYA,EAAA,OAAOG,GAAP,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/use-intl.esm.js';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import { defaultOnError, defaultGetMessageFallback } from '../core/use-intl.esm5.js';
|
|
4
|
+
import validateMessages from '../core/use-intl.esm6.js';
|
|
5
|
+
import IntlContext from './use-intl.esm9.js';
|
|
6
|
+
|
|
7
|
+
var _excluded = ["children", "onError", "getMessageFallback", "messages"];
|
|
8
|
+
function IntlProvider(_ref) {
|
|
9
|
+
var children = _ref.children,
|
|
10
|
+
_ref$onError = _ref.onError,
|
|
11
|
+
onError = _ref$onError === void 0 ? defaultOnError : _ref$onError,
|
|
12
|
+
_ref$getMessageFallba = _ref.getMessageFallback,
|
|
13
|
+
getMessageFallback = _ref$getMessageFallba === void 0 ? defaultGetMessageFallback : _ref$getMessageFallba,
|
|
14
|
+
messages = _ref.messages,
|
|
15
|
+
contextValues = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
|
|
17
|
+
if (process.env.NODE_ENV !== "production") {
|
|
18
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (messages) {
|
|
21
|
+
validateMessages(messages, onError);
|
|
22
|
+
}
|
|
23
|
+
}, [messages, onError]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return React.createElement(IntlContext.Provider, {
|
|
27
|
+
value: _extends({}, contextValues, {
|
|
28
|
+
messages: messages,
|
|
29
|
+
onError: onError,
|
|
30
|
+
getMessageFallback: getMessageFallback
|
|
31
|
+
})
|
|
32
|
+
}, children);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { IntlProvider as default };
|
|
36
|
+
//# sourceMappingURL=use-intl.esm5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm5.js","sources":["../../src/react/IntlProvider.tsx"],"sourcesContent":["import React, {ReactNode, useEffect} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\nimport {defaultGetMessageFallback, defaultOnError} from '../core/config';\nimport validateMessages from '../core/validateMessages';\nimport IntlContext from './IntlContext';\n\ntype Props = {\n /** All messages that will be available in your components. */\n messages?: AbstractIntlMessages;\n /** A valid Unicode locale tag (e.g. \"en\" or \"en-GB\"). */\n locale: string;\n /** Global formats can be provided to achieve consistent\n * formatting across components. */\n formats?: Partial<Formats>;\n /** A time zone as defined in [the tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) which will be applied when formatting dates and times. If this is absent, the user time zone will be used. You can override this by supplying an explicit time zone to `formatDateTime`. */\n timeZone?: string;\n /** This callback will be invoked when an error is encountered during\n * resolving a message or formatting it. This defaults to `console.error` to\n * keep your app running. You can customize the handling by taking\n * `error.code` into account. */\n onError?(error: IntlError): void;\n /** Will be called when a message couldn't be resolved or formatting it led to\n * an error. This defaults to `${namespace}.${key}` You can use this to\n * customize what will be rendered in this case. */\n getMessageFallback?(info: {\n namespace?: string;\n key: string;\n error: IntlError;\n }): string;\n /** All components that use the provided hooks should be within this tree. */\n children: ReactNode;\n /**\n * Providing this value will have two effects:\n * 1. It will be used as the default for the `now` argument of\n * `useIntl().formatRelativeTime` if no explicit value is provided.\n * 2. It will be returned as a static value from the `useNow` hook. Note\n * however that when `updateInterval` is configured on the `useNow` hook,\n * the global `now` value will only be used for the initial render, but\n * afterwards the current date will be returned continuously.\n */\n now?: Date;\n /** Global default values for translation values and rich text elements.\n * Can be used for consistent usage or styling of rich text elements.\n * Defaults will be overidden by locally provided values. */\n defaultTranslationValues?: RichTranslationValues;\n};\n\nexport default function IntlProvider({\n children,\n onError = defaultOnError,\n getMessageFallback = defaultGetMessageFallback,\n messages,\n ...contextValues\n}: Props) {\n if (__DEV__) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (messages) {\n validateMessages(messages, onError);\n }\n }, [messages, onError]);\n }\n\n return (\n <IntlContext.Provider\n value={{...contextValues, messages, onError, getMessageFallback}}\n >\n {children}\n </IntlContext.Provider>\n );\n}\n"],"names":["IntlProvider","children","onError","defaultOnError","getMessageFallback","defaultGetMessageFallback","messages","contextValues","useEffect","validateMessages","React","IntlContext","Provider","value"],"mappings":";;;;;;;AAkDwB,SAAAA,YAAA,CAMhB,IAAA,EAAA;AAAA,EALNC,IAAAA,QAKM,QALNA,QAKM;AAAA,MAAA,YAAA,GAAA,IAAA,CAJNC,OAIM;AAAA,MAJNA,OAIM,6BAJIC,cAIJ,GAAA,YAAA;AAAA,MAAA,qBAAA,GAAA,IAAA,CAHNC,kBAGM;AAAA,MAHNA,kBAGM,sCAHeC,yBAGf,GAAA,qBAAA;AAAA,MAFNC,QAEM,QAFNA,QAEM;AAAA,MADHC,aACG,GAAA,6BAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;;AACN,EAAa,IAAA,OAAA,CAAA,GAAA,CAAA,QAAA,KAAA,YAAA,EAAA;AACX;AACAC,IAAAA,SAAS,CAAC,YAAK;AACb,MAAA,IAAIF,QAAJ,EAAc;AACZG,QAAAA,gBAAgB,CAACH,QAAD,EAAWJ,OAAX,CAAhB,CAAA;AACD,OAAA;AACF,KAJQ,EAIN,CAACI,QAAD,EAAWJ,OAAX,CAJM,CAAT,CAAA;AAKD,GAAA;;AAED,EAAA,OACEQ,mBAAA,CAACC,WAAW,CAACC,QAAb,EACE;AAAAC,IAAAA,KAAK,eAAMN,aAAN,EAAA;AAAqBD,MAAAA,QAAQ,EAARA,QAArB;AAA+BJ,MAAAA,OAAO,EAAPA,OAA/B;AAAwCE,MAAAA,kBAAkB,EAAlBA,kBAAAA;AAAxC,KAAA,CAAA;AAAL,GADF,EAGGH,QAHH,CADF,CAAA;AAOD;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import useIntlContext from './use-intl.
|
|
1
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
2
2
|
|
|
3
3
|
function useLocale() {
|
|
4
4
|
return useIntlContext().locale;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export { useLocale as default };
|
|
8
|
-
//# sourceMappingURL=use-intl.
|
|
8
|
+
//# sourceMappingURL=use-intl.esm6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm6.js","sources":["../../src/react/useLocale.tsx"],"sourcesContent":["import useIntlContext from './useIntlContext';\n\nexport default function useLocale() {\n return useIntlContext().locale;\n}\n"],"names":["useLocale","useIntlContext","locale"],"mappings":";;AAEc,SAAUA,SAAV,GAAmB;AAC/B,EAAOC,OAAAA,cAAc,GAAGC,MAAxB,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm7.js","sources":["../../src/react/useIntlContext.tsx"],"sourcesContent":["import {useContext} from 'react';\nimport IntlContext from './IntlContext';\n\nexport default function useIntlContext() {\n const context = useContext(IntlContext);\n\n if (!context) {\n throw new Error(\n __DEV__\n ? 'No intl context found. Have you configured the provider?'\n : undefined\n );\n }\n\n return context;\n}\n"],"names":["useIntlContext","context","useContext","IntlContext","Error","undefined"],"mappings":";;;AAGc,SAAUA,cAAV,GAAwB;AACpC,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACC,WAAD,CAA1B,CAAA;;AAEA,EAAI,IAAA,CAACF,OAAL,EAAc;AACZ,IAAA,MAAM,IAAIG,KAAJ,CACJ,wCACI,0DADJ,GAEIC,SAHA,CAAN,CAAA;AAKD,GAAA;;AAED,EAAA,OAAOJ,OAAP,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useRef, useMemo } from 'react';
|
|
2
|
+
import createBaseTranslator, { getMessagesOrError } from '../core/use-intl.esm7.js';
|
|
3
|
+
import resolveNamespace from '../core/use-intl.esm8.js';
|
|
4
|
+
import useIntlContext from './use-intl.esm7.js';
|
|
5
|
+
|
|
6
|
+
function useTranslationsImpl(allMessages, namespace, namespacePrefix) {
|
|
7
|
+
var _useIntlContext = useIntlContext(),
|
|
8
|
+
defaultTranslationValues = _useIntlContext.defaultTranslationValues,
|
|
9
|
+
globalFormats = _useIntlContext.formats,
|
|
10
|
+
getMessageFallback = _useIntlContext.getMessageFallback,
|
|
11
|
+
locale = _useIntlContext.locale,
|
|
12
|
+
onError = _useIntlContext.onError,
|
|
13
|
+
timeZone = _useIntlContext.timeZone; // The `namespacePrefix` is part of the type system.
|
|
14
|
+
// See the comment in the hook invocation.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
allMessages = allMessages[namespacePrefix];
|
|
18
|
+
namespace = resolveNamespace(namespace, namespacePrefix);
|
|
19
|
+
var cachedFormatsByLocaleRef = useRef({});
|
|
20
|
+
var messagesOrError = useMemo(function () {
|
|
21
|
+
return getMessagesOrError({
|
|
22
|
+
messages: allMessages,
|
|
23
|
+
namespace: namespace,
|
|
24
|
+
onError: onError
|
|
25
|
+
});
|
|
26
|
+
}, [allMessages, namespace, onError]);
|
|
27
|
+
var translate = useMemo(function () {
|
|
28
|
+
return createBaseTranslator({
|
|
29
|
+
cachedFormatsByLocale: cachedFormatsByLocaleRef.current,
|
|
30
|
+
getMessageFallback: getMessageFallback,
|
|
31
|
+
messagesOrError: messagesOrError,
|
|
32
|
+
defaultTranslationValues: defaultTranslationValues,
|
|
33
|
+
namespace: namespace,
|
|
34
|
+
onError: onError,
|
|
35
|
+
formats: globalFormats,
|
|
36
|
+
locale: locale,
|
|
37
|
+
timeZone: timeZone
|
|
38
|
+
});
|
|
39
|
+
}, [getMessageFallback, messagesOrError, defaultTranslationValues, namespace, onError, globalFormats, locale, timeZone]);
|
|
40
|
+
return translate;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { useTranslationsImpl as default };
|
|
44
|
+
//# sourceMappingURL=use-intl.esm8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-intl.esm8.js","sources":["../../src/react/useTranslationsImpl.tsx"],"sourcesContent":["import {IntlMessageFormat} from 'intl-messageformat';\nimport {useMemo, useRef} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport createBaseTranslator, {\n getMessagesOrError\n} from '../core/createBaseTranslator';\nimport resolveNamespace from '../core/resolveNamespace';\nimport NestedKeyOf from '../core/utils/NestedKeyOf';\nimport useIntlContext from './useIntlContext';\n\nexport default function useTranslationsImpl<\n Messages extends AbstractIntlMessages,\n NestedKey extends NestedKeyOf<Messages>\n>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string) {\n const {\n defaultTranslationValues,\n formats: globalFormats,\n getMessageFallback,\n locale,\n onError,\n timeZone\n } = useIntlContext();\n\n // The `namespacePrefix` is part of the type system.\n // See the comment in the hook invocation.\n allMessages = allMessages[namespacePrefix] as Messages;\n namespace = resolveNamespace(namespace, namespacePrefix) as NestedKey;\n\n const cachedFormatsByLocaleRef = useRef<\n Record<string, Record<string, IntlMessageFormat>>\n >({});\n\n const messagesOrError = useMemo(\n () => getMessagesOrError({messages: allMessages, namespace, onError}),\n [allMessages, namespace, onError]\n );\n\n const translate = useMemo(\n () =>\n createBaseTranslator({\n cachedFormatsByLocale: cachedFormatsByLocaleRef.current,\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n formats: globalFormats,\n locale,\n timeZone\n }),\n [\n getMessageFallback,\n messagesOrError,\n defaultTranslationValues,\n namespace,\n onError,\n globalFormats,\n locale,\n timeZone\n ]\n );\n\n return translate;\n}\n"],"names":["useTranslationsImpl","allMessages","namespace","namespacePrefix","useIntlContext","defaultTranslationValues","globalFormats","formats","getMessageFallback","locale","onError","timeZone","resolveNamespace","cachedFormatsByLocaleRef","useRef","messagesOrError","useMemo","getMessagesOrError","messages","translate","createBaseTranslator","cachedFormatsByLocale","current"],"mappings":";;;;;AAUwB,SAAAA,mBAAA,CAGtBC,WAHsB,EAGCC,SAHD,EAGuBC,eAHvB,EAG8C;AACpE,EAAA,IAAA,eAAA,GAOIC,cAAc,EAPlB;AAAA,MACEC,wBADF,mBACEA,wBADF;AAAA,MAEWC,aAFX,mBAEEC,OAFF;AAAA,MAGEC,kBAHF,mBAGEA,kBAHF;AAAA,MAIEC,MAJF,mBAIEA,MAJF;AAAA,MAKEC,OALF,mBAKEA,OALF;AA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|
1
|
+
{"version":3,"file":"use-intl.esm9.js","sources":["../../src/react/IntlContext.tsx"],"sourcesContent":["import {createContext} from 'react';\nimport AbstractIntlMessages from '../core/AbstractIntlMessages';\nimport Formats from '../core/Formats';\nimport IntlError from '../core/IntlError';\nimport {RichTranslationValues} from '../core/TranslationValues';\n\nexport type IntlContextShape = {\n messages?: AbstractIntlMessages;\n locale: string;\n formats?: Partial<Formats>;\n timeZone?: string;\n onError(error: IntlError): void;\n getMessageFallback(info: {\n error: IntlError;\n key: string;\n namespace?: string;\n }): string;\n now?: Date;\n defaultTranslationValues?: RichTranslationValues;\n};\n\nconst IntlContext = createContext<IntlContextShape | undefined>(undefined);\n\nexport default IntlContext;\n"],"names":["IntlContext","createContext","undefined"],"mappings":";;AAqBA,IAAMA,WAAW,gBAAGC,aAAa,CAA+BC,SAA/B;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export default function useIntl(): {
|
|
2
|
+
formatDateTime: (value: number | Date, formatOrOptions?: string | import("../core/DateTimeFormatOptions").default | undefined) => string;
|
|
3
|
+
formatNumber: (value: number, formatOrOptions?: string | import("@formatjs/ecma402-abstract").NumberFormatOptions | undefined) => string;
|
|
4
|
+
formatRelativeTime: (date: number | Date, now?: number | Date | undefined) => string;
|
|
5
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReactElement, ReactNodeArray } from 'react';
|
|
2
|
-
import Formats from '
|
|
3
|
-
import TranslationValues, { RichTranslationValues } from '
|
|
4
|
-
import MessageKeys from '
|
|
5
|
-
import NamespaceKeys from '
|
|
6
|
-
import NestedKeyOf from '
|
|
7
|
-
import NestedValueOf from '
|
|
2
|
+
import Formats from '../core/Formats';
|
|
3
|
+
import TranslationValues, { RichTranslationValues } from '../core/TranslationValues';
|
|
4
|
+
import MessageKeys from '../core/utils/MessageKeys';
|
|
5
|
+
import NamespaceKeys from '../core/utils/NamespaceKeys';
|
|
6
|
+
import NestedKeyOf from '../core/utils/NestedKeyOf';
|
|
7
|
+
import NestedValueOf from '../core/utils/NestedValueOf';
|
|
8
8
|
/**
|
|
9
9
|
* Translates messages from the given namespace by using the ICU syntax.
|
|
10
10
|
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import AbstractIntlMessages from '../core/AbstractIntlMessages';
|
|
3
|
+
import NestedKeyOf from '../core/utils/NestedKeyOf';
|
|
4
|
+
export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessages: Messages, namespace: NestedKey, namespacePrefix: string): {
|
|
5
|
+
<TargetKey extends unknown>(key: TargetKey, values?: import("../core/TranslationValues").default | undefined, formats?: Partial<import("../core/Formats").default> | undefined): string;
|
|
6
|
+
rich: (key: string, values?: import("..").RichTranslationValues | undefined, formats?: Partial<import("../core/Formats").default> | undefined) => string | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray;
|
|
7
|
+
raw(key: string): any;
|
|
8
|
+
};
|