use-intl 4.0.0-beta-5ec7f45 → 4.0.0-beta-67507cc

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.
@@ -1,4 +1,4 @@
1
- import type TimeZone from './TimeZone.tsx';
1
+ import type TimeZone from './TimeZone.js';
2
2
  /**
3
3
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
4
4
  */
@@ -1,5 +1,5 @@
1
- import type DateTimeFormatOptions from './DateTimeFormatOptions.tsx';
2
- import type NumberFormatOptions from './NumberFormatOptions.tsx';
1
+ import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
2
+ import type NumberFormatOptions from './NumberFormatOptions.js';
3
3
  type Formats = {
4
4
  number?: Record<string, NumberFormatOptions>;
5
5
  dateTime?: Record<string, DateTimeFormatOptions>;
@@ -1,12 +1,12 @@
1
- import type AbstractIntlMessages from './AbstractIntlMessages.tsx';
2
- import type { Locale } from './AppConfig.tsx';
3
- import type Formats from './Formats.tsx';
4
- import type IntlError from './IntlError.tsx';
5
- import type TimeZone from './TimeZone.tsx';
1
+ import type { Locale, Messages } from './AppConfig.js';
2
+ import type Formats from './Formats.js';
3
+ import type IntlError from './IntlError.js';
4
+ import type TimeZone from './TimeZone.js';
5
+ import type { DeepPartial } from './types.js';
6
6
  /**
7
7
  * Should be used for entry points that configure the library.
8
8
  */
9
- type IntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> = {
9
+ type IntlConfig = {
10
10
  /** A valid Unicode locale tag (e.g. "en" or "en-GB"). */
11
11
  locale: Locale;
12
12
  /** Global formats can be provided to achieve consistent
@@ -38,14 +38,15 @@ type IntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> =
38
38
  */
39
39
  now?: Date;
40
40
  /** All messages that will be available. */
41
- messages?: Messages;
41
+ messages?: DeepPartial<Messages>;
42
42
  };
43
+ /**
43
44
  /**
44
45
  * A stricter set of the configuration that should be used internally
45
46
  * once defaults are assigned to `IntlConfiguration`.
46
47
  */
47
- export type InitializedIntlConfig<Messages extends AbstractIntlMessages = AbstractIntlMessages> = IntlConfig<Messages> & {
48
- onError: NonNullable<IntlConfig<Messages>['onError']>;
49
- getMessageFallback: NonNullable<IntlConfig<Messages>['getMessageFallback']>;
48
+ export type InitializedIntlConfig = IntlConfig & {
49
+ onError: NonNullable<IntlConfig['onError']>;
50
+ getMessageFallback: NonNullable<IntlConfig['getMessageFallback']>;
50
51
  };
51
52
  export default IntlConfig;
@@ -1,4 +1,4 @@
1
- import type IntlErrorCode from './IntlErrorCode.tsx';
1
+ import type IntlErrorCode from './IntlErrorCode.js';
2
2
  export default class IntlError extends Error {
3
3
  readonly code: IntlErrorCode;
4
4
  readonly originalMessage: string | undefined;
@@ -1,6 +1,6 @@
1
1
  import { type Formats as IntlFormats } from 'intl-messageformat';
2
- import type Formats from './Formats.tsx';
3
- import type TimeZone from './TimeZone.tsx';
2
+ import type Formats from './Formats.js';
3
+ import type TimeZone from './TimeZone.js';
4
4
  /**
5
5
  * `intl-messageformat` uses separate keys for `date` and `time`, but there's
6
6
  * only one native API: `Intl.DateTimeFormat`. Additionally you might want to
@@ -1,11 +1,11 @@
1
1
  import { type ReactNode } from 'react';
2
- import type AbstractIntlMessages from './AbstractIntlMessages.tsx';
3
- import type Formats from './Formats.tsx';
4
- import type { InitializedIntlConfig } from './IntlConfig.tsx';
5
- import IntlError from './IntlError.tsx';
6
- import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx';
7
- import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.tsx';
8
- import { type Formatters, type IntlCache } from './formatters.tsx';
2
+ import type AbstractIntlMessages from './AbstractIntlMessages.js';
3
+ import type Formats from './Formats.js';
4
+ import type { InitializedIntlConfig } from './IntlConfig.js';
5
+ import IntlError from './IntlError.js';
6
+ import type { MessageKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
7
+ import type { MarkupTranslationValues, RichTranslationValues, TranslationValues } from './TranslationValues.js';
8
+ import { type Formatters, type IntlCache } from './formatters.js';
9
9
  export type CreateBaseTranslatorProps<Messages> = InitializedIntlConfig & {
10
10
  cache: IntlCache;
11
11
  formatters: Formatters;
@@ -1,12 +1,12 @@
1
1
  import type { ReactElement } from 'react';
2
- import type { FormatNames, Locale } from './AppConfig.tsx';
3
- import type DateTimeFormatOptions from './DateTimeFormatOptions.tsx';
4
- import type Formats from './Formats.tsx';
5
- import IntlError from './IntlError.tsx';
6
- import type NumberFormatOptions from './NumberFormatOptions.tsx';
7
- import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.tsx';
8
- import type TimeZone from './TimeZone.tsx';
9
- import { type Formatters, type IntlCache } from './formatters.tsx';
2
+ import type { FormatNames, Locale } from './AppConfig.js';
3
+ import type DateTimeFormatOptions from './DateTimeFormatOptions.js';
4
+ import type Formats from './Formats.js';
5
+ import IntlError from './IntlError.js';
6
+ import type NumberFormatOptions from './NumberFormatOptions.js';
7
+ import type RelativeTimeFormatOptions from './RelativeTimeFormatOptions.js';
8
+ import type TimeZone from './TimeZone.js';
9
+ import { type Formatters, type IntlCache } from './formatters.js';
10
10
  type Props = {
11
11
  locale: Locale;
12
12
  timeZone?: TimeZone;
@@ -1,12 +1,12 @@
1
1
  import type { ReactNode } from 'react';
2
- import type Formats from './Formats.tsx';
3
- import type ICUArgs from './ICUArgs.tsx';
4
- import type ICUTags from './ICUTags.tsx';
5
- import type IntlConfig from './IntlConfig.tsx';
6
- import type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx';
7
- import type { MarkupTagsFunction, RichTagsFunction, TranslationValues } from './TranslationValues.tsx';
8
- import { type Formatters, type IntlCache } from './formatters.tsx';
9
- import type { Prettify } from './types.tsx';
2
+ import type Formats from './Formats.js';
3
+ import type ICUArgs from './ICUArgs.js';
4
+ import type ICUTags from './ICUTags.js';
5
+ import type IntlConfig from './IntlConfig.js';
6
+ import type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
7
+ import type { MarkupTagsFunction, RichTagsFunction, TranslationValues } from './TranslationValues.js';
8
+ import { type Formatters, type IntlCache } from './formatters.js';
9
+ import type { Prettify } from './types.js';
10
10
  type ICUArgsWithTags<MessageString extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = ICUArgs<MessageString, {
11
11
  ICUArgument: string;
12
12
  ICUNumberArgument: number;
@@ -38,7 +38,7 @@ type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends
38
38
  * The namespace can also indicate nesting by using a dot
39
39
  * (e.g. `namespace.Component`).
40
40
  */
41
- export default function createTranslator<const TranslatorMessages extends IntlMessages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig<TranslatorMessages>, 'messages'> & {
41
+ export default function createTranslator<const TranslatorMessages extends IntlMessages, const Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never>({ _cache, _formatters, getMessageFallback, messages, namespace, onError, ...rest }: Omit<IntlConfig, 'messages'> & {
42
42
  messages?: TranslatorMessages;
43
43
  namespace?: Namespace;
44
44
  /** @private */
@@ -1,7 +1,7 @@
1
- import type AbstractIntlMessages from './AbstractIntlMessages.tsx';
2
- import type { InitializedIntlConfig } from './IntlConfig.tsx';
3
- import type { NestedKeyOf } from './MessageKeys.tsx';
4
- import type { Formatters, IntlCache } from './formatters.tsx';
1
+ import type AbstractIntlMessages from './AbstractIntlMessages.js';
2
+ import type { InitializedIntlConfig } from './IntlConfig.js';
3
+ import type { NestedKeyOf } from './MessageKeys.js';
4
+ import type { Formatters, IntlCache } from './formatters.js';
5
5
  export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
6
6
  namespace: string;
7
7
  messages: Messages;
@@ -9,9 +9,9 @@ export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'm
9
9
  cache: IntlCache;
10
10
  };
11
11
  export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: string): {
12
- <TargetKey extends import("./MessageKeys.tsx").MessageKeys<import("./MessageKeys.tsx").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.tsx").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.tsx").TranslationValues, formats?: import("./Formats.tsx").default): string;
13
- rich: (key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode;
14
- markup(key: Parameters<(key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode>[0], values: import("./TranslationValues.tsx").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.tsx").RichTranslationValues, formats?: import("./Formats.tsx").default) => import("react").ReactNode>[2]): string;
12
+ <TargetKey extends import("./MessageKeys.js").MessageKeys<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>, NestedKeyOf<import("./MessageKeys.js").NestedValueOf<Messages, NestedKey>>>>(key: TargetKey, values?: import("./TranslationValues.js").TranslationValues, formats?: import("./Formats.js").default): string;
13
+ rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode;
14
+ markup(key: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[0], values: import("./TranslationValues.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default) => import("react").ReactNode>[2]): string;
15
15
  raw(key: string): any;
16
16
  has(key: string): boolean;
17
17
  };
@@ -1,4 +1,4 @@
1
- import type IntlError from './IntlError.tsx';
1
+ import type IntlError from './IntlError.js';
2
2
  /**
3
3
  * Contains defaults that are used for all entry points into the core.
4
4
  * See also `InitializedIntlConfiguration`.
@@ -1,4 +1,4 @@
1
- import type { Locale } from './AppConfig.tsx';
1
+ import type { Locale } from './AppConfig.js';
2
2
  /**
3
3
  * Checks if a locale exists in a list of locales.
4
4
  *
@@ -1,20 +1,20 @@
1
- export type { default as AbstractIntlMessages } from './AbstractIntlMessages.tsx';
2
- export type { TranslationValues, RichTranslationValues, MarkupTranslationValues, RichTagsFunction, MarkupTagsFunction } from './TranslationValues.tsx';
3
- export type { default as Formats } from './Formats.tsx';
4
- export type { default as IntlConfig } from './IntlConfig.tsx';
5
- export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions.tsx';
6
- export type { default as NumberFormatOptions } from './NumberFormatOptions.tsx';
7
- export { default as IntlError } from './IntlError.tsx';
8
- export { default as IntlErrorCode } from './IntlErrorCode.tsx';
9
- export { default as createTranslator } from './createTranslator.tsx';
10
- export { default as createFormatter } from './createFormatter.tsx';
11
- export { default as initializeConfig } from './initializeConfig.tsx';
12
- export type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.tsx';
13
- export { createIntlFormatters as _createIntlFormatters } from './formatters.tsx';
14
- export { createCache as _createCache } from './formatters.tsx';
15
- export type { default as AppConfig, Locale, Messages } from './AppConfig.tsx';
16
- export { default as hasLocale } from './hasLocale.tsx';
17
- export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions.tsx';
18
- export type { default as Timezone } from './TimeZone.tsx';
19
- export type { default as ICUArgs } from './ICUArgs.tsx';
20
- export type { default as ICUTags } from './ICUTags.tsx';
1
+ export type { default as AbstractIntlMessages } from './AbstractIntlMessages.js';
2
+ export type { TranslationValues, RichTranslationValues, MarkupTranslationValues, RichTagsFunction, MarkupTagsFunction } from './TranslationValues.js';
3
+ export type { default as Formats } from './Formats.js';
4
+ export type { default as IntlConfig } from './IntlConfig.js';
5
+ export type { default as DateTimeFormatOptions } from './DateTimeFormatOptions.js';
6
+ export type { default as NumberFormatOptions } from './NumberFormatOptions.js';
7
+ export { default as IntlError } from './IntlError.js';
8
+ export { default as IntlErrorCode } from './IntlErrorCode.js';
9
+ export { default as createTranslator } from './createTranslator.js';
10
+ export { default as createFormatter } from './createFormatter.js';
11
+ export { default as initializeConfig } from './initializeConfig.js';
12
+ export type { MessageKeys, NamespaceKeys, NestedKeyOf, NestedValueOf } from './MessageKeys.js';
13
+ export { createIntlFormatters as _createIntlFormatters } from './formatters.js';
14
+ export { createCache as _createCache } from './formatters.js';
15
+ export type { default as AppConfig, Locale, Messages } from './AppConfig.js';
16
+ export { default as hasLocale } from './hasLocale.js';
17
+ export type { default as RelativeTimeFormatOptions } from './RelativeTimeFormatOptions.js';
18
+ export type { default as Timezone } from './TimeZone.js';
19
+ export type { default as ICUArgs } from './ICUArgs.js';
20
+ export type { default as ICUTags } from './ICUTags.js';
@@ -1,12 +1,12 @@
1
- import type IntlConfig from './IntlConfig.tsx';
1
+ import type IntlConfig from './IntlConfig.js';
2
2
  /**
3
3
  * Enhances the incoming props with defaults.
4
4
  */
5
5
  export default function initializeConfig<Props extends IntlConfig>({ getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "onError" | "getMessageFallback" | "messages"> & {
6
- messages: import("./AbstractIntlMessages.tsx").default | undefined;
7
- onError: (error: import("./IntlError.tsx").default) => void;
6
+ messages: import("./types.js").DeepPartial<Record<string, any>> | undefined;
7
+ onError: (error: import("./IntlError.js").default) => void;
8
8
  getMessageFallback: (info: {
9
- error: import("./IntlError.tsx").default;
9
+ error: import("./IntlError.js").default;
10
10
  key: string;
11
11
  namespace?: string;
12
12
  }) => string;
@@ -1,3 +1,6 @@
1
1
  export type Prettify<T> = {
2
2
  [K in keyof T]: T[K];
3
3
  } & {};
4
+ export type DeepPartial<Type> = {
5
+ [Key in keyof Type]?: Type[Key] extends object ? DeepPartial<Type[Key]> : Type[Key];
6
+ };
@@ -1,3 +1,3 @@
1
- import type AbstractIntlMessages from './AbstractIntlMessages.tsx';
2
- import IntlError from './IntlError.tsx';
1
+ import type AbstractIntlMessages from './AbstractIntlMessages.js';
2
+ import IntlError from './IntlError.js';
3
3
  export default function validateMessages(messages: AbstractIntlMessages, onError: (error: IntlError) => void): void;
@@ -1 +1 @@
1
- export * from './core/index.tsx';
1
+ export * from './core/index.js';
@@ -1,2 +1,2 @@
1
- export * from './core.tsx';
2
- export * from './react.tsx';
1
+ export * from './core.js';
2
+ export * from './react.js';
@@ -1,5 +1,5 @@
1
- import type { InitializedIntlConfig } from '../core/IntlConfig.tsx';
2
- import type { Formatters, IntlCache } from '../core/formatters.tsx';
1
+ import type { InitializedIntlConfig } from '../core/IntlConfig.js';
2
+ import type { Formatters, IntlCache } from '../core/formatters.js';
3
3
  export type IntlContextValue = InitializedIntlConfig & {
4
4
  formatters: Formatters;
5
5
  cache: IntlCache;
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import type IntlConfig from '../core/IntlConfig.tsx';
2
+ import type IntlConfig from '../core/IntlConfig.js';
3
3
  type Props = IntlConfig & {
4
4
  children: ReactNode;
5
5
  };
@@ -1,7 +1,7 @@
1
- export { default as IntlProvider } from './IntlProvider.tsx';
2
- export { default as useTranslations } from './useTranslations.tsx';
3
- export { default as useLocale } from './useLocale.tsx';
4
- export { default as useNow } from './useNow.tsx';
5
- export { default as useTimeZone } from './useTimeZone.tsx';
6
- export { default as useMessages } from './useMessages.tsx';
7
- export { default as useFormatter } from './useFormatter.tsx';
1
+ export { default as IntlProvider } from './IntlProvider.js';
2
+ export { default as useTranslations } from './useTranslations.js';
3
+ export { default as useLocale } from './useLocale.js';
4
+ export { default as useNow } from './useNow.js';
5
+ export { default as useTimeZone } from './useTimeZone.js';
6
+ export { default as useMessages } from './useMessages.js';
7
+ export { default as useFormatter } from './useFormatter.js';
@@ -1,2 +1,2 @@
1
- import createFormatter from '../core/createFormatter.tsx';
1
+ import createFormatter from '../core/createFormatter.js';
2
2
  export default function useFormatter(): ReturnType<typeof createFormatter>;
@@ -1,2 +1,2 @@
1
- import { type IntlContextValue } from './IntlContext.tsx';
1
+ import { type IntlContextValue } from './IntlContext.js';
2
2
  export default function useIntlContext(): IntlContextValue;
@@ -1,2 +1,2 @@
1
- import type { Locale } from '../core.tsx';
1
+ import type { Locale } from '../core.js';
2
2
  export default function useLocale(): Locale;
@@ -1,2 +1,2 @@
1
- import type { Messages } from '../core/AppConfig.tsx';
1
+ import type { Messages } from '../core/AppConfig.js';
2
2
  export default function useMessages(): Messages;
@@ -1 +1 @@
1
- export default function useTimeZone(): import("../core.tsx").Timezone | undefined;
1
+ export default function useTimeZone(): import("../core.js").Timezone | undefined;
@@ -1,6 +1,6 @@
1
- import type { Messages } from '../core/AppConfig.tsx';
2
- import type { NamespaceKeys, NestedKeyOf } from '../core/MessageKeys.tsx';
3
- import type createTranslator from '../core/createTranslator.tsx';
1
+ import type { Messages } from '../core/AppConfig.js';
2
+ import type { NamespaceKeys, NestedKeyOf } from '../core/MessageKeys.js';
3
+ import type createTranslator from '../core/createTranslator.js';
4
4
  /**
5
5
  * Translates messages from the given namespace by using the ICU syntax.
6
6
  * See https://formatjs.io/docs/core-concepts/icu-syntax.
@@ -1,9 +1,9 @@
1
- import type AbstractIntlMessages from '../core/AbstractIntlMessages.tsx';
2
- import type { NestedKeyOf } from '../core/MessageKeys.tsx';
1
+ import type AbstractIntlMessages from '../core/AbstractIntlMessages.js';
2
+ import type { NestedKeyOf } from '../core/MessageKeys.js';
3
3
  export default function useTranslationsImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>(allMessagesPrefixed: Messages, namespacePrefixed: NestedKey, namespacePrefix: string): {
4
- <TargetKey extends unknown>(key: TargetKey, values?: import("../core.tsx").TranslationValues, formats?: import("../core.tsx").Formats): string;
5
- rich: (key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode;
6
- markup(key: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[0], values: import("../core.tsx").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.tsx").RichTranslationValues, formats?: import("../core.tsx").Formats) => import("react").ReactNode>[2]): string;
4
+ <TargetKey extends unknown>(key: TargetKey, values?: import("../core.js").TranslationValues, formats?: import("../core.js").Formats): string;
5
+ rich: (key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode;
6
+ markup(key: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[0], values: import("../core.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats) => import("react").ReactNode>[2]): string;
7
7
  raw(key: string): any;
8
8
  has(key: string): boolean;
9
9
  };
@@ -1 +1 @@
1
- export * from './react/index.tsx';
1
+ export * from './react/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-intl",
3
- "version": "4.0.0-beta-5ec7f45",
3
+ "version": "4.0.0-beta-67507cc",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "description": "Internationalization (i18n) for React",
@@ -64,5 +64,5 @@
64
64
  "peerDependencies": {
65
65
  "react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0"
66
66
  },
67
- "gitHead": "5fefd099d53560ee76badb418afd80570e56a5a1"
67
+ "gitHead": "9220b68c2e83f70b1d45ecad3f672ecf2cde0d57"
68
68
  }