use-intl 2.16.0 → 2.17.1
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/core/AbstractIntlMessages.d.mts +10 -0
- package/dist/core/AbstractIntlMessages.d.ts +10 -9
- package/dist/core/AbstractIntlMessages.js +2 -0
- package/dist/core/AbstractIntlMessages.js.map +1 -0
- package/dist/core/AbstractIntlMessages.mjs +1 -0
- package/dist/core/AbstractIntlMessages.mjs.map +1 -0
- package/dist/core/DateTimeFormatOptions.d.mts +75 -0
- package/dist/core/DateTimeFormatOptions.d.ts +75 -72
- package/dist/core/DateTimeFormatOptions.js +2 -0
- package/dist/core/DateTimeFormatOptions.js.map +1 -0
- package/dist/core/DateTimeFormatOptions.mjs +1 -0
- package/dist/core/DateTimeFormatOptions.mjs.map +1 -0
- package/dist/core/Formats.d.mts +11 -0
- package/dist/core/Formats.d.ts +11 -8
- package/dist/core/Formats.js +2 -0
- package/dist/core/Formats.js.map +1 -0
- package/dist/core/Formats.mjs +1 -0
- package/dist/core/Formats.mjs.map +1 -0
- package/dist/core/IntlConfig.d.mts +60 -0
- package/dist/core/IntlConfig.d.ts +60 -53
- package/dist/core/IntlConfig.js +2 -0
- package/dist/core/IntlConfig.js.map +1 -0
- package/dist/core/IntlConfig.mjs +1 -0
- package/dist/core/IntlConfig.mjs.map +1 -0
- package/dist/core/IntlError.d.mts +15 -0
- package/dist/core/IntlError.d.ts +15 -13
- package/dist/core/IntlError.js +2 -0
- package/dist/core/IntlError.js.map +1 -0
- package/dist/core/IntlError.mjs +2 -0
- package/dist/core/IntlError.mjs.map +1 -0
- package/dist/core/NumberFormatOptions.d.mts +2 -0
- package/dist/core/NumberFormatOptions.d.ts +2 -2
- package/dist/core/NumberFormatOptions.js +2 -0
- package/dist/core/NumberFormatOptions.js.map +1 -0
- package/dist/core/NumberFormatOptions.mjs +2 -0
- package/dist/core/NumberFormatOptions.mjs.map +1 -0
- package/dist/core/TimeZone.d.mts +3 -0
- package/dist/core/TimeZone.d.ts +3 -0
- package/dist/core/TimeZone.js +2 -0
- package/dist/core/TimeZone.js.map +1 -0
- package/dist/core/TimeZone.mjs +1 -0
- package/dist/core/TimeZone.mjs.map +1 -0
- package/dist/core/TranslationValues.d.mts +7 -0
- package/dist/core/TranslationValues.d.ts +7 -5
- package/dist/core/TranslationValues.js +2 -0
- package/dist/core/TranslationValues.js.map +1 -0
- package/dist/core/TranslationValues.mjs +1 -0
- package/dist/core/TranslationValues.mjs.map +1 -0
- package/dist/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
- package/dist/core/convertFormatsToIntlMessageFormat.d.ts +16 -10
- package/dist/core/convertFormatsToIntlMessageFormat.js +2 -0
- package/dist/core/convertFormatsToIntlMessageFormat.js.map +1 -0
- package/dist/core/convertFormatsToIntlMessageFormat.mjs +2 -0
- package/dist/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
- package/dist/core/createBaseTranslator.d.mts +32 -0
- package/dist/core/createBaseTranslator.d.ts +32 -26
- package/dist/core/createBaseTranslator.js +2 -0
- package/dist/core/createBaseTranslator.js.map +1 -0
- package/dist/core/createBaseTranslator.mjs +2 -0
- package/dist/core/createBaseTranslator.mjs.map +1 -0
- package/dist/core/createFormatter.d.mts +21 -0
- package/dist/core/createFormatter.d.ts +21 -18
- package/dist/core/createFormatter.js +2 -0
- package/dist/core/createFormatter.js.map +1 -0
- package/dist/core/createFormatter.mjs +2 -0
- package/dist/core/createFormatter.mjs.map +1 -0
- package/dist/core/createIntl.d.mts +15 -0
- package/dist/core/createIntl.d.ts +15 -7
- package/dist/core/createIntl.js +2 -0
- package/dist/core/createIntl.js.map +1 -0
- package/dist/core/createIntl.mjs +2 -0
- package/dist/core/createIntl.mjs.map +1 -0
- package/dist/core/createTranslator.d.mts +57 -0
- package/dist/core/createTranslator.d.ts +57 -48
- package/dist/core/createTranslator.js +2 -0
- package/dist/core/createTranslator.js.map +1 -0
- package/dist/core/createTranslator.mjs +2 -0
- package/dist/core/createTranslator.mjs.map +1 -0
- package/dist/core/createTranslatorImpl.d.mts +25 -0
- package/dist/core/createTranslatorImpl.d.ts +25 -14
- package/dist/core/createTranslatorImpl.js +2 -0
- package/dist/core/createTranslatorImpl.js.map +1 -0
- package/dist/core/createTranslatorImpl.mjs +2 -0
- package/dist/core/createTranslatorImpl.mjs.map +1 -0
- package/dist/core/defaults.d.mts +14 -0
- package/dist/core/defaults.d.ts +14 -11
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/defaults.mjs +2 -0
- package/dist/core/defaults.mjs.map +1 -0
- package/dist/core/index.d.mts +17 -0
- package/dist/core/index.d.ts +17 -9
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +2 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/resolveNamespace.d.mts +7 -0
- package/dist/core/resolveNamespace.d.ts +7 -5
- package/dist/core/resolveNamespace.js +2 -0
- package/dist/core/resolveNamespace.js.map +1 -0
- package/dist/core/resolveNamespace.mjs +2 -0
- package/dist/core/resolveNamespace.mjs.map +1 -0
- package/dist/core/utils/MessageKeys.d.mts +7 -0
- package/dist/core/utils/MessageKeys.d.ts +7 -5
- package/dist/core/utils/MessageKeys.js +2 -0
- package/dist/core/utils/MessageKeys.js.map +1 -0
- package/dist/core/utils/MessageKeys.mjs +1 -0
- package/dist/core/utils/MessageKeys.mjs.map +1 -0
- package/dist/core/utils/NamespaceKeys.d.mts +7 -0
- package/dist/core/utils/NamespaceKeys.d.ts +7 -5
- package/dist/core/utils/NamespaceKeys.js +2 -0
- package/dist/core/utils/NamespaceKeys.js.map +1 -0
- package/dist/core/utils/NamespaceKeys.mjs +1 -0
- package/dist/core/utils/NamespaceKeys.mjs.map +1 -0
- package/dist/core/utils/NestedKeyOf.d.mts +5 -0
- package/dist/core/utils/NestedKeyOf.d.ts +5 -4
- package/dist/core/utils/NestedKeyOf.js +2 -0
- package/dist/core/utils/NestedKeyOf.js.map +1 -0
- package/dist/core/utils/NestedKeyOf.mjs +1 -0
- package/dist/core/utils/NestedKeyOf.mjs.map +1 -0
- package/dist/core/utils/NestedValueOf.d.mts +3 -0
- package/dist/core/utils/NestedValueOf.d.ts +3 -2
- package/dist/core/utils/NestedValueOf.js +2 -0
- package/dist/core/utils/NestedValueOf.js.map +1 -0
- package/dist/core/utils/NestedValueOf.mjs +1 -0
- package/dist/core/utils/NestedValueOf.mjs.map +1 -0
- package/dist/core/validateMessages.d.mts +6 -0
- package/dist/core/validateMessages.d.ts +6 -3
- package/dist/core/validateMessages.js +34 -0
- package/dist/core/validateMessages.js.map +1 -0
- package/dist/core/validateMessages.mjs +34 -0
- package/dist/core/validateMessages.mjs.map +1 -0
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -2
- package/dist/index.js +2 -8
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/IntlContext.d.mts +13 -0
- package/dist/react/IntlContext.d.ts +13 -4
- package/dist/react/IntlContext.js +2 -0
- package/dist/react/IntlContext.js.map +1 -0
- package/dist/react/IntlContext.mjs +2 -0
- package/dist/react/IntlContext.mjs.map +1 -0
- package/dist/react/IntlProvider.d.mts +16 -0
- package/dist/react/IntlProvider.d.ts +16 -7
- package/dist/react/IntlProvider.js +2 -0
- package/dist/react/IntlProvider.js.map +1 -0
- package/dist/react/IntlProvider.mjs +2 -0
- package/dist/react/IntlProvider.mjs.map +1 -0
- package/dist/react/getInitializedConfig.d.mts +24 -0
- package/dist/react/getInitializedConfig.d.ts +24 -13
- package/dist/react/getInitializedConfig.js +2 -0
- package/dist/react/getInitializedConfig.js.map +1 -0
- package/dist/react/getInitializedConfig.mjs +2 -0
- package/dist/react/getInitializedConfig.mjs.map +1 -0
- package/dist/react/index.d.mts +21 -0
- package/dist/react/index.d.ts +21 -8
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +2 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/useFormatter.d.mts +12 -0
- package/dist/react/useFormatter.d.ts +12 -6
- package/dist/react/useFormatter.js +2 -0
- package/dist/react/useFormatter.js.map +1 -0
- package/dist/react/useFormatter.mjs +2 -0
- package/dist/react/useFormatter.mjs.map +1 -0
- package/dist/react/useIntl.d.mts +12 -0
- package/dist/react/useIntl.d.ts +12 -6
- package/dist/react/useIntl.js +2 -0
- package/dist/react/useIntl.js.map +1 -0
- package/dist/react/useIntl.mjs +2 -0
- package/dist/react/useIntl.mjs.map +1 -0
- package/dist/react/useIntlContext.d.mts +13 -0
- package/dist/react/useIntlContext.d.ts +13 -1
- package/dist/react/useIntlContext.js +2 -0
- package/dist/react/useIntlContext.js.map +1 -0
- package/dist/react/useIntlContext.mjs +2 -0
- package/dist/react/useIntlContext.mjs.map +1 -0
- package/dist/react/useLocale.d.mts +3 -0
- package/dist/react/useLocale.d.ts +3 -1
- package/dist/react/useLocale.js +2 -0
- package/dist/react/useLocale.js.map +1 -0
- package/dist/react/useLocale.mjs +2 -0
- package/dist/react/useLocale.mjs.map +1 -0
- package/dist/react/useMessages.d.mts +5 -0
- package/dist/react/useMessages.d.ts +5 -1
- package/dist/react/useMessages.js +2 -0
- package/dist/react/useMessages.js.map +1 -0
- package/dist/react/useMessages.mjs +2 -0
- package/dist/react/useMessages.mjs.map +1 -0
- package/dist/react/{use-intl.esm4.js → useNow.d.mts} +21 -42
- package/dist/react/useNow.d.ts +24 -23
- package/dist/react/useNow.js +2 -0
- package/dist/react/useNow.js.map +1 -0
- package/dist/react/useNow.mjs +2 -0
- package/dist/react/useNow.mjs.map +1 -0
- package/dist/react/useTimeZone.d.mts +5 -0
- package/dist/react/useTimeZone.d.ts +5 -1
- package/dist/react/useTimeZone.js +2 -0
- package/dist/react/useTimeZone.js.map +1 -0
- package/dist/react/useTimeZone.mjs +2 -0
- package/dist/react/useTimeZone.mjs.map +1 -0
- package/dist/react/useTranslations.d.mts +50 -0
- package/dist/react/useTranslations.d.ts +50 -44
- package/dist/react/useTranslations.js +2 -0
- package/dist/react/useTranslations.js.map +1 -0
- package/dist/react/useTranslations.mjs +2 -0
- package/dist/react/useTranslations.mjs.map +1 -0
- package/dist/react/useTranslationsImpl.d.mts +16 -0
- package/dist/react/useTranslationsImpl.d.ts +16 -8
- package/dist/react/useTranslationsImpl.js +2 -0
- package/dist/react/useTranslationsImpl.js.map +1 -0
- package/dist/react/useTranslationsImpl.mjs +2 -0
- package/dist/react/useTranslationsImpl.mjs.map +1 -0
- package/dist/src/core/AbstractIntlMessages.d.mts +10 -0
- package/dist/src/core/AbstractIntlMessages.d.ts +2 -1
- package/dist/src/core/AbstractIntlMessages.js +1 -1
- package/dist/src/core/AbstractIntlMessages.js.map +1 -1
- package/dist/src/core/AbstractIntlMessages.mjs +1 -0
- package/dist/src/core/AbstractIntlMessages.mjs.map +1 -0
- package/dist/src/core/DateTimeFormatOptions.d.mts +75 -0
- package/dist/src/core/DateTimeFormatOptions.d.ts +5 -2
- package/dist/src/core/DateTimeFormatOptions.js +1 -2
- package/dist/src/core/DateTimeFormatOptions.js.map +1 -1
- package/dist/src/core/DateTimeFormatOptions.mjs +1 -0
- package/dist/src/core/DateTimeFormatOptions.mjs.map +1 -0
- package/dist/src/core/Formats.d.mts +11 -0
- package/dist/src/core/Formats.d.ts +6 -3
- package/dist/src/core/Formats.js +1 -1
- package/dist/src/core/Formats.js.map +1 -1
- package/dist/src/core/Formats.mjs +1 -0
- package/dist/src/core/Formats.mjs.map +1 -0
- package/dist/src/core/IntlConfig.d.mts +60 -0
- package/dist/src/core/IntlConfig.d.ts +13 -6
- package/dist/src/core/IntlConfig.js +1 -1
- package/dist/src/core/IntlConfig.js.map +1 -1
- package/dist/src/core/IntlConfig.mjs +1 -0
- package/dist/src/core/IntlConfig.mjs.map +1 -0
- package/dist/src/core/IntlError.d.mts +15 -0
- package/dist/src/core/IntlError.d.ts +4 -2
- package/dist/src/core/IntlError.js +1 -22
- package/dist/src/core/IntlError.js.map +1 -1
- package/dist/src/core/IntlError.mjs +2 -0
- package/dist/src/core/IntlError.mjs.map +1 -0
- package/dist/src/core/NumberFormatOptions.d.mts +2 -0
- package/dist/src/core/NumberFormatOptions.d.ts +2 -2
- package/dist/src/core/NumberFormatOptions.js +1 -1
- package/dist/src/core/NumberFormatOptions.js.map +1 -1
- package/dist/src/core/NumberFormatOptions.mjs +2 -0
- package/dist/src/core/NumberFormatOptions.mjs.map +1 -0
- package/dist/src/core/TimeZone.d.mts +3 -0
- package/dist/src/core/TimeZone.d.ts +3 -0
- package/dist/src/core/TimeZone.js +2 -0
- package/dist/src/core/TimeZone.js.map +1 -0
- package/dist/src/core/TimeZone.mjs +1 -0
- package/dist/src/core/TimeZone.mjs.map +1 -0
- package/dist/src/core/TranslationValues.d.mts +7 -0
- package/dist/src/core/TranslationValues.d.ts +5 -3
- package/dist/src/core/TranslationValues.js +1 -1
- package/dist/src/core/TranslationValues.js.map +1 -1
- package/dist/src/core/TranslationValues.mjs +1 -0
- package/dist/src/core/TranslationValues.mjs.map +1 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.d.mts +16 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.d.ts +9 -3
- package/dist/src/core/convertFormatsToIntlMessageFormat.js +1 -30
- package/dist/src/core/convertFormatsToIntlMessageFormat.js.map +1 -1
- package/dist/src/core/convertFormatsToIntlMessageFormat.mjs +2 -0
- package/dist/src/core/convertFormatsToIntlMessageFormat.mjs.map +1 -0
- package/dist/src/core/createBaseTranslator.d.mts +32 -0
- package/dist/src/core/createBaseTranslator.d.ts +17 -11
- package/dist/src/core/createBaseTranslator.js +1 -205
- package/dist/src/core/createBaseTranslator.js.map +1 -1
- package/dist/src/core/createBaseTranslator.mjs +2 -0
- package/dist/src/core/createBaseTranslator.mjs.map +1 -0
- package/dist/src/core/createFormatter.d.mts +21 -0
- package/dist/src/core/createFormatter.d.ts +10 -7
- package/dist/src/core/createFormatter.js +1 -128
- package/dist/src/core/createFormatter.js.map +1 -1
- package/dist/src/core/createFormatter.mjs +2 -0
- package/dist/src/core/createFormatter.mjs.map +1 -0
- package/dist/src/core/createIntl.d.mts +15 -0
- package/dist/src/core/createIntl.d.ts +12 -4
- package/dist/src/core/createIntl.js +1 -10
- package/dist/src/core/createIntl.js.map +1 -1
- package/dist/src/core/createIntl.mjs +2 -0
- package/dist/src/core/createIntl.mjs.map +1 -0
- package/dist/src/core/createTranslator.d.mts +57 -0
- package/dist/src/core/createTranslator.d.ts +18 -9
- package/dist/src/core/createTranslator.js +1 -23
- package/dist/src/core/createTranslator.js.map +1 -1
- package/dist/src/core/createTranslator.mjs +2 -0
- package/dist/src/core/createTranslator.mjs.map +1 -0
- package/dist/src/core/createTranslatorImpl.d.mts +25 -0
- package/dist/src/core/createTranslatorImpl.d.ts +20 -9
- package/dist/src/core/createTranslatorImpl.js +1 -42
- package/dist/src/core/createTranslatorImpl.js.map +1 -1
- package/dist/src/core/createTranslatorImpl.mjs +2 -0
- package/dist/src/core/createTranslatorImpl.mjs.map +1 -0
- package/dist/src/core/defaults.d.mts +14 -0
- package/dist/src/core/defaults.d.ts +6 -3
- package/dist/src/core/defaults.js +1 -10
- package/dist/src/core/defaults.js.map +1 -1
- package/dist/src/core/defaults.mjs +2 -0
- package/dist/src/core/defaults.mjs.map +1 -0
- package/dist/src/core/index.d.mts +17 -0
- package/dist/src/core/index.d.ts +17 -9
- package/dist/src/core/index.js +1 -5
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/index.mjs +2 -0
- package/dist/src/core/index.mjs.map +1 -0
- package/dist/src/core/resolveNamespace.d.mts +7 -0
- package/dist/src/core/resolveNamespace.d.ts +3 -1
- package/dist/src/core/resolveNamespace.js +1 -9
- package/dist/src/core/resolveNamespace.js.map +1 -1
- package/dist/src/core/resolveNamespace.mjs +2 -0
- package/dist/src/core/resolveNamespace.mjs.map +1 -0
- package/dist/src/core/utils/MessageKeys.d.mts +7 -0
- package/dist/src/core/utils/MessageKeys.d.ts +4 -2
- package/dist/src/core/utils/MessageKeys.js +1 -1
- package/dist/src/core/utils/MessageKeys.js.map +1 -1
- package/dist/src/core/utils/MessageKeys.mjs +1 -0
- package/dist/src/core/utils/MessageKeys.mjs.map +1 -0
- package/dist/src/core/utils/NamespaceKeys.d.mts +7 -0
- package/dist/src/core/utils/NamespaceKeys.d.ts +4 -2
- package/dist/src/core/utils/NamespaceKeys.js +1 -1
- package/dist/src/core/utils/NamespaceKeys.js.map +1 -1
- package/dist/src/core/utils/NamespaceKeys.mjs +1 -0
- package/dist/src/core/utils/NamespaceKeys.mjs.map +1 -0
- package/dist/src/core/utils/NestedKeyOf.d.mts +5 -0
- package/dist/src/core/utils/NestedKeyOf.d.ts +2 -1
- package/dist/src/core/utils/NestedKeyOf.js +1 -1
- package/dist/src/core/utils/NestedKeyOf.js.map +1 -1
- package/dist/src/core/utils/NestedKeyOf.mjs +1 -0
- package/dist/src/core/utils/NestedKeyOf.mjs.map +1 -0
- package/dist/src/core/utils/NestedValueOf.d.mts +3 -0
- package/dist/src/core/utils/NestedValueOf.d.ts +2 -1
- package/dist/src/core/utils/NestedValueOf.js +1 -1
- package/dist/src/core/utils/NestedValueOf.js.map +1 -1
- package/dist/src/core/utils/NestedValueOf.mjs +1 -0
- package/dist/src/core/utils/NestedValueOf.mjs.map +1 -0
- package/dist/src/core/validateMessages.d.mts +6 -0
- package/dist/src/core/validateMessages.d.ts +6 -3
- package/dist/src/core/validateMessages.js +3 -25
- package/dist/src/core/validateMessages.js.map +1 -1
- package/dist/src/core/validateMessages.mjs +34 -0
- package/dist/src/core/validateMessages.mjs.map +1 -0
- package/dist/src/index.d.mts +25 -0
- package/dist/src/index.d.ts +25 -2
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +2 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/react/IntlContext.d.mts +13 -0
- package/dist/src/react/IntlContext.d.ts +13 -4
- package/dist/src/react/IntlContext.js +1 -3
- package/dist/src/react/IntlContext.js.map +1 -1
- package/dist/src/react/IntlContext.mjs +2 -0
- package/dist/src/react/IntlContext.mjs.map +1 -0
- package/dist/src/react/IntlProvider.d.mts +16 -0
- package/dist/src/react/IntlProvider.d.ts +12 -3
- package/dist/src/react/IntlProvider.js +1 -6
- package/dist/src/react/IntlProvider.js.map +1 -1
- package/dist/src/react/IntlProvider.mjs +2 -0
- package/dist/src/react/IntlProvider.mjs.map +1 -0
- package/dist/src/react/getInitializedConfig.d.mts +24 -0
- package/dist/src/react/getInitializedConfig.d.ts +16 -5
- package/dist/src/react/getInitializedConfig.js +1 -20
- package/dist/src/react/getInitializedConfig.js.map +1 -1
- package/dist/src/react/getInitializedConfig.mjs +2 -0
- package/dist/src/react/getInitializedConfig.mjs.map +1 -0
- package/dist/src/react/index.d.mts +21 -0
- package/dist/src/react/index.d.ts +21 -8
- package/dist/src/react/index.js +1 -9
- package/dist/src/react/index.js.map +1 -1
- package/dist/src/react/index.mjs +2 -0
- package/dist/src/react/index.mjs.map +1 -0
- package/dist/src/react/useFormatter.d.mts +12 -0
- package/dist/src/react/useFormatter.d.ts +9 -3
- package/dist/src/react/useFormatter.js +1 -13
- package/dist/src/react/useFormatter.js.map +1 -1
- package/dist/src/react/useFormatter.mjs +2 -0
- package/dist/src/react/useFormatter.mjs.map +1 -0
- package/dist/src/react/useIntl.d.mts +12 -0
- package/dist/src/react/useIntl.d.ts +9 -3
- package/dist/src/react/useIntl.js +1 -19
- package/dist/src/react/useIntl.js.map +1 -1
- package/dist/src/react/useIntl.mjs +2 -0
- package/dist/src/react/useIntl.mjs.map +1 -0
- package/dist/src/react/useIntlContext.d.mts +13 -0
- package/dist/src/react/useIntlContext.d.ts +13 -1
- package/dist/src/react/useIntlContext.js +1 -11
- package/dist/src/react/useIntlContext.js.map +1 -1
- package/dist/src/react/useIntlContext.mjs +2 -0
- package/dist/src/react/useIntlContext.mjs.map +1 -0
- package/dist/src/react/useLocale.d.mts +3 -0
- package/dist/src/react/useLocale.d.ts +3 -1
- package/dist/src/react/useLocale.js +1 -4
- package/dist/src/react/useLocale.js.map +1 -1
- package/dist/src/react/useLocale.mjs +2 -0
- package/dist/src/react/useLocale.mjs.map +1 -0
- package/dist/src/react/useMessages.d.mts +5 -0
- package/dist/src/react/useMessages.d.ts +5 -1
- package/dist/src/react/useMessages.js +1 -4
- package/dist/src/react/useMessages.js.map +1 -1
- package/dist/src/react/useMessages.mjs +2 -0
- package/dist/src/react/useMessages.mjs.map +1 -0
- package/dist/src/react/useNow.d.mts +24 -0
- package/dist/src/react/useNow.d.ts +3 -2
- package/dist/src/react/useNow.js +1 -39
- package/dist/src/react/useNow.js.map +1 -1
- package/dist/src/react/useNow.mjs +2 -0
- package/dist/src/react/useNow.mjs.map +1 -0
- package/dist/src/react/useTimeZone.d.mts +5 -0
- package/dist/src/react/useTimeZone.d.ts +5 -1
- package/dist/src/react/useTimeZone.js +1 -4
- package/dist/src/react/useTimeZone.js.map +1 -1
- package/dist/src/react/useTimeZone.mjs +2 -0
- package/dist/src/react/useTimeZone.mjs.map +1 -0
- package/dist/src/react/useTranslations.d.mts +50 -0
- package/dist/src/react/useTranslations.d.ts +13 -7
- package/dist/src/react/useTranslations.js +1 -20
- package/dist/src/react/useTranslations.js.map +1 -1
- package/dist/src/react/useTranslations.mjs +2 -0
- package/dist/src/react/useTranslations.mjs.map +1 -0
- package/dist/src/react/useTranslationsImpl.d.mts +16 -0
- package/dist/src/react/useTranslationsImpl.d.ts +14 -6
- package/dist/src/react/useTranslationsImpl.js +1 -34
- package/dist/src/react/useTranslationsImpl.js.map +1 -1
- package/dist/src/react/useTranslationsImpl.mjs +2 -0
- package/dist/src/react/useTranslationsImpl.mjs.map +1 -0
- package/package.json +8 -16
- package/src/core/DateTimeFormatOptions.tsx +3 -1
- package/src/core/IntlConfig.tsx +2 -1
- package/src/core/TimeZone.tsx +426 -0
- package/src/core/convertFormatsToIntlMessageFormat.tsx +3 -2
- package/src/core/createFormatter.tsx +2 -1
- package/src/core/index.tsx +5 -5
- package/dist/_virtual/use-intl.esm.js +0 -102
- package/dist/_virtual/use-intl.esm.js.map +0 -1
- package/dist/core/IntlMessages.d.ts +0 -2
- package/dist/core/use-intl.esm.js +0 -33
- package/dist/core/use-intl.esm.js.map +0 -1
- package/dist/core/use-intl.esm10.js +0 -32
- package/dist/core/use-intl.esm10.js.map +0 -1
- package/dist/core/use-intl.esm2.js +0 -37
- package/dist/core/use-intl.esm2.js.map +0 -1
- package/dist/core/use-intl.esm3.js +0 -138
- package/dist/core/use-intl.esm3.js.map +0 -1
- package/dist/core/use-intl.esm4.js +0 -14
- package/dist/core/use-intl.esm4.js.map +0 -1
- package/dist/core/use-intl.esm5.js +0 -53
- package/dist/core/use-intl.esm5.js.map +0 -1
- package/dist/core/use-intl.esm6.js +0 -15
- package/dist/core/use-intl.esm6.js.map +0 -1
- package/dist/core/use-intl.esm7.js +0 -191
- package/dist/core/use-intl.esm7.js.map +0 -1
- package/dist/core/use-intl.esm8.js +0 -10
- package/dist/core/use-intl.esm8.js.map +0 -1
- package/dist/core/use-intl.esm9.js +0 -28
- package/dist/core/use-intl.esm9.js.map +0 -1
- package/dist/react/use-intl.esm.js +0 -16
- package/dist/react/use-intl.esm.js.map +0 -1
- package/dist/react/use-intl.esm10.js +0 -29
- package/dist/react/use-intl.esm10.js.map +0 -1
- package/dist/react/use-intl.esm11.js +0 -13
- package/dist/react/use-intl.esm11.js.map +0 -1
- package/dist/react/use-intl.esm12.js +0 -43
- package/dist/react/use-intl.esm12.js.map +0 -1
- package/dist/react/use-intl.esm2.js +0 -26
- package/dist/react/use-intl.esm2.js.map +0 -1
- package/dist/react/use-intl.esm3.js +0 -8
- package/dist/react/use-intl.esm3.js.map +0 -1
- package/dist/react/use-intl.esm4.js.map +0 -1
- package/dist/react/use-intl.esm5.js +0 -8
- package/dist/react/use-intl.esm5.js.map +0 -1
- package/dist/react/use-intl.esm6.js +0 -8
- package/dist/react/use-intl.esm6.js.map +0 -1
- package/dist/react/use-intl.esm7.js +0 -24
- package/dist/react/use-intl.esm7.js.map +0 -1
- package/dist/react/use-intl.esm8.js +0 -30
- package/dist/react/use-intl.esm8.js.map +0 -1
- package/dist/react/use-intl.esm9.js +0 -6
- package/dist/react/use-intl.esm9.js.map +0 -1
- package/dist/src/core/IntlMessages.d.ts +0 -2
- package/dist/src/core/IntlMessages.js +0 -4
- package/dist/src/core/IntlMessages.js.map +0 -1
- package/dist/use-intl.cjs.development.js +0 -821
- package/dist/use-intl.cjs.development.js.map +0 -1
- package/dist/use-intl.cjs.production.min.js +0 -2
- package/dist/use-intl.cjs.production.min.js.map +0 -1
- package/dist/use-intl.esm.js +0 -13
- package/dist/use-intl.esm.js.map +0 -1
- package/src/core/IntlMessages.tsx +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/TimeZone.tsx"],"sourcesContent":["type TimeZone =\n | 'Africa/Abidjan'\n | 'Africa/Accra'\n | 'Africa/Addis_Ababa'\n | 'Africa/Algiers'\n | 'Africa/Asmara'\n | 'Africa/Bamako'\n | 'Africa/Bangui'\n | 'Africa/Banjul'\n | 'Africa/Bissau'\n | 'Africa/Blantyre'\n | 'Africa/Brazzaville'\n | 'Africa/Bujumbura'\n | 'Africa/Cairo'\n | 'Africa/Casablanca'\n | 'Africa/Ceuta'\n | 'Africa/Conakry'\n | 'Africa/Dakar'\n | 'Africa/Dar_es_Salaam'\n | 'Africa/Djibouti'\n | 'Africa/Douala'\n | 'Africa/El_Aaiun'\n | 'Africa/Freetown'\n | 'Africa/Gaborone'\n | 'Africa/Harare'\n | 'Africa/Johannesburg'\n | 'Africa/Juba'\n | 'Africa/Kampala'\n | 'Africa/Khartoum'\n | 'Africa/Kigali'\n | 'Africa/Kinshasa'\n | 'Africa/Lagos'\n | 'Africa/Libreville'\n | 'Africa/Lome'\n | 'Africa/Luanda'\n | 'Africa/Lubumbashi'\n | 'Africa/Lusaka'\n | 'Africa/Malabo'\n | 'Africa/Maputo'\n | 'Africa/Maseru'\n | 'Africa/Mbabane'\n | 'Africa/Mogadishu'\n | 'Africa/Monrovia'\n | 'Africa/Nairobi'\n | 'Africa/Ndjamena'\n | 'Africa/Niamey'\n | 'Africa/Nouakchott'\n | 'Africa/Ouagadougou'\n | 'Africa/Porto-Novo'\n | 'Africa/Sao_Tome'\n | 'Africa/Tripoli'\n | 'Africa/Tunis'\n | 'Africa/Windhoek'\n | 'America/Adak'\n | 'America/Anchorage'\n | 'America/Anguilla'\n | 'America/Antigua'\n | 'America/Araguaina'\n | 'America/Argentina/Buenos_Aires'\n | 'America/Argentina/Catamarca'\n | 'America/Argentina/Cordoba'\n | 'America/Argentina/Jujuy'\n | 'America/Argentina/La_Rioja'\n | 'America/Argentina/Mendoza'\n | 'America/Argentina/Rio_Gallegos'\n | 'America/Argentina/Salta'\n | 'America/Argentina/San_Juan'\n | 'America/Argentina/San_Luis'\n | 'America/Argentina/Tucuman'\n | 'America/Argentina/Ushuaia'\n | 'America/Aruba'\n | 'America/Asuncion'\n | 'America/Atikokan'\n | 'America/Bahia'\n | 'America/Bahia_Banderas'\n | 'America/Barbados'\n | 'America/Belem'\n | 'America/Belize'\n | 'America/Blanc-Sablon'\n | 'America/Boa_Vista'\n | 'America/Bogota'\n | 'America/Boise'\n | 'America/Cambridge_Bay'\n | 'America/Campo_Grande'\n | 'America/Cancun'\n | 'America/Caracas'\n | 'America/Cayenne'\n | 'America/Cayman'\n | 'America/Chicago'\n | 'America/Chihuahua'\n | 'America/Costa_Rica'\n | 'America/Creston'\n | 'America/Cuiaba'\n | 'America/Curacao'\n | 'America/Danmarkshavn'\n | 'America/Dawson'\n | 'America/Dawson_Creek'\n | 'America/Denver'\n | 'America/Detroit'\n | 'America/Dominica'\n | 'America/Edmonton'\n | 'America/Eirunepe'\n | 'America/El_Salvador'\n | 'America/Fort_Nelson'\n | 'America/Fortaleza'\n | 'America/Glace_Bay'\n | 'America/Godthab'\n | 'America/Goose_Bay'\n | 'America/Grand_Turk'\n | 'America/Grenada'\n | 'America/Guadeloupe'\n | 'America/Guatemala'\n | 'America/Guayaquil'\n | 'America/Guyana'\n | 'America/Halifax'\n | 'America/Havana'\n | 'America/Hermosillo'\n | 'America/Indiana/Indianapolis'\n | 'America/Indiana/Knox'\n | 'America/Indiana/Marengo'\n | 'America/Indiana/Petersburg'\n | 'America/Indiana/Tell_City'\n | 'America/Indiana/Vevay'\n | 'America/Indiana/Vincennes'\n | 'America/Indiana/Winamac'\n | 'America/Inuvik'\n | 'America/Iqaluit'\n | 'America/Jamaica'\n | 'America/Juneau'\n | 'America/Kentucky/Louisville'\n | 'America/Kentucky/Monticello'\n | 'America/Kralendijk'\n | 'America/La_Paz'\n | 'America/Lima'\n | 'America/Los_Angeles'\n | 'America/Lower_Princes'\n | 'America/Maceio'\n | 'America/Managua'\n | 'America/Manaus'\n | 'America/Marigot'\n | 'America/Martinique'\n | 'America/Matamoros'\n | 'America/Mazatlan'\n | 'America/Menominee'\n | 'America/Merida'\n | 'America/Metlakatla'\n | 'America/Mexico_City'\n | 'America/Miquelon'\n | 'America/Moncton'\n | 'America/Monterrey'\n | 'America/Montevideo'\n | 'America/Montserrat'\n | 'America/Nassau'\n | 'America/New_York'\n | 'America/Nipigon'\n | 'America/Nome'\n | 'America/Noronha'\n | 'America/North_Dakota/Beulah'\n | 'America/North_Dakota/Center'\n | 'America/North_Dakota/New_Salem'\n | 'America/Ojinaga'\n | 'America/Panama'\n | 'America/Pangnirtung'\n | 'America/Paramaribo'\n | 'America/Phoenix'\n | 'America/Port-au-Prince'\n | 'America/Port_of_Spain'\n | 'America/Porto_Velho'\n | 'America/Puerto_Rico'\n | 'America/Punta_Arenas'\n | 'America/Rainy_River'\n | 'America/Rankin_Inlet'\n | 'America/Recife'\n | 'America/Regina'\n | 'America/Resolute'\n | 'America/Rio_Branco'\n | 'America/Santarem'\n | 'America/Santiago'\n | 'America/Santo_Domingo'\n | 'America/Sao_Paulo'\n | 'America/Scoresbysund'\n | 'America/Sitka'\n | 'America/St_Barthelemy'\n | 'America/St_Johns'\n | 'America/St_Kitts'\n | 'America/St_Lucia'\n | 'America/St_Thomas'\n | 'America/St_Vincent'\n | 'America/Swift_Current'\n | 'America/Tegucigalpa'\n | 'America/Thule'\n | 'America/Thunder_Bay'\n | 'America/Tijuana'\n | 'America/Toronto'\n | 'America/Tortola'\n | 'America/Vancouver'\n | 'America/Whitehorse'\n | 'America/Winnipeg'\n | 'America/Yakutat'\n | 'America/Yellowknife'\n | 'Antarctica/Casey'\n | 'Antarctica/Davis'\n | 'Antarctica/DumontDUrville'\n | 'Antarctica/Macquarie'\n | 'Antarctica/Mawson'\n | 'Antarctica/Palmer'\n | 'Antarctica/Rothera'\n | 'Antarctica/Syowa'\n | 'Antarctica/Troll'\n | 'Antarctica/Vostok'\n | 'Arctic/Longyearbyen'\n | 'Asia/Almaty'\n | 'Asia/Amman'\n | 'Asia/Anadyr'\n | 'Asia/Aqtau'\n | 'Asia/Aqtobe'\n | 'Asia/Ashgabat'\n | 'Asia/Atyrau'\n | 'Asia/Baghdad'\n | 'Asia/Baku'\n | 'Asia/Bangkok'\n | 'Asia/Barnaul'\n | 'Asia/Beirut'\n | 'Asia/Bishkek'\n | 'Asia/Brunei'\n | 'Asia/Chita'\n | 'Asia/Choibalsan'\n | 'Asia/Colombo'\n | 'Asia/Damascus'\n | 'Asia/Dhaka'\n | 'Asia/Dili'\n | 'Asia/Dubai'\n | 'Asia/Dushanbe'\n | 'Asia/Famagusta'\n | 'Asia/Gaza'\n | 'Asia/Hebron'\n | 'Asia/Ho_Chi_Minh'\n | 'Asia/Hong_Kong'\n | 'Asia/Hovd'\n | 'Asia/Irkutsk'\n | 'Asia/Jakarta'\n | 'Asia/Jayapura'\n | 'Asia/Jerusalem'\n | 'Asia/Kabul'\n | 'Asia/Kamchatka'\n | 'Asia/Karachi'\n | 'Asia/Kathmandu'\n | 'Asia/Khandyga'\n | 'Asia/Kolkata'\n | 'Asia/Krasnoyarsk'\n | 'Asia/Kuala_Lumpur'\n | 'Asia/Kuching'\n | 'Asia/Macau'\n | 'Asia/Magadan'\n | 'Asia/Makassar'\n | 'Asia/Manila'\n | 'Asia/Nicosia'\n | 'Asia/Novokuznetsk'\n | 'Asia/Novosibirsk'\n | 'Asia/Omsk'\n | 'Asia/Oral'\n | 'Asia/Phnom_Penh'\n | 'Asia/Pontianak'\n | 'Asia/Pyongyang'\n | 'Asia/Qatar'\n | 'Asia/Qostanay'\n | 'Asia/Qyzylorda'\n | 'Asia/Riyadh'\n | 'Asia/Sakhalin'\n | 'Asia/Samarkand'\n | 'Asia/Seoul'\n | 'Asia/Shanghai'\n | 'Asia/Singapore'\n | 'Asia/Srednekolymsk'\n | 'Asia/Taipei'\n | 'Asia/Tashkent'\n | 'Asia/Tbilisi'\n | 'Asia/Tehran'\n | 'Asia/Thimphu'\n | 'Asia/Tokyo'\n | 'Asia/Tomsk'\n | 'Asia/Ulaanbaatar'\n | 'Asia/Urumqi'\n | 'Asia/Ust-Nera'\n | 'Asia/Vladivostok'\n | 'Asia/Yakutsk'\n | 'Asia/Yangon'\n | 'Asia/Yekaterinburg'\n | 'Asia/Yerevan'\n | 'Atlantic/Azores'\n | 'Atlantic/Bermuda'\n | 'Atlantic/Canary'\n | 'Atlantic/Cape_Verde'\n | 'Atlantic/Faroe'\n | 'Atlantic/Madeira'\n | 'Atlantic/Reykjavik'\n | 'Atlantic/South_Georgia'\n | 'Atlantic/St_Helena'\n | 'Atlantic/Stanley'\n | 'Australia/Adelaide'\n | 'Australia/Brisbane'\n | 'Australia/Broken_Hill'\n | 'Australia/Currie'\n | 'Australia/Darwin'\n | 'Australia/Eucla'\n | 'Australia/Hobart'\n | 'Australia/Lindeman'\n | 'Australia/Lord_Howe'\n | 'Australia/Melbourne'\n | 'Australia/Perth'\n | 'Australia/Sydney'\n | 'Europe/Amsterdam'\n | 'Europe/Andorra'\n | 'Europe/Astrakhan'\n | 'Europe/Athens'\n | 'Europe/Belgrade'\n | 'Europe/Berlin'\n | 'Europe/Bratislava'\n | 'Europe/Brussels'\n | 'Europe/Bucharest'\n | 'Europe/Budapest'\n | 'Europe/Busingen'\n | 'Europe/Chisinau'\n | 'Europe/Copenhagen'\n | 'Europe/Dublin'\n | 'Europe/Gibraltar'\n | 'Europe/Guernsey'\n | 'Europe/Helsinki'\n | 'Europe/Isle_of_Man'\n | 'Europe/Istanbul'\n | 'Europe/Jersey'\n | 'Europe/Kaliningrad'\n | 'Europe/Kiev'\n | 'Europe/Kirov'\n | 'Europe/Lisbon'\n | 'Europe/Ljubljana'\n | 'Europe/London'\n | 'Europe/Luxembourg'\n | 'Europe/Madrid'\n | 'Europe/Malta'\n | 'Europe/Mariehamn'\n | 'Europe/Minsk'\n | 'Europe/Monaco'\n | 'Europe/Moscow'\n | 'Europe/Oslo'\n | 'Europe/Paris'\n | 'Europe/Podgorica'\n | 'Europe/Prague'\n | 'Europe/Riga'\n | 'Europe/Rome'\n | 'Europe/Samara'\n | 'Europe/San_Marino'\n | 'Europe/Sarajevo'\n | 'Europe/Saratov'\n | 'Europe/Simferopol'\n | 'Europe/Skopje'\n | 'Europe/Sofia'\n | 'Europe/Stockholm'\n | 'Europe/Tallinn'\n | 'Europe/Tirane'\n | 'Europe/Ulyanovsk'\n | 'Europe/Uzhgorod'\n | 'Europe/Vaduz'\n | 'Europe/Vatican'\n | 'Europe/Vienna'\n | 'Europe/Vilnius'\n | 'Europe/Volgograd'\n | 'Europe/Warsaw'\n | 'Europe/Zagreb'\n | 'Europe/Zaporozhye'\n | 'Europe/Zurich'\n | 'Indian/Antananarivo'\n | 'Indian/Chagos'\n | 'Indian/Christmas'\n | 'Indian/Cocos'\n | 'Indian/Comoro'\n | 'Indian/Kerguelen'\n | 'Indian/Mahe'\n | 'Indian/Maldives'\n | 'Indian/Mauritius'\n | 'Indian/Mayotte'\n | 'Indian/Reunion'\n | 'Pacific/Apia'\n | 'Pacific/Auckland'\n | 'Pacific/Bougainville'\n | 'Pacific/Chatham'\n | 'Pacific/Chuuk'\n | 'Pacific/Easter'\n | 'Pacific/Efate'\n | 'Pacific/Enderbury'\n | 'Pacific/Fakaofo'\n | 'Pacific/Fiji'\n | 'Pacific/Funafuti'\n | 'Pacific/Galapagos'\n | 'Pacific/Gambier'\n | 'Pacific/Guadalcanal'\n | 'Pacific/Guam'\n | 'Pacific/Honolulu'\n | 'Pacific/Kiritimati'\n | 'Pacific/Kosrae'\n | 'Pacific/Kwajalein'\n | 'Pacific/Majuro'\n | 'Pacific/Marquesas'\n | 'Pacific/Nauru'\n | 'Pacific/Niue'\n | 'Pacific/Norfolk'\n | 'Pacific/Noumea'\n | 'Pacific/Pago_Pago'\n | 'Pacific/Palau'\n | 'Pacific/Pitcairn'\n | 'Pacific/Pohnpei'\n | 'Pacific/Port_Moresby'\n | 'Pacific/Rarotonga'\n | 'Pacific/Tahiti'\n | 'Pacific/Tarawa'\n | 'Pacific/Tongatapu'\n | 'Pacific/Wake'\n | 'Pacific/Wallis'\n | 'UTC'\n | 'W-SU'\n | 'WET'\n | 'Zulu'\n // eslint-disable-next-line @typescript-eslint/ban-types\n | (string & {});\n\nexport default TimeZone;\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD","names":["TimeZone_exports","__toCommonJS"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=TimeZone.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type TranslationValue = string | number | boolean | Date | null | undefined;
|
|
4
|
+
type TranslationValues = Record<string, TranslationValue>;
|
|
5
|
+
type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
|
|
6
|
+
|
|
7
|
+
export { RichTranslationValues, TranslationValue, TranslationValues as default };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
type TranslationValue = string | number | boolean | Date | null | undefined;
|
|
3
4
|
type TranslationValues = Record<string, TranslationValue>;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
type RichTranslationValues = Record<string, TranslationValue | ((chunks: ReactNode) => ReactNode)>;
|
|
6
|
+
|
|
7
|
+
export { RichTranslationValues, TranslationValue, TranslationValues as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var u=(a,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of s(e))!i.call(a,n)&&n!==r&&o(a,n,{get:()=>e[n],enumerable:!(t=l(e,n))||t.enumerable});return a};var d=a=>u(o({},"__esModule",{value:!0}),a);var c={};module.exports=d(c);
|
|
2
2
|
//# sourceMappingURL=TranslationValues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/core/TranslationValues.tsx"],"sourcesContent":["import {ReactNode} from 'react';\n\n// From IntlMessageFormat#format\nexport type TranslationValue =\n | string\n | number\n | boolean\n | Date\n | null\n | undefined;\n\ntype TranslationValues = Record<string, TranslationValue>;\n\n// We could consider renaming this to `ReactRichTranslationValues` and defining\n// it in the `react` namespace if the core becomes useful to other frameworks.\n// It would be a breaking change though, so let's wait for now.\nexport type RichTranslationValues = Record<\n string,\n TranslationValue | ((chunks: ReactNode) => ReactNode)\n>;\n\nexport default TranslationValues;\n"],"mappings":"+WAAA,IAAAA,EAAA,kBAAAC,EAAAD","names":["TranslationValues_exports","__toCommonJS"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=TranslationValues.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Formats as Formats$1 } from 'intl-messageformat';
|
|
2
|
+
import Formats from './Formats.mjs';
|
|
3
|
+
import TimeZone from './TimeZone.mjs';
|
|
4
|
+
import './DateTimeFormatOptions.mjs';
|
|
5
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
9
|
+
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
10
|
+
* include both a time and a date in a value, therefore the separation doesn't
|
|
11
|
+
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
12
|
+
* to convert the format before `intl-messageformat` can be used.
|
|
13
|
+
*/
|
|
14
|
+
declare function convertFormatsToIntlMessageFormat(formats: Partial<Formats>, timeZone?: TimeZone): Partial<Formats$1>;
|
|
15
|
+
|
|
16
|
+
export { convertFormatsToIntlMessageFormat as default };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Formats as
|
|
2
|
-
import Formats from './Formats';
|
|
1
|
+
import { Formats as Formats$1 } from 'intl-messageformat';
|
|
2
|
+
import Formats from './Formats.js';
|
|
3
|
+
import TimeZone from './TimeZone.js';
|
|
4
|
+
import './DateTimeFormatOptions.js';
|
|
5
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
5
9
|
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
@@ -7,4 +11,6 @@ import Formats from './Formats';
|
|
|
7
11
|
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
8
12
|
* to convert the format before `intl-messageformat` can be used.
|
|
9
13
|
*/
|
|
10
|
-
|
|
14
|
+
declare function convertFormatsToIntlMessageFormat(formats: Partial<Formats>, timeZone?: TimeZone): Partial<Formats$1>;
|
|
15
|
+
|
|
16
|
+
export { convertFormatsToIntlMessageFormat as default };
|
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!formats)
|
|
3
|
-
return formats;
|
|
4
|
-
// The only way to set a time zone with `intl-messageformat` is to merge it into the formats
|
|
5
|
-
// https://github.com/formatjs/formatjs/blob/8256c5271505cf2606e48e3c97ecdd16ede4f1b5/packages/intl/src/message.ts#L15
|
|
6
|
-
return Object.keys(formats).reduce((acc, key) => {
|
|
7
|
-
acc[key] = {
|
|
8
|
-
timeZone,
|
|
9
|
-
...formats[key]
|
|
10
|
-
};
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* `intl-messageformat` uses separate keys for `date` and `time`, but there's
|
|
16
|
-
* only one native API: `Intl.DateTimeFormat`. Additionally you might want to
|
|
17
|
-
* include both a time and a date in a value, therefore the separation doesn't
|
|
18
|
-
* seem so useful. We offer a single `dateTime` namespace instead, but we have
|
|
19
|
-
* to convert the format before `intl-messageformat` can be used.
|
|
20
|
-
*/
|
|
21
|
-
export default function convertFormatsToIntlMessageFormat(formats, timeZone) {
|
|
22
|
-
const formatsWithTimeZone = timeZone
|
|
23
|
-
? { ...formats, dateTime: setTimeZoneInFormats(formats.dateTime, timeZone) }
|
|
24
|
-
: formats;
|
|
25
|
-
return {
|
|
26
|
-
...formatsWithTimeZone,
|
|
27
|
-
date: formatsWithTimeZone?.dateTime,
|
|
28
|
-
time: formatsWithTimeZone?.dateTime
|
|
29
|
-
};
|
|
30
|
-
}
|
|
1
|
+
"use strict";var m=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},F=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of s(e))!T.call(t,i)&&i!==r&&m(t,i,{get:()=>e[i],enumerable:!(o=a(e,i))||o.enumerable});return t};var u=t=>F(m({},"__esModule",{value:!0}),t);var c={};d(c,{default:()=>n});module.exports=u(c);function p(t,e){return t&&Object.keys(t).reduce((r,o)=>(r[o]={timeZone:e,...t[o]},r),{})}function n(t,e){const r=e?{...t,dateTime:p(t.dateTime,e)}:t;return{...r,date:r?.dateTime,time:r?.dateTime}}
|
|
31
2
|
//# sourceMappingURL=convertFormatsToIntlMessageFormat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\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?: TimeZone\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"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAKA,SAASI,EACPC,EACAC,EACA,CACA,OAAKD,GAIE,OAAO,KAAKA,CAAO,EAAE,OAC1B,CAACE,EAA4CC,KAC3CD,EAAIC,CAAG,EAAI,CACT,SAAAF,EACA,GAAGD,EAAQG,CAAG,CAChB,EACOD,GAET,CAAC,CACH,CACF,CASe,SAARL,EACLG,EACAC,EACsB,CACtB,MAAMG,EAAsBH,EACxB,CAAC,GAAGD,EAAS,SAAUD,EAAqBC,EAAQ,SAAUC,CAAQ,CAAC,EACvED,EAEJ,MAAO,CACL,GAAGI,EACH,KAAMA,GAAqB,SAC3B,KAAMA,GAAqB,QAC7B,CACF","names":["convertFormatsToIntlMessageFormat_exports","__export","convertFormatsToIntlMessageFormat","__toCommonJS","setTimeZoneInFormats","formats","timeZone","acc","key","formatsWithTimeZone"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function i(t,r){return t&&Object.keys(t).reduce((e,o)=>(e[o]={timeZone:r,...t[o]},e),{})}function m(t,r){const e=r?{...t,dateTime:i(t.dateTime,r)}:t;return{...e,date:e?.dateTime,time:e?.dateTime}}export{m as default};
|
|
2
|
+
//# sourceMappingURL=convertFormatsToIntlMessageFormat.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/convertFormatsToIntlMessageFormat.tsx"],"sourcesContent":["import {Formats as IntlFormats} from 'intl-messageformat';\nimport DateTimeFormatOptions from './DateTimeFormatOptions';\nimport Formats from './Formats';\nimport TimeZone from './TimeZone';\n\nfunction setTimeZoneInFormats(\n formats: Record<string, DateTimeFormatOptions> | undefined,\n timeZone: TimeZone\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?: TimeZone\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"],"mappings":"AAKA,SAASA,EACPC,EACAC,EACA,CACA,OAAKD,GAIE,OAAO,KAAKA,CAAO,EAAE,OAC1B,CAACE,EAA4CC,KAC3CD,EAAIC,CAAG,EAAI,CACT,SAAAF,EACA,GAAGD,EAAQG,CAAG,CAChB,EACOD,GAET,CAAC,CACH,CACF,CASe,SAARE,EACLJ,EACAC,EACsB,CACtB,MAAMI,EAAsBJ,EACxB,CAAC,GAAGD,EAAS,SAAUD,EAAqBC,EAAQ,SAAUC,CAAQ,CAAC,EACvED,EAEJ,MAAO,CACL,GAAGK,EACH,KAAMA,GAAqB,SAC3B,KAAMA,GAAqB,QAC7B,CACF","names":["setTimeZoneInFormats","formats","timeZone","acc","key","convertFormatsToIntlMessageFormat","formatsWithTimeZone"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import IntlMessageFormat from 'intl-messageformat';
|
|
2
|
+
import { ReactElement, ReactNodeArray } from 'react';
|
|
3
|
+
import AbstractIntlMessages from './AbstractIntlMessages.mjs';
|
|
4
|
+
import Formats from './Formats.mjs';
|
|
5
|
+
import { InitializedIntlConfig } from './IntlConfig.mjs';
|
|
6
|
+
import IntlError from './IntlError.mjs';
|
|
7
|
+
import TranslationValues, { RichTranslationValues } from './TranslationValues.mjs';
|
|
8
|
+
import MessageKeys from './utils/MessageKeys.mjs';
|
|
9
|
+
import NestedKeyOf from './utils/NestedKeyOf.mjs';
|
|
10
|
+
import NestedValueOf from './utils/NestedValueOf.mjs';
|
|
11
|
+
import './DateTimeFormatOptions.mjs';
|
|
12
|
+
import './TimeZone.mjs';
|
|
13
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
14
|
+
|
|
15
|
+
declare function getMessagesOrError<Messages extends AbstractIntlMessages>({ messages, namespace, onError }: {
|
|
16
|
+
messages: Messages;
|
|
17
|
+
namespace?: string;
|
|
18
|
+
onError?(error: IntlError): void;
|
|
19
|
+
}): AbstractIntlMessages | IntlError;
|
|
20
|
+
type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
21
|
+
cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
|
|
22
|
+
defaultTranslationValues?: RichTranslationValues;
|
|
23
|
+
namespace?: string;
|
|
24
|
+
messagesOrError: Messages | IntlError;
|
|
25
|
+
};
|
|
26
|
+
declare function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
|
|
27
|
+
<TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
|
|
28
|
+
rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
|
|
29
|
+
raw(key: string): any;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { CreateBaseTranslatorProps, createBaseTranslator as default, getMessagesOrError };
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import IntlMessageFormat from 'intl-messageformat';
|
|
2
2
|
import { ReactElement, ReactNodeArray } from 'react';
|
|
3
|
-
import AbstractIntlMessages from './AbstractIntlMessages';
|
|
4
|
-
import Formats from './Formats';
|
|
5
|
-
import { InitializedIntlConfig } from './IntlConfig';
|
|
6
|
-
import IntlError from './IntlError';
|
|
7
|
-
import TranslationValues, { RichTranslationValues } from './TranslationValues';
|
|
8
|
-
import MessageKeys from './utils/MessageKeys';
|
|
9
|
-
import NestedKeyOf from './utils/NestedKeyOf';
|
|
10
|
-
import NestedValueOf from './utils/NestedValueOf';
|
|
11
|
-
|
|
3
|
+
import AbstractIntlMessages from './AbstractIntlMessages.js';
|
|
4
|
+
import Formats from './Formats.js';
|
|
5
|
+
import { InitializedIntlConfig } from './IntlConfig.js';
|
|
6
|
+
import IntlError from './IntlError.js';
|
|
7
|
+
import TranslationValues, { RichTranslationValues } from './TranslationValues.js';
|
|
8
|
+
import MessageKeys from './utils/MessageKeys.js';
|
|
9
|
+
import NestedKeyOf from './utils/NestedKeyOf.js';
|
|
10
|
+
import NestedValueOf from './utils/NestedValueOf.js';
|
|
11
|
+
import './DateTimeFormatOptions.js';
|
|
12
|
+
import './TimeZone.js';
|
|
13
|
+
import '@formatjs/ecma402-abstract/types/number';
|
|
14
|
+
|
|
15
|
+
declare function getMessagesOrError<Messages extends AbstractIntlMessages>({ messages, namespace, onError }: {
|
|
12
16
|
messages: Messages;
|
|
13
17
|
namespace?: string;
|
|
14
18
|
onError?(error: IntlError): void;
|
|
15
19
|
}): AbstractIntlMessages | IntlError;
|
|
16
|
-
|
|
20
|
+
type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
|
|
17
21
|
cachedFormatsByLocale?: Record<string, Record<string, IntlMessageFormat>>;
|
|
18
22
|
defaultTranslationValues?: RichTranslationValues;
|
|
19
23
|
namespace?: string;
|
|
20
24
|
messagesOrError: Messages | IntlError;
|
|
21
25
|
};
|
|
22
|
-
|
|
26
|
+
declare function createBaseTranslator<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback, locale, messagesOrError, namespace, onError, timeZone }: CreateBaseTranslatorProps<Messages>): {
|
|
23
27
|
<TargetKey extends MessageKeys<NestedValueOf<Messages, NestedKey>, NestedKeyOf<NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: TranslationValues, formats?: Partial<Formats>): string;
|
|
24
28
|
rich: (key: string, values?: RichTranslationValues, formats?: Partial<Formats>) => string | ReactElement | ReactNodeArray;
|
|
25
29
|
raw(key: string): any;
|
|
26
30
|
};
|
|
31
|
+
|
|
32
|
+
export { CreateBaseTranslatorProps, createBaseTranslator as default, getMessagesOrError };
|
|
@@ -1,206 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import IntlMessageFormat from 'intl-messageformat';
|
|
3
|
-
import { cloneElement, isValidElement } from 'react';
|
|
4
|
-
import IntlError, { IntlErrorCode } from './IntlError';
|
|
5
|
-
import convertFormatsToIntlMessageFormat from './convertFormatsToIntlMessageFormat';
|
|
6
|
-
import { defaultGetMessageFallback, defaultOnError } from './defaults';
|
|
7
|
-
function resolvePath(messages, key, namespace) {
|
|
8
|
-
if (!messages) {
|
|
9
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
10
|
-
? `No messages available at \`${namespace}\`.`
|
|
11
|
-
: undefined);
|
|
12
|
-
}
|
|
13
|
-
let message = messages;
|
|
14
|
-
key.split('.').forEach((part) => {
|
|
15
|
-
const next = message[part];
|
|
16
|
-
if (part == null || next == null) {
|
|
17
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
18
|
-
? `Could not resolve \`${key}\` in ${namespace ? `\`${namespace}\`` : 'messages'}.`
|
|
19
|
-
: undefined);
|
|
20
|
-
}
|
|
21
|
-
message = next;
|
|
22
|
-
});
|
|
23
|
-
return message;
|
|
24
|
-
}
|
|
25
|
-
function prepareTranslationValues(values) {
|
|
26
|
-
if (Object.keys(values).length === 0)
|
|
27
|
-
return undefined;
|
|
28
|
-
// Workaround for https://github.com/formatjs/formatjs/issues/1467
|
|
29
|
-
const transformedValues = {};
|
|
30
|
-
Object.keys(values).forEach((key) => {
|
|
31
|
-
let index = 0;
|
|
32
|
-
const value = values[key];
|
|
33
|
-
let transformed;
|
|
34
|
-
if (typeof value === 'function') {
|
|
35
|
-
transformed = (chunks) => {
|
|
36
|
-
const result = value(chunks);
|
|
37
|
-
return isValidElement(result)
|
|
38
|
-
? cloneElement(result, { key: key + index++ })
|
|
39
|
-
: result;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
transformed = value;
|
|
44
|
-
}
|
|
45
|
-
transformedValues[key] = transformed;
|
|
46
|
-
});
|
|
47
|
-
return transformedValues;
|
|
48
|
-
}
|
|
49
|
-
export function getMessagesOrError({ messages, namespace, onError = defaultOnError }) {
|
|
50
|
-
try {
|
|
51
|
-
if (!messages) {
|
|
52
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
53
|
-
? `No messages were configured on the provider.`
|
|
54
|
-
: undefined);
|
|
55
|
-
}
|
|
56
|
-
const retrievedMessages = namespace
|
|
57
|
-
? resolvePath(messages, namespace)
|
|
58
|
-
: messages;
|
|
59
|
-
if (!retrievedMessages) {
|
|
60
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
61
|
-
? `No messages for namespace \`${namespace}\` found.`
|
|
62
|
-
: undefined);
|
|
63
|
-
}
|
|
64
|
-
return retrievedMessages;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
const intlError = new IntlError(IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
68
|
-
onError(intlError);
|
|
69
|
-
return intlError;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export default function createBaseTranslator({ cachedFormatsByLocale, defaultTranslationValues, formats: globalFormats, getMessageFallback = defaultGetMessageFallback, locale, messagesOrError, namespace, onError, timeZone }) {
|
|
73
|
-
function getFallbackFromErrorAndNotify(key, code, message) {
|
|
74
|
-
const error = new IntlError(code, message);
|
|
75
|
-
onError(error);
|
|
76
|
-
return getMessageFallback({ error, key, namespace });
|
|
77
|
-
}
|
|
78
|
-
function translateBaseFn(
|
|
79
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
80
|
-
key,
|
|
81
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
82
|
-
values,
|
|
83
|
-
/** Provide custom formats for numbers, dates and times. */
|
|
84
|
-
formats) {
|
|
85
|
-
if (messagesOrError instanceof IntlError) {
|
|
86
|
-
// We have already warned about this during render
|
|
87
|
-
return getMessageFallback({
|
|
88
|
-
error: messagesOrError,
|
|
89
|
-
key,
|
|
90
|
-
namespace
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
const messages = messagesOrError;
|
|
94
|
-
let message;
|
|
95
|
-
try {
|
|
96
|
-
message = resolvePath(messages, key, namespace);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
100
|
-
}
|
|
101
|
-
function joinPath(parts) {
|
|
102
|
-
return parts.filter((part) => part != null).join('.');
|
|
103
|
-
}
|
|
104
|
-
const cacheKey = joinPath([namespace, key, String(message)]);
|
|
105
|
-
let messageFormat;
|
|
106
|
-
if (cachedFormatsByLocale?.[locale]?.[cacheKey]) {
|
|
107
|
-
messageFormat = cachedFormatsByLocale?.[locale][cacheKey];
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
if (typeof message === 'object') {
|
|
111
|
-
let code, errorMessage;
|
|
112
|
-
if (Array.isArray(message)) {
|
|
113
|
-
code = IntlErrorCode.INVALID_MESSAGE;
|
|
114
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
115
|
-
errorMessage = `Message at \`${joinPath([
|
|
116
|
-
namespace,
|
|
117
|
-
key
|
|
118
|
-
])}\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
code = IntlErrorCode.INSUFFICIENT_PATH;
|
|
123
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
124
|
-
errorMessage = `Message at \`${joinPath([
|
|
125
|
-
namespace,
|
|
126
|
-
key
|
|
127
|
-
])}\` 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`;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return getFallbackFromErrorAndNotify(key, code, errorMessage);
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
messageFormat = new IntlMessageFormat(message, locale, convertFormatsToIntlMessageFormat({ ...globalFormats, ...formats }, timeZone));
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, error.message);
|
|
137
|
-
}
|
|
138
|
-
if (cachedFormatsByLocale) {
|
|
139
|
-
if (!cachedFormatsByLocale[locale]) {
|
|
140
|
-
cachedFormatsByLocale[locale] = {};
|
|
141
|
-
}
|
|
142
|
-
cachedFormatsByLocale[locale][cacheKey] = messageFormat;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
const formattedMessage = messageFormat.format(
|
|
147
|
-
// @ts-ignore `intl-messageformat` expects a different format
|
|
148
|
-
// for rich text elements since a recent minor update. This
|
|
149
|
-
// needs to be evaluated in detail, possibly also in regards
|
|
150
|
-
// to be able to format to parts.
|
|
151
|
-
prepareTranslationValues({ ...defaultTranslationValues, ...values }));
|
|
152
|
-
if (formattedMessage == null) {
|
|
153
|
-
throw new Error(process.env.NODE_ENV !== 'production'
|
|
154
|
-
? `Unable to format \`${key}\` in ${namespace ? `namespace \`${namespace}\`` : 'messages'}`
|
|
155
|
-
: undefined);
|
|
156
|
-
}
|
|
157
|
-
// Limit the function signature to return strings or React elements
|
|
158
|
-
return isValidElement(formattedMessage) ||
|
|
159
|
-
// Arrays of React elements
|
|
160
|
-
Array.isArray(formattedMessage) ||
|
|
161
|
-
typeof formattedMessage === 'string'
|
|
162
|
-
? formattedMessage
|
|
163
|
-
: String(formattedMessage);
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.FORMATTING_ERROR, error.message);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function translateFn(
|
|
170
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
171
|
-
key,
|
|
172
|
-
/** Key value pairs for values to interpolate into the message. */
|
|
173
|
-
values,
|
|
174
|
-
/** Provide custom formats for numbers, dates and times. */
|
|
175
|
-
formats) {
|
|
176
|
-
const result = translateBaseFn(key, values, formats);
|
|
177
|
-
if (typeof result !== 'string') {
|
|
178
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.INVALID_MESSAGE, process.env.NODE_ENV !== 'production'
|
|
179
|
-
? `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.`
|
|
180
|
-
: undefined);
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
translateFn.rich = translateBaseFn;
|
|
185
|
-
translateFn.raw = (
|
|
186
|
-
/** Use a dot to indicate a level of nesting (e.g. `namespace.nestedLabel`). */
|
|
187
|
-
key) => {
|
|
188
|
-
if (messagesOrError instanceof IntlError) {
|
|
189
|
-
// We have already warned about this during render
|
|
190
|
-
return getMessageFallback({
|
|
191
|
-
error: messagesOrError,
|
|
192
|
-
key,
|
|
193
|
-
namespace
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const messages = messagesOrError;
|
|
197
|
-
try {
|
|
198
|
-
return resolvePath(messages, key, namespace);
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
return getFallbackFromErrorAndNotify(key, IntlErrorCode.MISSING_MESSAGE, error.message);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
return translateFn;
|
|
205
|
-
}
|
|
1
|
+
"use strict";var b=Object.create;var M=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var F=(r,e)=>{for(var s in e)M(r,s,{get:e[s],enumerable:!0})},R=(r,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of D(e))!K.call(r,t)&&t!==s&&M(r,t,{get:()=>e[t],enumerable:!(a=x(e,t))||a.enumerable});return r};var v=(r,e,s)=>(s=r!=null?b(G(r)):{},R(e||!r||!r.__esModule?M(s,"default",{value:r,enumerable:!0}):s,r)),C=r=>R(M({},"__esModule",{value:!0}),r);var U={};F(U,{default:()=>_,getMessagesOrError:()=>j});module.exports=C(U);var w=v(require("intl-messageformat")),p=require("react"),f=v(require("./IntlError")),O=v(require("./convertFormatsToIntlMessageFormat")),V=require("./defaults");function T(r,e,s){if(!r)throw new Error(process.env.NODE_ENV!=="production"?`No messages available at \`${s}\`.`:void 0);let a=r;return e.split(".").forEach(t=>{const u=a[t];if(t==null||u==null)throw new Error(process.env.NODE_ENV!=="production"?`Could not resolve \`${e}\` in ${s?`\`${s}\``:"messages"}.`:void 0);a=u}),a}function P(r){if(Object.keys(r).length===0)return;const e={};return Object.keys(r).forEach(s=>{let a=0;const t=r[s];let u;typeof t=="function"?u=i=>{const E=t(i);return(0,p.isValidElement)(E)?(0,p.cloneElement)(E,{key:s+a++}):E}:u=t,e[s]=u}),e}function j({messages:r,namespace:e,onError:s=V.defaultOnError}){try{if(!r)throw new Error(process.env.NODE_ENV!=="production"?"No messages were configured on the provider.":void 0);const a=e?T(r,e):r;if(!a)throw new Error(process.env.NODE_ENV!=="production"?`No messages for namespace \`${e}\` found.`:void 0);return a}catch(a){const t=new f.default(f.IntlErrorCode.MISSING_MESSAGE,a.message);return s(t),t}}function _({cachedFormatsByLocale:r,defaultTranslationValues:e,formats:s,getMessageFallback:a=V.defaultGetMessageFallback,locale:t,messagesOrError:u,namespace:i,onError:E,timeZone:$}){function c(n,l,d){const g=new f.default(l,d);return E(g),a({error:g,key:n,namespace:i})}function y(n,l,d){if(u instanceof f.default)return a({error:u,key:n,namespace:i});const g=u;let m;try{m=T(g,n,i)}catch(o){return c(n,f.IntlErrorCode.MISSING_MESSAGE,o.message)}function A(o){return o.filter(N=>N!=null).join(".")}const S=A([i,n,String(m)]);let I;if(r?.[t]?.[S])I=r?.[t][S];else{if(typeof m=="object"){let o,N;return Array.isArray(m)?(o=f.IntlErrorCode.INVALID_MESSAGE,process.env.NODE_ENV!=="production"&&(N=`Message at \`${A([i,n])}\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`)):(o=f.IntlErrorCode.INSUFFICIENT_PATH,process.env.NODE_ENV!=="production"&&(N=`Message at \`${A([i,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`)),c(n,o,N)}try{I=new w.default(m,t,(0,O.default)({...s,...d},$))}catch(o){return c(n,f.IntlErrorCode.INVALID_MESSAGE,o.message)}r&&(r[t]||(r[t]={}),r[t][S]=I)}try{const o=I.format(P({...e,...l}));if(o==null)throw new Error(process.env.NODE_ENV!=="production"?`Unable to format \`${n}\` in ${i?`namespace \`${i}\``:"messages"}`:void 0);return(0,p.isValidElement)(o)||Array.isArray(o)||typeof o=="string"?o:String(o)}catch(o){return c(n,f.IntlErrorCode.FORMATTING_ERROR,o.message)}}function h(n,l,d){const g=y(n,l,d);return typeof g!="string"?c(n,f.IntlErrorCode.INVALID_MESSAGE,process.env.NODE_ENV!=="production"?`The message \`${n}\` in ${i?`namespace \`${i}\``:"messages"} didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`:void 0):g}return h.rich=y,h.raw=n=>{if(u instanceof f.default)return a({error:u,key:n,namespace:i});const l=u;try{return T(l,n,i)}catch(d){return c(n,f.IntlErrorCode.MISSING_MESSAGE,d.message)}},h}0&&(module.exports={getMessagesOrError});
|
|
206
2
|
//# sourceMappingURL=createBaseTranslator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseTranslator.js","sourceRoot":"","sources":["../../../src/core/createBaseTranslator.tsx"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,cAAc,EAIf,MAAM,OAAO,CAAC;AAIf,OAAO,SAAS,EAAE,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAErD,OAAO,iCAAiC,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAC,yBAAyB,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAKrE,SAAS,WAAW,CAClB,QAA0C,EAC1C,GAAW,EACX,SAAkB;IAElB,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACnC,CAAC,CAAC,8BAA8B,SAAS,KAAK;YAC9C,CAAC,CAAC,SAAS,CACd,CAAC;KACH;IAED,IAAI,OAAO,GAAG,QAAQ,CAAC;IAEvB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAI,OAAe,CAAC,IAAI,CAAC,CAAC;QAEpC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CACb,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACnC,CAAC,CAAC,uBAAuB,GAAG,SACxB,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,UACnC,GAAG;gBACL,CAAC,CAAC,SAAS,CACd,CAAC;S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H,aAAa,CAAC,eAAe,EAC5B,KAAe,CAAC,OAAO,CACzB,CAAC;SACH;IACH,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
1
|
+
{"version":3,"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\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 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>({\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"],"mappings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a,aACrB,iBAAiBA,CAAG,SAClBC,EAAY,eAAeA,CAAS,KAAO,UAC7C,wFACA,MACN,EAGKW,CACT,CAEA,OAAAyB,EAAY,KAAOV,EAEnBU,EAAY,IAEVrC,GACQ,CACR,GAAIuB,aAA2B,EAAAN,QAE7B,OAAOI,EAAmB,CACxB,MAAOE,EACP,IAAAvB,EACA,UAAAC,CACF,CAAC,EAEH,MAAMF,EAAWwB,EAEjB,GAAI,CACF,OAAOzB,EAAYC,EAAUC,EAAKC,CAAS,CAC7C,OAASc,EAAO,CACd,OAAOU,EACLzB,EACA,gBAAc,gBACbe,EAAgB,OACnB,CACF,CACF,EAEOsB,CACT","names":["createBaseTranslator_exports","__export","createBaseTranslator","getMessagesOrError","__toCommonJS","import_intl_messageformat","import_react","import_IntlError","import_convertFormatsToIntlMessageFormat","import_defaults","resolvePath","messages","key","namespace","message","part","next","prepareTranslationValues","values","transformedValues","index","value","transformed","chunks","result","onError","retrievedMessages","error","intlError","IntlError","cachedFormatsByLocale","defaultTranslationValues","globalFormats","getMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","formats","joinPath","parts","cacheKey","messageFormat","errorMessage","IntlMessageFormat","convertFormatsToIntlMessageFormat","formattedMessage","translateFn"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import y from"intl-messageformat";import{cloneElement as R,isValidElement as v}from"react";import I,{IntlErrorCode as u}from"./IntlError";import w from"./convertFormatsToIntlMessageFormat";import{defaultGetMessageFallback as O,defaultOnError as _}from"./defaults";function A(t,i,f){if(!t)throw new Error(process.env.NODE_ENV!=="production"?`No messages available at \`${f}\`.`:void 0);let n=t;return i.split(".").forEach(s=>{const a=n[s];if(s==null||a==null)throw new Error(process.env.NODE_ENV!=="production"?`Could not resolve \`${i}\` in ${f?`\`${f}\``:"messages"}.`:void 0);n=a}),n}function $(t){if(Object.keys(t).length===0)return;const i={};return Object.keys(t).forEach(f=>{let n=0;const s=t[f];let a;typeof s=="function"?a=o=>{const E=s(o);return v(E)?R(E,{key:f+n++}):E}:a=s,i[f]=a}),i}function tr({messages:t,namespace:i,onError:f=_}){try{if(!t)throw new Error(process.env.NODE_ENV!=="production"?"No messages were configured on the provider.":void 0);const n=i?A(t,i):t;if(!n)throw new Error(process.env.NODE_ENV!=="production"?`No messages for namespace \`${i}\` found.`:void 0);return n}catch(n){const s=new I(u.MISSING_MESSAGE,n.message);return f(s),s}}function b({cachedFormatsByLocale:t,defaultTranslationValues:i,formats:f,getMessageFallback:n=O,locale:s,messagesOrError:a,namespace:o,onError:E,timeZone:T}){function c(r,l,d){const g=new I(l,d);return E(g),n({error:g,key:r,namespace:o})}function S(r,l,d){if(a instanceof I)return n({error:a,key:r,namespace:o});const g=a;let m;try{m=A(g,r,o)}catch(e){return c(r,u.MISSING_MESSAGE,e.message)}function V(e){return e.filter(N=>N!=null).join(".")}const h=V([o,r,String(m)]);let p;if(t?.[s]?.[h])p=t?.[s][h];else{if(typeof m=="object"){let e,N;return Array.isArray(m)?(e=u.INVALID_MESSAGE,process.env.NODE_ENV!=="production"&&(N=`Message at \`${V([o,r])}\` resolved to an array, but only strings are supported. See https://next-intl-docs.vercel.app/docs/usage/messages#arrays-of-messages`)):(e=u.INSUFFICIENT_PATH,process.env.NODE_ENV!=="production"&&(N=`Message at \`${V([o,r])}\` 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`)),c(r,e,N)}try{p=new y(m,s,w({...f,...d},T))}catch(e){return c(r,u.INVALID_MESSAGE,e.message)}t&&(t[s]||(t[s]={}),t[s][h]=p)}try{const e=p.format($({...i,...l}));if(e==null)throw new Error(process.env.NODE_ENV!=="production"?`Unable to format \`${r}\` in ${o?`namespace \`${o}\``:"messages"}`:void 0);return v(e)||Array.isArray(e)||typeof e=="string"?e:String(e)}catch(e){return c(r,u.FORMATTING_ERROR,e.message)}}function M(r,l,d){const g=S(r,l,d);return typeof g!="string"?c(r,u.INVALID_MESSAGE,process.env.NODE_ENV!=="production"?`The message \`${r}\` in ${o?`namespace \`${o}\``:"messages"} didn't resolve to a string. If you want to format rich text, use \`t.rich\` instead.`:void 0):g}return M.rich=S,M.raw=r=>{if(a instanceof I)return n({error:a,key:r,namespace:o});const l=a;try{return A(l,r,o)}catch(d){return c(r,u.MISSING_MESSAGE,d.message)}},M}export{b as default,tr as getMessagesOrError};
|
|
2
|
+
//# sourceMappingURL=createBaseTranslator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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\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 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>({\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"],"mappings":"AACA,OAAOA,MAAuB,qBAC9B,OACE,gBAAAC,EACA,kBAAAC,MAIK,QAIP,OAAOC,GAAY,iBAAAC,MAAoB,cAEvC,OAAOC,MAAuC,sCAC9C,OAAQ,6BAAAC,EAA2B,kBAAAC,MAAqB,aAKxD,SAASC,EACPC,EACAC,EACAC,EACA,CACA,GAAI,CAACF,EACH,MAAM,IAAI,MACR,QAAQ,IAAI,WAAa,aACrB,8BAA8BE,CAAS,MACvC,MACN,EAGF,IAAIC,EAAUH,EAEd,OAAAC,EAAI,MAAM,GAAG,EAAE,QAASG,GAAS,CAC/B,MAAMC,EAAQF,EAAgBC,CAAI,EAElC,GAAIA,GAAQ,MAAQC,GAAQ,KAC1B,MAAM,IAAI,MACR,QAAQ,IAAI,WAAa,aACrB,uBAAuBJ,CAAG,SACxBC,EAAY,KAAKA,CAAS,KAAO,UACnC,IACA,MACN,EAGFC,EAAUE,CACZ,CAAC,EAEMF,CACT,CAEA,SAASG,EAAyBC,EAA+B,CAC/D,GAAI,OAAO,KAAKA,CAAM,EAAE,SAAW,EAAG,OAGtC,MAAMC,EAA2C,CAAC,EAClD,cAAO,KAAKD,CAAM,EAAE,QAASN,GAAQ,CACnC,IAAIQ,EAAQ,EACZ,MAAMC,EAAQH,EAAON,CAAG,EAExB,IAAIU,EACA,OAAOD,GAAU,WACnBC,EAAeC,GAAsB,CACnC,MAAMC,EAASH,EAAME,CAAM,EAE3B,OAAOnB,EAAeoB,CAAM,EACxBrB,EAAaqB,EAAQ,CAAC,IAAKZ,EAAMQ,GAAO,CAAC,EACzCI,CACN,EAEAF,EAAcD,EAGhBF,EAAkBP,CAAG,EAAIU,CAC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EAAgB,OACnB,CACF,CACF,CAEA,SAASoB,EAOPpC,EAEAM,EAEAuB,EACQ,CACR,MAAMjB,EAASgB,EAAgB5B,EAAKM,EAAQuB,CAAO,EAEnD,OAAI,OAAOjB,GAAW,SACbc,EACL1B,EACAN,EAAc,gBACd,QAAQ,IAAI,WAAa,aACrB,iBAAiBM,CAAG,SAClBC,EAAY,eAAeA,CAAS,KAAO,UAC7C,wFACA,MACN,EAGKW,CACT,CAEA,OAAAwB,EAAY,KAAOR,EAEnBQ,EAAY,IAEVpC,GACQ,CACR,GAAIwB,aAA2B/B,EAE7B,OAAO6B,EAAmB,CACxB,MAAOE,EACP,IAAAxB,EACA,UAAAC,CACF,CAAC,EAEH,MAAMF,EAAWyB,EAEjB,GAAI,CACF,OAAO1B,EAAYC,EAAUC,EAAKC,CAAS,CAC7C,OAASe,EAAO,CACd,OAAOU,EACL1B,EACAN,EAAc,gBACbsB,EAAgB,OACnB,CACF,CACF,EAEOoB,CACT","names":["IntlMessageFormat","cloneElement","isValidElement","IntlError","IntlErrorCode","convertFormatsToIntlMessageFormat","defaultGetMessageFallback","defaultOnError","resolvePath","messages","key","namespace","message","part","next","prepareTranslationValues","values","transformedValues","index","value","transformed","chunks","result","getMessagesOrError","onError","retrievedMessages","error","intlError","createBaseTranslator","cachedFormatsByLocale","defaultTranslationValues","globalFormats","getMessageFallback","locale","messagesOrError","timeZone","getFallbackFromErrorAndNotify","code","translateBaseFn","formats","joinPath","parts","cacheKey","messageFormat","errorMessage","formattedMessage","translateFn"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import DateTimeFormatOptions from './DateTimeFormatOptions.mjs';
|
|
2
|
+
import Formats from './Formats.mjs';
|
|
3
|
+
import IntlError from './IntlError.mjs';
|
|
4
|
+
import { NumberFormatOptions } from '@formatjs/ecma402-abstract/types/number';
|
|
5
|
+
import TimeZone from './TimeZone.mjs';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
locale: string;
|
|
9
|
+
timeZone?: TimeZone;
|
|
10
|
+
onError?(error: IntlError): void;
|
|
11
|
+
formats?: Partial<Formats>;
|
|
12
|
+
now?: Date;
|
|
13
|
+
};
|
|
14
|
+
declare function createFormatter({ formats, locale, now: globalNow, onError, timeZone }: Props): {
|
|
15
|
+
dateTime: (value: Date | number, formatOrOptions?: string | DateTimeFormatOptions) => string;
|
|
16
|
+
number: (value: number | bigint, formatOrOptions?: string | NumberFormatOptions) => string;
|
|
17
|
+
relativeTime: (date: number | Date, now?: number | Date) => string;
|
|
18
|
+
list: (value: Iterable<string>, formatOrOptions?: string | Intl.ListFormatOptions) => string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { createFormatter as default };
|