@common.js/use-intl 4.13.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/LICENSE +21 -0
- package/README.md +5 -0
- package/core.d.ts +2 -0
- package/dist/esm/development/core.js +174 -0
- package/dist/esm/development/format-message/format-only.js +314 -0
- package/dist/esm/development/format-message/index.js +238 -0
- package/dist/esm/development/formatters-r4aAmsMP.js +266 -0
- package/dist/esm/development/index.js +64 -0
- package/dist/esm/development/initializeConfig-CUsOI8u2.js +651 -0
- package/dist/esm/development/react.js +390 -0
- package/dist/esm/production/core.js +149 -0
- package/dist/esm/production/format-message/format-only.js +299 -0
- package/dist/esm/production/format-message/index.js +188 -0
- package/dist/esm/production/formatters-CJcico0N.js +244 -0
- package/dist/esm/production/index.js +64 -0
- package/dist/esm/production/initializeConfig-CHgjheii.js +399 -0
- package/dist/esm/production/react.js +270 -0
- package/dist/types/core/AbstractIntlMessages.d.ts +10 -0
- package/dist/types/core/AppConfig.d.ts +29 -0
- package/dist/types/core/DateTimeFormatOptions.d.ts +73 -0
- package/dist/types/core/Formats.d.ts +9 -0
- package/dist/types/core/ICUArgs.d.ts +3 -0
- package/dist/types/core/ICUTags.d.ts +2 -0
- package/dist/types/core/IntlConfig.d.ts +54 -0
- package/dist/types/core/IntlError.d.ts +6 -0
- package/dist/types/core/IntlErrorCode.d.ts +10 -0
- package/dist/types/core/MessageKeys.d.ts +10 -0
- package/dist/types/core/NumberFormatOptions.d.ts +3 -0
- package/dist/types/core/RelativeTimeFormatOptions.d.ts +7 -0
- package/dist/types/core/TimeZone.d.ts +2 -0
- package/dist/types/core/TranslationValues.d.ts +6 -0
- package/dist/types/core/convertFormatsToIntlMessageFormat.d.ts +11 -0
- package/dist/types/core/createBaseTranslator.d.ts +21 -0
- package/dist/types/core/createFormatter.d.ts +47 -0
- package/dist/types/core/createTranslator.d.ts +59 -0
- package/dist/types/core/createTranslatorImpl.d.ts +17 -0
- package/dist/types/core/defaults.d.ts +11 -0
- package/dist/types/core/format-message/compile-format.d.ts +12 -0
- package/dist/types/core/format-message/format-only.d.ts +13 -0
- package/dist/types/core/format-message/index.d.ts +5 -0
- package/dist/types/core/format-message/types.d.ts +15 -0
- package/dist/types/core/formatters.d.ts +25 -0
- package/dist/types/core/hasLocale.d.ts +7 -0
- package/dist/types/core/index.d.ts +22 -0
- package/dist/types/core/initializeConfig.d.ts +14 -0
- package/dist/types/core/joinPath.d.ts +1 -0
- package/dist/types/core/resolveNamespace.d.ts +5 -0
- package/dist/types/core/types.d.ts +6 -0
- package/dist/types/core/validateMessages.d.ts +3 -0
- package/dist/types/core.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/react/IntlContext.d.ts +8 -0
- package/dist/types/react/IntlProvider.d.ts +7 -0
- package/dist/types/react/index.d.ts +9 -0
- package/dist/types/react/useExtracted.d.ts +42 -0
- package/dist/types/react/useFormatter.d.ts +2 -0
- package/dist/types/react/useIntlContext.d.ts +2 -0
- package/dist/types/react/useLocale.d.ts +2 -0
- package/dist/types/react/useMessages.d.ts +2 -0
- package/dist/types/react/useNow.d.ts +8 -0
- package/dist/types/react/useTimeZone.d.ts +1 -0
- package/dist/types/react/useTranslations.d.ts +12 -0
- package/dist/types/react/useTranslationsImpl.d.ts +9 -0
- package/dist/types/react.d.ts +1 -0
- package/format-message/format-only.d.ts +2 -0
- package/format-message.d.ts +2 -0
- package/package.json +45 -0
- package/react.d.ts +2 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
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
|
+
type ICUArgsWithTags<MessageString extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = ICUArgs<MessageString, {
|
|
11
|
+
ICUArgument: string;
|
|
12
|
+
ICUNumberArgument: number | bigint;
|
|
13
|
+
ICUDateArgument: Date;
|
|
14
|
+
}> & ([TagsFn] extends [never] ? {} : ICUTags<MessageString, TagsFn>);
|
|
15
|
+
type OnlyOptional<T> = Partial<T> extends T ? true : false;
|
|
16
|
+
export type TranslateArgs<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = string extends Value ? [
|
|
17
|
+
values?: Record<string, TranslationValues[string] | TagsFn>,
|
|
18
|
+
formats?: Formats
|
|
19
|
+
] : (Value extends any ? (key: ICUArgsWithTags<Value, TagsFn>) => void : never) extends (key: infer Args) => void ? OnlyOptional<Args> extends true ? [values?: undefined, formats?: Formats] : [values: Prettify<Args>, formats?: Formats] : never;
|
|
20
|
+
type IntlMessages = Record<string, any>;
|
|
21
|
+
type NamespacedMessageKeys<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = MessageKeys<NestedValueOf<{
|
|
22
|
+
'!': TranslatorMessages;
|
|
23
|
+
}, [
|
|
24
|
+
Namespace
|
|
25
|
+
] extends [never] ? '!' : `!.${Namespace}`>, NestedKeyOf<NestedValueOf<{
|
|
26
|
+
'!': TranslatorMessages;
|
|
27
|
+
}, [
|
|
28
|
+
Namespace
|
|
29
|
+
] extends [never] ? '!' : `!.${Namespace}`>>>;
|
|
30
|
+
type NamespacedValue<TranslatorMessages extends IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>>, TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>> = NestedValueOf<TranslatorMessages, [
|
|
31
|
+
Namespace
|
|
32
|
+
] extends [never] ? TargetKey : `${Namespace}.${TargetKey}`>;
|
|
33
|
+
/**
|
|
34
|
+
* @private Not intended for direct use.
|
|
35
|
+
*/
|
|
36
|
+
export type Translator<TranslatorMessages extends IntlMessages = IntlMessages, Namespace extends NamespaceKeys<TranslatorMessages, NestedKeyOf<TranslatorMessages>> = never> = {
|
|
37
|
+
<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>>): string;
|
|
38
|
+
rich<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, RichTagsFunction>): ReactNode;
|
|
39
|
+
markup<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey, ...args: TranslateArgs<NamespacedValue<TranslatorMessages, Namespace, TargetKey>, MarkupTagsFunction>): string;
|
|
40
|
+
raw<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): any;
|
|
41
|
+
has<TargetKey extends NamespacedMessageKeys<TranslatorMessages, Namespace>>(key: TargetKey): boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
45
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
46
|
+
*
|
|
47
|
+
* If no namespace is provided, all available messages are returned.
|
|
48
|
+
* The namespace can also indicate nesting by using a dot
|
|
49
|
+
* (e.g. `namespace.Component`).
|
|
50
|
+
*/
|
|
51
|
+
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'> & {
|
|
52
|
+
messages?: TranslatorMessages;
|
|
53
|
+
namespace?: Namespace;
|
|
54
|
+
/** @private */
|
|
55
|
+
_formatters?: Formatters;
|
|
56
|
+
/** @private */
|
|
57
|
+
_cache?: IntlCache;
|
|
58
|
+
}): Translator<TranslatorMessages, Namespace>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export type CreateTranslatorImplProps<Messages> = Omit<InitializedIntlConfig, 'messages'> & {
|
|
6
|
+
namespace: string;
|
|
7
|
+
messages: Messages;
|
|
8
|
+
formatters: Formatters;
|
|
9
|
+
cache: IntlCache;
|
|
10
|
+
};
|
|
11
|
+
export default function createTranslatorImpl<Messages extends AbstractIntlMessages, NestedKey extends NestedKeyOf<Messages>>({ messages, namespace, ...rest }: CreateTranslatorImplProps<Messages>, namespacePrefix: 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, _fallback?: never): string;
|
|
13
|
+
rich: (key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode;
|
|
14
|
+
markup(key: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode>[0], values: import("./TranslationValues.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("./TranslationValues.js").RichTranslationValues, formats?: import("./Formats.js").default, _fallback?: never) => import("react").ReactNode>[2], _fallback?: never): string;
|
|
15
|
+
raw(key: string): any;
|
|
16
|
+
has(key: string): boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type IntlError from './IntlError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Contains defaults that are used for all entry points into the core.
|
|
4
|
+
* See also `InitializedIntlConfiguration`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function defaultGetMessageFallback(props: {
|
|
7
|
+
error: IntlError;
|
|
8
|
+
key: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function defaultOnError(error: IntlError): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FormatMessage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles and formats an ICU message at runtime using intl-messageformat.
|
|
4
|
+
* This is the default implementation used when messages are not precompiled.
|
|
5
|
+
*/
|
|
6
|
+
declare function formatMessage(
|
|
7
|
+
/** The raw ICU message string (or precompiled message, though this implementation ignores precompilation) */
|
|
8
|
+
...[key, message, values, options]: Parameters<FormatMessage<string>>): ReturnType<FormatMessage<string>>;
|
|
9
|
+
declare namespace formatMessage {
|
|
10
|
+
var raw: boolean;
|
|
11
|
+
}
|
|
12
|
+
export default formatMessage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CompiledMessage } from 'icu-minify/format';
|
|
2
|
+
import type { FormatMessage } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Formats a precompiled ICU message using icu-minify/format.
|
|
5
|
+
* This implementation requires messages to be precompiled at build time.
|
|
6
|
+
*/
|
|
7
|
+
declare function formatMessage(
|
|
8
|
+
/** The precompiled ICU message (CompiledMessage from icu-minify) */
|
|
9
|
+
...[, message, values, options]: Parameters<FormatMessage<CompiledMessage>>): ReturnType<FormatMessage<CompiledMessage>>;
|
|
10
|
+
declare namespace formatMessage {
|
|
11
|
+
var raw: boolean;
|
|
12
|
+
}
|
|
13
|
+
export default formatMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type Formats from '../Formats.js';
|
|
3
|
+
import type TimeZone from '../TimeZone.js';
|
|
4
|
+
import type { RichTranslationValues } from '../TranslationValues.js';
|
|
5
|
+
import type { Formatters, IntlCache } from '../formatters.js';
|
|
6
|
+
type FormatMessageOptions = {
|
|
7
|
+
cache: IntlCache;
|
|
8
|
+
formatters: Formatters;
|
|
9
|
+
globalFormats?: Formats;
|
|
10
|
+
formats?: Formats;
|
|
11
|
+
locale: string;
|
|
12
|
+
timeZone?: TimeZone;
|
|
13
|
+
};
|
|
14
|
+
export type FormatMessage<Message> = (key: string, message: Message, values: RichTranslationValues | undefined, options: FormatMessageOptions) => ReactNode;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IntlMessageFormat } from 'intl-messageformat';
|
|
2
|
+
export type IntlCache = {
|
|
3
|
+
dateTime: Record<string, Intl.DateTimeFormat>;
|
|
4
|
+
number: Record<string, Intl.NumberFormat>;
|
|
5
|
+
message: Record<string, IntlMessageFormat>;
|
|
6
|
+
relativeTime: Record<string, Intl.RelativeTimeFormat>;
|
|
7
|
+
pluralRules: Record<string, Intl.PluralRules>;
|
|
8
|
+
list: Record<string, Intl.ListFormat>;
|
|
9
|
+
displayNames: Record<string, Intl.DisplayNames>;
|
|
10
|
+
};
|
|
11
|
+
export declare function createCache(): IntlCache;
|
|
12
|
+
export declare function memoFn<Fn extends (...args: Array<any>) => any>(fn: Fn, cache: Record<string, ReturnType<Fn> | undefined>): Fn;
|
|
13
|
+
export type IntlFormatters = {
|
|
14
|
+
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
|
|
15
|
+
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
|
|
16
|
+
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
|
|
17
|
+
getRelativeTimeFormat(...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>): Intl.RelativeTimeFormat;
|
|
18
|
+
getListFormat(...args: ConstructorParameters<typeof Intl.ListFormat>): Intl.ListFormat;
|
|
19
|
+
getDisplayNames(...args: ConstructorParameters<typeof Intl.DisplayNames>): Intl.DisplayNames;
|
|
20
|
+
};
|
|
21
|
+
export declare function createIntlFormatters(cache: IntlCache): IntlFormatters;
|
|
22
|
+
export type MessageFormatter = (...args: ConstructorParameters<typeof IntlMessageFormat>) => IntlMessageFormat;
|
|
23
|
+
export type Formatters = IntlFormatters & {
|
|
24
|
+
getMessageFormat?: MessageFormatter;
|
|
25
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Locale } from './AppConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a locale exists in a list of locales.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale
|
|
6
|
+
*/
|
|
7
|
+
export default function hasLocale<LocaleType extends Locale>(locales: ReadonlyArray<LocaleType>, candidate: unknown): candidate is LocaleType;
|
|
@@ -0,0 +1,22 @@
|
|
|
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';
|
|
21
|
+
/** @private -- Only for type portability */
|
|
22
|
+
export type { Translator as _Translator } from './createTranslator.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type IntlConfig from './IntlConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Enhances the incoming props with defaults.
|
|
4
|
+
*/
|
|
5
|
+
export default function initializeConfig<Props extends IntlConfig>({ formats, getMessageFallback, messages, onError, ...rest }: Props): Omit<Props, "formats" | "messages" | "onError" | "getMessageFallback"> & {
|
|
6
|
+
formats: NonNullable<IntlConfig["formats"]> | undefined;
|
|
7
|
+
messages: NonNullable<IntlConfig["messages"]> | undefined;
|
|
8
|
+
onError: (error: import("./IntlError.js").default) => void;
|
|
9
|
+
getMessageFallback: (info: {
|
|
10
|
+
error: import("./IntlError.js").default;
|
|
11
|
+
key: string;
|
|
12
|
+
namespace?: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function joinPath(...parts: Array<string | undefined>): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './core/index.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InitializedIntlConfig } from '../core/IntlConfig.js';
|
|
2
|
+
import type { Formatters, IntlCache } from '../core/formatters.js';
|
|
3
|
+
export type IntlContextValue = InitializedIntlConfig & {
|
|
4
|
+
formatters: Formatters;
|
|
5
|
+
cache: IntlCache;
|
|
6
|
+
};
|
|
7
|
+
declare const IntlContext: import("react").Context<IntlContextValue | undefined>;
|
|
8
|
+
export default IntlContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type IntlConfig from '../core/IntlConfig.js';
|
|
3
|
+
type Props = IntlConfig & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
export default function IntlProvider({ children, formats, getMessageFallback, locale, messages, now, onError, timeZone }: Props): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
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';
|
|
8
|
+
/** @private -- Only for usage in `next-intl` currently */
|
|
9
|
+
export { default as _useExtracted } from './useExtracted.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MarkupTagsFunction, RichTagsFunction } from '../core/TranslationValues.js';
|
|
3
|
+
import type { TranslateArgs } from '../core/createTranslator.js';
|
|
4
|
+
type TranslateArgsObject<Value extends string, TagsFn extends RichTagsFunction | MarkupTagsFunction = never> = TranslateArgs<Value, TagsFn> extends readonly [any?, any?] ? undefined extends TranslateArgs<Value, TagsFn>[0] ? {
|
|
5
|
+
values?: TranslateArgs<Value, TagsFn>[0];
|
|
6
|
+
formats?: TranslateArgs<Value, TagsFn>[1];
|
|
7
|
+
} : {
|
|
8
|
+
values: TranslateArgs<Value, TagsFn>[0];
|
|
9
|
+
formats?: TranslateArgs<Value, TagsFn>[1];
|
|
10
|
+
} : never;
|
|
11
|
+
export default function useExtracted(namespace?: string): {
|
|
12
|
+
<Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message>): string;
|
|
13
|
+
<Message extends string>(params: {
|
|
14
|
+
id?: string;
|
|
15
|
+
/** Inline ICU message in the source locale. */
|
|
16
|
+
message: Message;
|
|
17
|
+
/** Description for translators and tooling. */
|
|
18
|
+
description?: string;
|
|
19
|
+
} & TranslateArgsObject<Message>): string;
|
|
20
|
+
rich: {
|
|
21
|
+
<Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message, RichTagsFunction>): ReactNode;
|
|
22
|
+
<Message extends string>(params: {
|
|
23
|
+
id?: string;
|
|
24
|
+
/** Inline ICU message in the source locale. */
|
|
25
|
+
message: Message;
|
|
26
|
+
/** Description for translators and tooling. */
|
|
27
|
+
description?: string;
|
|
28
|
+
} & TranslateArgsObject<Message, RichTagsFunction>): ReactNode;
|
|
29
|
+
};
|
|
30
|
+
markup: {
|
|
31
|
+
<Message extends string>(message: Message, ...[values, formats]: TranslateArgs<Message, MarkupTagsFunction>): string;
|
|
32
|
+
<Message extends string>(params: {
|
|
33
|
+
id?: string;
|
|
34
|
+
/** Inline ICU message in the source locale. */
|
|
35
|
+
message: Message;
|
|
36
|
+
/** Description for translators and tooling. */
|
|
37
|
+
description?: string;
|
|
38
|
+
} & TranslateArgsObject<Message, MarkupTagsFunction>): string;
|
|
39
|
+
};
|
|
40
|
+
has<Message extends string>(message: Message): boolean;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useTimeZone(): import("../core.js").Timezone | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Translates messages from the given namespace by using the ICU syntax.
|
|
6
|
+
* See https://formatjs.io/docs/core-concepts/icu-syntax.
|
|
7
|
+
*
|
|
8
|
+
* If no namespace is provided, all available messages are returned.
|
|
9
|
+
* The namespace can also indicate nesting by using a dot
|
|
10
|
+
* (e.g. `namespace.Component`).
|
|
11
|
+
*/
|
|
12
|
+
export default function useTranslations<NestedKey extends NamespaceKeys<Messages, NestedKeyOf<Messages>> = never>(namespace?: NestedKey): ReturnType<typeof createTranslator<Messages, NestedKey>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type AbstractIntlMessages from '../core/AbstractIntlMessages.js';
|
|
2
|
+
import type { NestedKeyOf } from '../core/MessageKeys.js';
|
|
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.js").TranslationValues, formats?: import("../core.js").Formats, _fallback?: never): string;
|
|
5
|
+
rich: (key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode;
|
|
6
|
+
markup(key: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode>[0], values: import("../core.js").MarkupTranslationValues, formats?: Parameters<(key: string, values?: import("../core.js").RichTranslationValues, formats?: import("../core.js").Formats, _fallback?: never) => import("react").ReactNode>[2], _fallback?: never): string;
|
|
7
|
+
raw(key: string): any;
|
|
8
|
+
has(key: string): boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react/index.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@common.js/use-intl",
|
|
3
|
+
"version": "4.13.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"funding": [
|
|
6
|
+
{
|
|
7
|
+
"type": "individual",
|
|
8
|
+
"url": "https://github.com/sponsors/amannn"
|
|
9
|
+
}
|
|
10
|
+
],
|
|
11
|
+
"description": "use-intl package exported as CommonJS modules",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
14
|
+
"repository": "etienne-martin/common.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rm -rf dist && rollup -c",
|
|
17
|
+
"test": "TZ=Europe/Berlin vitest",
|
|
18
|
+
"lint": "pnpm run lint:source && pnpm run lint:package",
|
|
19
|
+
"lint:source": "eslint src test && tsc --noEmit && pnpm run lint:prettier",
|
|
20
|
+
"lint:package": "publint && attw --pack --ignore-rules=cjs-resolves-to-esm",
|
|
21
|
+
"lint:prettier": "prettier src --check",
|
|
22
|
+
"size": "size-limit"
|
|
23
|
+
},
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"main": "./dist/esm/production/index.js",
|
|
26
|
+
"typings": "./dist/types/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"core.d.ts",
|
|
30
|
+
"react.d.ts",
|
|
31
|
+
"format-message.d.ts",
|
|
32
|
+
"format-message"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@common.js/formatjs__fast-memoize": "^3.1.0",
|
|
36
|
+
"@common.js/schummar__icu-type-parser": "1.21.5",
|
|
37
|
+
"@common.js/icu-minify": "^4.13.1",
|
|
38
|
+
"@common.js/intl-messageformat": "^11.1.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "976ca1f83a6e06b5646865b87c4fb461cbf84374",
|
|
44
|
+
"types": "./dist/types/index.d.ts"
|
|
45
|
+
}
|
package/react.d.ts
ADDED