@puzzle-ui/i18n 0.0.0-stage → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -2
- package/ai/instructions.md +141 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/adapters/next.cjs +11 -0
- package/dist/adapters/next.cjs.map +1 -0
- package/dist/adapters/next.d.cts +7 -0
- package/dist/adapters/next.d.ts +7 -0
- package/dist/adapters/next.js +10 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/react-router.cjs +13 -0
- package/dist/adapters/react-router.cjs.map +1 -0
- package/dist/adapters/react-router.d.cts +10 -0
- package/dist/adapters/react-router.d.ts +10 -0
- package/dist/adapters/react-router.js +12 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/request.cjs +67 -0
- package/dist/adapters/request.cjs.map +1 -0
- package/dist/adapters/request.d.cts +16 -0
- package/dist/adapters/request.d.ts +16 -0
- package/dist/adapters/request.js +65 -0
- package/dist/adapters/request.js.map +1 -0
- package/dist/adapters/tanstack.cjs +13 -0
- package/dist/adapters/tanstack.cjs.map +1 -0
- package/dist/adapters/tanstack.d.cts +10 -0
- package/dist/adapters/tanstack.d.ts +10 -0
- package/dist/adapters/tanstack.js +12 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/ai/index.cjs +205 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +75 -0
- package/dist/ai/index.d.ts +75 -0
- package/dist/ai/index.js +195 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/review.cjs +319 -0
- package/dist/ai/review.cjs.map +1 -0
- package/dist/ai/review.d.cts +91 -0
- package/dist/ai/review.d.ts +91 -0
- package/dist/ai/review.js +315 -0
- package/dist/ai/review.js.map +1 -0
- package/dist/cli/bin.cjs +10 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +12 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +310 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +309 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/index.cjs +218 -0
- package/dist/compiler/index.cjs.map +1 -0
- package/dist/compiler/index.d.cts +18 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.js +210 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/typescript.cjs +251 -0
- package/dist/compiler/typescript.cjs.map +1 -0
- package/dist/compiler/typescript.d.cts +27 -0
- package/dist/compiler/typescript.d.ts +27 -0
- package/dist/compiler/typescript.js +247 -0
- package/dist/compiler/typescript.js.map +1 -0
- package/dist/compiler/vite.cjs +94 -0
- package/dist/compiler/vite.cjs.map +1 -0
- package/dist/compiler/vite.d.cts +13 -0
- package/dist/compiler/vite.d.ts +13 -0
- package/dist/compiler/vite.js +92 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/content/index.cjs +156 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +75 -0
- package/dist/content/index.d.ts +75 -0
- package/dist/content/index.js +151 -0
- package/dist/content/index.js.map +1 -0
- package/dist/content/sanity.cjs +74 -0
- package/dist/content/sanity.cjs.map +1 -0
- package/dist/content/sanity.d.cts +19 -0
- package/dist/content/sanity.d.ts +19 -0
- package/dist/content/sanity.js +73 -0
- package/dist/content/sanity.js.map +1 -0
- package/dist/devtools/index.cjs +77 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +29 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.js +75 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/format.cjs +17 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/locale.cjs +158 -0
- package/dist/locale.cjs.map +1 -0
- package/dist/locale.d.cts +42 -0
- package/dist/locale.d.ts +42 -0
- package/dist/locale.js +155 -0
- package/dist/locale.js.map +1 -0
- package/dist/react/index.cjs +239 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.js +238 -0
- package/dist/react/index.js.map +1 -0
- package/dist/routing/index.cjs +381 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +44 -0
- package/dist/routing/index.d.ts +44 -0
- package/dist/routing/index.js +380 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/runtime.cjs +261 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +74 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +257 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seo/index.cjs +212 -0
- package/dist/seo/index.cjs.map +1 -0
- package/dist/seo/index.d.cts +52 -0
- package/dist/seo/index.d.ts +52 -0
- package/dist/seo/index.js +209 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/seo/origin.cjs +27 -0
- package/dist/seo/origin.cjs.map +1 -0
- package/dist/seo/origin.js +26 -0
- package/dist/seo/origin.js.map +1 -0
- package/dist/seo/sitemap.cjs +74 -0
- package/dist/seo/sitemap.cjs.map +1 -0
- package/dist/seo/sitemap.d.cts +16 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +72 -0
- package/dist/seo/sitemap.js.map +1 -0
- package/dist/sources/index.cjs +227 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +41 -0
- package/dist/sources/index.d.ts +41 -0
- package/dist/sources/index.js +222 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +50 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +5 -0
- package/dist/sources/node.d.ts +5 -0
- package/dist/sources/node.js +49 -0
- package/dist/sources/node.js.map +1 -0
- package/package.json +256 -4
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { I18nInstance, MessageAtPath, MessageCatalog, MessageKeys, MessageValue, RichMessageValues, RichTranslationArgs, Translator } from "../runtime.cjs";
|
|
2
|
+
import { DateTimeFormatOptions, ListFormatOptions, NumberFormatOptions, RelativeTimeFormatOptions } from "../format.cjs";
|
|
3
|
+
import { ComponentType, ReactNode } from "react";
|
|
4
|
+
export interface I18nProviderProps {
|
|
5
|
+
locale: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface LocaleSwitcherProps {
|
|
9
|
+
label?: string;
|
|
10
|
+
onLocaleChange(locale: string): void;
|
|
11
|
+
className?: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
selectClassName?: string;
|
|
17
|
+
"aria-describedby"?: string;
|
|
18
|
+
}
|
|
19
|
+
type TrimMessageVariable<Name extends string> = Name extends ` ${infer Rest}` | `\n${infer Rest}` | `\t${infer Rest}` ? TrimMessageVariable<Rest> : Name extends `${infer Rest} ` | `${infer Rest}\n` | `${infer Rest}\t` ? TrimMessageVariable<Rest> : Name;
|
|
20
|
+
type ValidMessageVariable<Name extends string> = Name extends "" | `#${string}` | `${string} ${string}` ? never : Name;
|
|
21
|
+
type MessageVariables<Message extends string> = Message extends `${string}{${infer Token}}${infer Rest}` ? ValidMessageVariable<Token extends `${infer Name},${string}` ? TrimMessageVariable<Name> : TrimMessageVariable<Token>> | MessageVariables<Rest> : never;
|
|
22
|
+
type TranslationValuesProps<Message> = [Message] extends [string] ? [MessageVariables<Extract<Message, string>>] extends [never] ? {
|
|
23
|
+
values?: never;
|
|
24
|
+
} : {
|
|
25
|
+
values: Readonly<Record<MessageVariables<Extract<Message, string>>, MessageValue>>;
|
|
26
|
+
} : {
|
|
27
|
+
values?: never;
|
|
28
|
+
};
|
|
29
|
+
type RichTranslationValuesProps<Message> = [Message] extends [string] ? [MessageVariables<Extract<Message, string>>] extends [never] ? {
|
|
30
|
+
values?: RichMessageValues<ReactNode>;
|
|
31
|
+
} : {
|
|
32
|
+
values: RichTranslationArgs<Message, ReactNode> extends [infer Values] ? Values : never;
|
|
33
|
+
} : {
|
|
34
|
+
values?: never;
|
|
35
|
+
};
|
|
36
|
+
export type TranslationComponentProps<Catalog extends MessageCatalog, Key extends MessageKeys<Catalog>> = {
|
|
37
|
+
id: Key;
|
|
38
|
+
children?: (translation: string) => ReactNode;
|
|
39
|
+
} & TranslationValuesProps<MessageAtPath<Catalog, Key>>;
|
|
40
|
+
export type RichTranslationComponentProps<Catalog extends MessageCatalog, Key extends MessageKeys<Catalog>> = {
|
|
41
|
+
id: Key;
|
|
42
|
+
children?: (translation: ReactNode) => ReactNode;
|
|
43
|
+
} & RichTranslationValuesProps<MessageAtPath<Catalog, Key>>;
|
|
44
|
+
export interface FormattedNumberProps {
|
|
45
|
+
value: number;
|
|
46
|
+
options?: NumberFormatOptions;
|
|
47
|
+
children?: (formatted: string) => ReactNode;
|
|
48
|
+
}
|
|
49
|
+
export interface FormattedCurrencyProps {
|
|
50
|
+
value: number;
|
|
51
|
+
currency: string;
|
|
52
|
+
options?: Omit<NumberFormatOptions, "style" | "currency">;
|
|
53
|
+
children?: (formatted: string) => ReactNode;
|
|
54
|
+
}
|
|
55
|
+
export interface FormattedDateProps {
|
|
56
|
+
value: Date | number;
|
|
57
|
+
options?: DateTimeFormatOptions;
|
|
58
|
+
children?: (formatted: string) => ReactNode;
|
|
59
|
+
}
|
|
60
|
+
export interface FormattedRelativeTimeProps {
|
|
61
|
+
value: number;
|
|
62
|
+
unit: Intl.RelativeTimeFormatUnit;
|
|
63
|
+
options?: RelativeTimeFormatOptions;
|
|
64
|
+
children?: (formatted: string) => ReactNode;
|
|
65
|
+
}
|
|
66
|
+
export interface FormattedListProps {
|
|
67
|
+
value: readonly string[];
|
|
68
|
+
options?: ListFormatOptions;
|
|
69
|
+
children?: (formatted: string) => ReactNode;
|
|
70
|
+
}
|
|
71
|
+
export interface I18nReactBindings<Catalog extends MessageCatalog> {
|
|
72
|
+
Provider: ComponentType<I18nProviderProps>;
|
|
73
|
+
LocaleSwitcher: ComponentType<LocaleSwitcherProps>;
|
|
74
|
+
Translation<Key extends MessageKeys<Catalog>>(props: TranslationComponentProps<Catalog, Key>): ReactNode;
|
|
75
|
+
RichTranslation<Key extends MessageKeys<Catalog>>(props: RichTranslationComponentProps<Catalog, Key>): ReactNode;
|
|
76
|
+
FormattedNumber: ComponentType<FormattedNumberProps>;
|
|
77
|
+
FormattedCurrency: ComponentType<FormattedCurrencyProps>;
|
|
78
|
+
FormattedDate: ComponentType<FormattedDateProps>;
|
|
79
|
+
FormattedRelativeTime: ComponentType<FormattedRelativeTimeProps>;
|
|
80
|
+
FormattedList: ComponentType<FormattedListProps>;
|
|
81
|
+
useLocale(): string;
|
|
82
|
+
useLocaleAttributes(): {
|
|
83
|
+
lang: string;
|
|
84
|
+
dir: "ltr" | "rtl";
|
|
85
|
+
};
|
|
86
|
+
useTranslation(): Translator<Catalog>;
|
|
87
|
+
useRichTranslation(): ReactRichTranslator<Catalog>;
|
|
88
|
+
useNamespace(namespace: string): NamespaceLoadState;
|
|
89
|
+
useNumberFormat(options?: NumberFormatOptions): Intl.NumberFormat;
|
|
90
|
+
useCurrencyFormat(currency: string, options?: Omit<NumberFormatOptions, "style" | "currency">): Intl.NumberFormat;
|
|
91
|
+
useDateFormat(options?: DateTimeFormatOptions): Intl.DateTimeFormat;
|
|
92
|
+
useRelativeTimeFormat(options?: RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
|
|
93
|
+
useListFormat(options?: ListFormatOptions): Intl.ListFormat;
|
|
94
|
+
}
|
|
95
|
+
export type ReactRichTranslator<Catalog extends MessageCatalog> = <Key extends MessageKeys<Catalog>>(key: Key, ...args: RichTranslationArgs<MessageAtPath<Catalog, Key>, ReactNode>) => ReactNode;
|
|
96
|
+
export type NamespaceLoadState = {
|
|
97
|
+
status: "loading";
|
|
98
|
+
} | {
|
|
99
|
+
status: "ready";
|
|
100
|
+
} | {
|
|
101
|
+
status: "error";
|
|
102
|
+
error: unknown;
|
|
103
|
+
};
|
|
104
|
+
export declare const createI18nReact: <Catalog extends MessageCatalog>(instance: I18nInstance<Catalog>) => I18nReactBindings<Catalog>;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { I18nInstance, MessageAtPath, MessageCatalog, MessageKeys, MessageValue, RichMessageValues, RichTranslationArgs, Translator } from "../runtime.js";
|
|
2
|
+
import { DateTimeFormatOptions, ListFormatOptions, NumberFormatOptions, RelativeTimeFormatOptions } from "../format.js";
|
|
3
|
+
import { ComponentType, ReactNode } from "react";
|
|
4
|
+
export interface I18nProviderProps {
|
|
5
|
+
locale: string;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface LocaleSwitcherProps {
|
|
9
|
+
label?: string;
|
|
10
|
+
onLocaleChange(locale: string): void;
|
|
11
|
+
className?: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
selectClassName?: string;
|
|
17
|
+
"aria-describedby"?: string;
|
|
18
|
+
}
|
|
19
|
+
type TrimMessageVariable<Name extends string> = Name extends ` ${infer Rest}` | `\n${infer Rest}` | `\t${infer Rest}` ? TrimMessageVariable<Rest> : Name extends `${infer Rest} ` | `${infer Rest}\n` | `${infer Rest}\t` ? TrimMessageVariable<Rest> : Name;
|
|
20
|
+
type ValidMessageVariable<Name extends string> = Name extends "" | `#${string}` | `${string} ${string}` ? never : Name;
|
|
21
|
+
type MessageVariables<Message extends string> = Message extends `${string}{${infer Token}}${infer Rest}` ? ValidMessageVariable<Token extends `${infer Name},${string}` ? TrimMessageVariable<Name> : TrimMessageVariable<Token>> | MessageVariables<Rest> : never;
|
|
22
|
+
type TranslationValuesProps<Message> = [Message] extends [string] ? [MessageVariables<Extract<Message, string>>] extends [never] ? {
|
|
23
|
+
values?: never;
|
|
24
|
+
} : {
|
|
25
|
+
values: Readonly<Record<MessageVariables<Extract<Message, string>>, MessageValue>>;
|
|
26
|
+
} : {
|
|
27
|
+
values?: never;
|
|
28
|
+
};
|
|
29
|
+
type RichTranslationValuesProps<Message> = [Message] extends [string] ? [MessageVariables<Extract<Message, string>>] extends [never] ? {
|
|
30
|
+
values?: RichMessageValues<ReactNode>;
|
|
31
|
+
} : {
|
|
32
|
+
values: RichTranslationArgs<Message, ReactNode> extends [infer Values] ? Values : never;
|
|
33
|
+
} : {
|
|
34
|
+
values?: never;
|
|
35
|
+
};
|
|
36
|
+
export type TranslationComponentProps<Catalog extends MessageCatalog, Key extends MessageKeys<Catalog>> = {
|
|
37
|
+
id: Key;
|
|
38
|
+
children?: (translation: string) => ReactNode;
|
|
39
|
+
} & TranslationValuesProps<MessageAtPath<Catalog, Key>>;
|
|
40
|
+
export type RichTranslationComponentProps<Catalog extends MessageCatalog, Key extends MessageKeys<Catalog>> = {
|
|
41
|
+
id: Key;
|
|
42
|
+
children?: (translation: ReactNode) => ReactNode;
|
|
43
|
+
} & RichTranslationValuesProps<MessageAtPath<Catalog, Key>>;
|
|
44
|
+
export interface FormattedNumberProps {
|
|
45
|
+
value: number;
|
|
46
|
+
options?: NumberFormatOptions;
|
|
47
|
+
children?: (formatted: string) => ReactNode;
|
|
48
|
+
}
|
|
49
|
+
export interface FormattedCurrencyProps {
|
|
50
|
+
value: number;
|
|
51
|
+
currency: string;
|
|
52
|
+
options?: Omit<NumberFormatOptions, "style" | "currency">;
|
|
53
|
+
children?: (formatted: string) => ReactNode;
|
|
54
|
+
}
|
|
55
|
+
export interface FormattedDateProps {
|
|
56
|
+
value: Date | number;
|
|
57
|
+
options?: DateTimeFormatOptions;
|
|
58
|
+
children?: (formatted: string) => ReactNode;
|
|
59
|
+
}
|
|
60
|
+
export interface FormattedRelativeTimeProps {
|
|
61
|
+
value: number;
|
|
62
|
+
unit: Intl.RelativeTimeFormatUnit;
|
|
63
|
+
options?: RelativeTimeFormatOptions;
|
|
64
|
+
children?: (formatted: string) => ReactNode;
|
|
65
|
+
}
|
|
66
|
+
export interface FormattedListProps {
|
|
67
|
+
value: readonly string[];
|
|
68
|
+
options?: ListFormatOptions;
|
|
69
|
+
children?: (formatted: string) => ReactNode;
|
|
70
|
+
}
|
|
71
|
+
export interface I18nReactBindings<Catalog extends MessageCatalog> {
|
|
72
|
+
Provider: ComponentType<I18nProviderProps>;
|
|
73
|
+
LocaleSwitcher: ComponentType<LocaleSwitcherProps>;
|
|
74
|
+
Translation<Key extends MessageKeys<Catalog>>(props: TranslationComponentProps<Catalog, Key>): ReactNode;
|
|
75
|
+
RichTranslation<Key extends MessageKeys<Catalog>>(props: RichTranslationComponentProps<Catalog, Key>): ReactNode;
|
|
76
|
+
FormattedNumber: ComponentType<FormattedNumberProps>;
|
|
77
|
+
FormattedCurrency: ComponentType<FormattedCurrencyProps>;
|
|
78
|
+
FormattedDate: ComponentType<FormattedDateProps>;
|
|
79
|
+
FormattedRelativeTime: ComponentType<FormattedRelativeTimeProps>;
|
|
80
|
+
FormattedList: ComponentType<FormattedListProps>;
|
|
81
|
+
useLocale(): string;
|
|
82
|
+
useLocaleAttributes(): {
|
|
83
|
+
lang: string;
|
|
84
|
+
dir: "ltr" | "rtl";
|
|
85
|
+
};
|
|
86
|
+
useTranslation(): Translator<Catalog>;
|
|
87
|
+
useRichTranslation(): ReactRichTranslator<Catalog>;
|
|
88
|
+
useNamespace(namespace: string): NamespaceLoadState;
|
|
89
|
+
useNumberFormat(options?: NumberFormatOptions): Intl.NumberFormat;
|
|
90
|
+
useCurrencyFormat(currency: string, options?: Omit<NumberFormatOptions, "style" | "currency">): Intl.NumberFormat;
|
|
91
|
+
useDateFormat(options?: DateTimeFormatOptions): Intl.DateTimeFormat;
|
|
92
|
+
useRelativeTimeFormat(options?: RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
|
|
93
|
+
useListFormat(options?: ListFormatOptions): Intl.ListFormat;
|
|
94
|
+
}
|
|
95
|
+
export type ReactRichTranslator<Catalog extends MessageCatalog> = <Key extends MessageKeys<Catalog>>(key: Key, ...args: RichTranslationArgs<MessageAtPath<Catalog, Key>, ReactNode>) => ReactNode;
|
|
96
|
+
export type NamespaceLoadState = {
|
|
97
|
+
status: "loading";
|
|
98
|
+
} | {
|
|
99
|
+
status: "ready";
|
|
100
|
+
} | {
|
|
101
|
+
status: "error";
|
|
102
|
+
error: unknown;
|
|
103
|
+
};
|
|
104
|
+
export declare const createI18nReact: <Catalog extends MessageCatalog>(instance: I18nInstance<Catalog>) => I18nReactBindings<Catalog>;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext, useEffect, useId, useMemo, useState } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/react/index.tsx
|
|
5
|
+
const rtlScripts = /* @__PURE__ */ new Set([
|
|
6
|
+
"adlm",
|
|
7
|
+
"aran",
|
|
8
|
+
"arab",
|
|
9
|
+
"hebr",
|
|
10
|
+
"mand",
|
|
11
|
+
"mend",
|
|
12
|
+
"nkoo",
|
|
13
|
+
"phli",
|
|
14
|
+
"phlp",
|
|
15
|
+
"prti",
|
|
16
|
+
"rohg",
|
|
17
|
+
"samr",
|
|
18
|
+
"syrc",
|
|
19
|
+
"thaa"
|
|
20
|
+
]);
|
|
21
|
+
const rtlLanguages = /* @__PURE__ */ new Set([
|
|
22
|
+
"arc",
|
|
23
|
+
"ar",
|
|
24
|
+
"ckb",
|
|
25
|
+
"dv",
|
|
26
|
+
"fa",
|
|
27
|
+
"he",
|
|
28
|
+
"nqo",
|
|
29
|
+
"ps",
|
|
30
|
+
"sd",
|
|
31
|
+
"syr",
|
|
32
|
+
"ug",
|
|
33
|
+
"ur",
|
|
34
|
+
"yi"
|
|
35
|
+
]);
|
|
36
|
+
const getLocaleDirection = (locale, configuredDirection) => {
|
|
37
|
+
if (configuredDirection) return configuredDirection;
|
|
38
|
+
const localeInfo = typeof Intl.Locale === "function" ? new Intl.Locale(locale) : void 0;
|
|
39
|
+
const textInfoDirection = localeInfo?.textInfo?.direction;
|
|
40
|
+
if (textInfoDirection === "rtl" || textInfoDirection === "ltr") return textInfoDirection;
|
|
41
|
+
const subtags = locale.split("-");
|
|
42
|
+
const script = localeInfo?.script ?? subtags.slice(1).find((subtag) => /^[A-Za-z]{4}$/.test(subtag));
|
|
43
|
+
if (script) return rtlScripts.has(script.toLowerCase()) ? "rtl" : "ltr";
|
|
44
|
+
const language = localeInfo?.language ?? subtags[0] ?? "";
|
|
45
|
+
return rtlLanguages.has(language.toLowerCase()) ? "rtl" : "ltr";
|
|
46
|
+
};
|
|
47
|
+
const createI18nReact = (instance) => {
|
|
48
|
+
const Context = createContext(null);
|
|
49
|
+
const useI18n = () => {
|
|
50
|
+
const context = useContext(Context);
|
|
51
|
+
if (!context) throw new Error("Puzzle I18n hooks must be used within the matching I18n Provider.");
|
|
52
|
+
return context;
|
|
53
|
+
};
|
|
54
|
+
const Provider = ({ locale, children }) => {
|
|
55
|
+
const translator = useMemo(() => instance.createTranslator(locale), [instance, locale]);
|
|
56
|
+
const value = useMemo(() => ({
|
|
57
|
+
locale: translator.locale,
|
|
58
|
+
translator
|
|
59
|
+
}), [translator]);
|
|
60
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
61
|
+
value,
|
|
62
|
+
children
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const LocaleSwitcher = ({ label = "Language", onLocaleChange, className, id, name, disabled, required, selectClassName, "aria-describedby": ariaDescribedBy }) => {
|
|
66
|
+
const { locale } = useI18n();
|
|
67
|
+
const generatedId = useId();
|
|
68
|
+
const selectId = id?.trim() ? id : generatedId;
|
|
69
|
+
const direction = getLocaleDirection(locale, instance.registry.get(locale)?.direction);
|
|
70
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
71
|
+
className,
|
|
72
|
+
dir: direction,
|
|
73
|
+
htmlFor: selectId,
|
|
74
|
+
lang: locale,
|
|
75
|
+
children: [label, /* @__PURE__ */ jsx("select", {
|
|
76
|
+
"aria-describedby": ariaDescribedBy,
|
|
77
|
+
className: selectClassName,
|
|
78
|
+
dir: direction,
|
|
79
|
+
disabled,
|
|
80
|
+
id: selectId,
|
|
81
|
+
lang: locale,
|
|
82
|
+
name,
|
|
83
|
+
required,
|
|
84
|
+
value: locale,
|
|
85
|
+
onChange: (event) => onLocaleChange(event.currentTarget.value),
|
|
86
|
+
children: instance.registry.locales.map((definition) => /* @__PURE__ */ jsx("option", {
|
|
87
|
+
dir: getLocaleDirection(definition.locale, definition.direction),
|
|
88
|
+
lang: definition.locale,
|
|
89
|
+
value: definition.locale,
|
|
90
|
+
children: definition.nativeName ?? definition.name ?? definition.locale
|
|
91
|
+
}, definition.locale))
|
|
92
|
+
})]
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const Translation = ({ id, values, children }) => {
|
|
96
|
+
const { translator } = useI18n();
|
|
97
|
+
const translate = translator.t;
|
|
98
|
+
const text = translate(id, values);
|
|
99
|
+
return children ? children(text) : text;
|
|
100
|
+
};
|
|
101
|
+
const RichTranslation = ({ id, values, children }) => {
|
|
102
|
+
const { translator } = useI18n();
|
|
103
|
+
const translate = translator.rich;
|
|
104
|
+
const result = translate(id, values);
|
|
105
|
+
return children ? children(result) : result;
|
|
106
|
+
};
|
|
107
|
+
const FormattedNumber = ({ value, options, children }) => {
|
|
108
|
+
const formatted = useNumberFormat(options).format(value);
|
|
109
|
+
return children ? children(formatted) : formatted;
|
|
110
|
+
};
|
|
111
|
+
const FormattedCurrency = ({ value, currency, options, children }) => {
|
|
112
|
+
const formatted = useCurrencyFormat(currency, options).format(value);
|
|
113
|
+
return children ? children(formatted) : formatted;
|
|
114
|
+
};
|
|
115
|
+
const FormattedDate = ({ value, options, children }) => {
|
|
116
|
+
const formatted = useDateFormat(options).format(value);
|
|
117
|
+
return children ? children(formatted) : formatted;
|
|
118
|
+
};
|
|
119
|
+
const FormattedRelativeTime = ({ value, unit, options, children }) => {
|
|
120
|
+
const formatted = useRelativeTimeFormat(options).format(value, unit);
|
|
121
|
+
return children ? children(formatted) : formatted;
|
|
122
|
+
};
|
|
123
|
+
const FormattedList = ({ value, options, children }) => {
|
|
124
|
+
const formatted = useListFormat(options).format(value);
|
|
125
|
+
return children ? children(formatted) : formatted;
|
|
126
|
+
};
|
|
127
|
+
const useNamespace = (namespace) => {
|
|
128
|
+
const { locale } = useI18n();
|
|
129
|
+
const key = `${locale}\u0000${namespace}`;
|
|
130
|
+
const [snapshot, setSnapshot] = useState(() => ({
|
|
131
|
+
key,
|
|
132
|
+
state: instance.isNamespaceLoaded(locale, namespace) ? { status: "ready" } : { status: "loading" }
|
|
133
|
+
}));
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (instance.isNamespaceLoaded(locale, namespace)) {
|
|
136
|
+
setSnapshot({
|
|
137
|
+
key,
|
|
138
|
+
state: { status: "ready" }
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const controller = new AbortController();
|
|
143
|
+
let active = true;
|
|
144
|
+
setSnapshot({
|
|
145
|
+
key,
|
|
146
|
+
state: { status: "loading" }
|
|
147
|
+
});
|
|
148
|
+
instance.loadNamespace(locale, namespace, { signal: controller.signal }).then(() => {
|
|
149
|
+
if (active) setSnapshot({
|
|
150
|
+
key,
|
|
151
|
+
state: { status: "ready" }
|
|
152
|
+
});
|
|
153
|
+
}, (error) => {
|
|
154
|
+
if (active) setSnapshot({
|
|
155
|
+
key,
|
|
156
|
+
state: {
|
|
157
|
+
status: "error",
|
|
158
|
+
error
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return () => {
|
|
163
|
+
active = false;
|
|
164
|
+
controller.abort();
|
|
165
|
+
};
|
|
166
|
+
}, [
|
|
167
|
+
instance,
|
|
168
|
+
key,
|
|
169
|
+
locale,
|
|
170
|
+
namespace
|
|
171
|
+
]);
|
|
172
|
+
if (snapshot.key !== key) return instance.isNamespaceLoaded(locale, namespace) ? { status: "ready" } : { status: "loading" };
|
|
173
|
+
return snapshot.state;
|
|
174
|
+
};
|
|
175
|
+
const useRichTranslation = () => {
|
|
176
|
+
const translator = useI18n().translator;
|
|
177
|
+
return useMemo(() => (key, ...args) => translator.rich(key, ...args), [translator]);
|
|
178
|
+
};
|
|
179
|
+
const useLocaleAttributes = () => {
|
|
180
|
+
const locale = useI18n().locale;
|
|
181
|
+
return useMemo(() => ({
|
|
182
|
+
lang: locale,
|
|
183
|
+
dir: getLocaleDirection(locale, instance.registry.get(locale)?.direction)
|
|
184
|
+
}), [instance, locale]);
|
|
185
|
+
};
|
|
186
|
+
const useNumberFormat = (options) => {
|
|
187
|
+
const locale = useI18n().locale;
|
|
188
|
+
return useMemo(() => new Intl.NumberFormat(locale, options), [locale, options]);
|
|
189
|
+
};
|
|
190
|
+
const useCurrencyFormat = (currency, options) => {
|
|
191
|
+
const locale = useI18n().locale;
|
|
192
|
+
return useMemo(() => new Intl.NumberFormat(locale, {
|
|
193
|
+
...options,
|
|
194
|
+
style: "currency",
|
|
195
|
+
currency
|
|
196
|
+
}), [
|
|
197
|
+
currency,
|
|
198
|
+
locale,
|
|
199
|
+
options
|
|
200
|
+
]);
|
|
201
|
+
};
|
|
202
|
+
const useDateFormat = (options) => {
|
|
203
|
+
const locale = useI18n().locale;
|
|
204
|
+
return useMemo(() => new Intl.DateTimeFormat(locale, options), [locale, options]);
|
|
205
|
+
};
|
|
206
|
+
const useRelativeTimeFormat = (options) => {
|
|
207
|
+
const locale = useI18n().locale;
|
|
208
|
+
return useMemo(() => new Intl.RelativeTimeFormat(locale, options), [locale, options]);
|
|
209
|
+
};
|
|
210
|
+
const useListFormat = (options) => {
|
|
211
|
+
const locale = useI18n().locale;
|
|
212
|
+
return useMemo(() => new Intl.ListFormat(locale, options), [locale, options]);
|
|
213
|
+
};
|
|
214
|
+
return Object.freeze({
|
|
215
|
+
Provider,
|
|
216
|
+
LocaleSwitcher,
|
|
217
|
+
Translation,
|
|
218
|
+
RichTranslation,
|
|
219
|
+
FormattedNumber,
|
|
220
|
+
FormattedCurrency,
|
|
221
|
+
FormattedDate,
|
|
222
|
+
FormattedRelativeTime,
|
|
223
|
+
FormattedList,
|
|
224
|
+
useLocale: () => useI18n().locale,
|
|
225
|
+
useLocaleAttributes,
|
|
226
|
+
useTranslation: () => useI18n().translator,
|
|
227
|
+
useRichTranslation,
|
|
228
|
+
useNamespace,
|
|
229
|
+
useNumberFormat,
|
|
230
|
+
useCurrencyFormat,
|
|
231
|
+
useDateFormat,
|
|
232
|
+
useRelativeTimeFormat,
|
|
233
|
+
useListFormat
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
export { createI18nReact };
|
|
237
|
+
|
|
238
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/react/index.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useContext,\n useEffect,\n useId,\n useMemo,\n useState,\n} from \"react\";\n\nimport type { ComponentType, ReactNode } from \"react\";\nimport type {\n I18nInstance,\n MessageAtPath,\n MessageCatalog,\n MessageKeys,\n MessageValue,\n MessageValues,\n RichMessageValues,\n RichTranslationArgs,\n Translator,\n} from \"../runtime\";\nimport type {\n DateTimeFormatOptions,\n ListFormatOptions,\n NumberFormatOptions,\n RelativeTimeFormatOptions,\n} from \"../format\";\n\nexport interface I18nProviderProps {\n locale: string;\n children: ReactNode;\n}\n\nexport interface LocaleSwitcherProps {\n label?: string;\n onLocaleChange(locale: string): void;\n className?: string;\n id?: string;\n name?: string;\n disabled?: boolean;\n required?: boolean;\n selectClassName?: string;\n \"aria-describedby\"?: string;\n}\n\ntype TrimMessageVariable<Name extends string> = Name extends\n | ` ${infer Rest}`\n | `\\n${infer Rest}`\n | `\\t${infer Rest}`\n ? TrimMessageVariable<Rest>\n : Name extends `${infer Rest} `\n | `${infer Rest}\\n`\n | `${infer Rest}\\t`\n ? TrimMessageVariable<Rest>\n : Name;\n\ntype ValidMessageVariable<Name extends string> = Name extends\n | \"\"\n | `#${string}`\n | `${string} ${string}`\n ? never\n : Name;\n\ntype MessageVariables<Message extends string> =\n Message extends `${string}{${infer Token}}${infer Rest}`\n ? ValidMessageVariable<\n Token extends `${infer Name},${string}`\n ? TrimMessageVariable<Name>\n : TrimMessageVariable<Token>\n > |\n MessageVariables<Rest>\n : never;\n\ntype TranslationValuesProps<Message> = [Message] extends [string]\n ? [MessageVariables<Extract<Message, string>>] extends [never]\n ? { values?: never }\n : {\n values: Readonly<\n Record<\n MessageVariables<Extract<Message, string>>,\n MessageValue\n >\n >;\n }\n : { values?: never };\n\ntype RichTranslationValuesProps<Message> = [Message] extends [string]\n ? [MessageVariables<Extract<Message, string>>] extends [never]\n ? { values?: RichMessageValues<ReactNode> }\n : {\n values: RichTranslationArgs<Message, ReactNode> extends [\n infer Values,\n ]\n ? Values\n : never;\n }\n : { values?: never };\n\nexport type TranslationComponentProps<\n Catalog extends MessageCatalog,\n Key extends MessageKeys<Catalog>,\n> = {\n id: Key;\n children?: (translation: string) => ReactNode;\n} & TranslationValuesProps<MessageAtPath<Catalog, Key>>;\n\nexport type RichTranslationComponentProps<\n Catalog extends MessageCatalog,\n Key extends MessageKeys<Catalog>,\n> = {\n id: Key;\n children?: (translation: ReactNode) => ReactNode;\n} & RichTranslationValuesProps<MessageAtPath<Catalog, Key>>;\n\nexport interface FormattedNumberProps {\n value: number;\n options?: NumberFormatOptions;\n children?: (formatted: string) => ReactNode;\n}\n\nexport interface FormattedCurrencyProps {\n value: number;\n currency: string;\n options?: Omit<NumberFormatOptions, \"style\" | \"currency\">;\n children?: (formatted: string) => ReactNode;\n}\n\nexport interface FormattedDateProps {\n value: Date | number;\n options?: DateTimeFormatOptions;\n children?: (formatted: string) => ReactNode;\n}\n\nexport interface FormattedRelativeTimeProps {\n value: number;\n unit: Intl.RelativeTimeFormatUnit;\n options?: RelativeTimeFormatOptions;\n children?: (formatted: string) => ReactNode;\n}\n\nexport interface FormattedListProps {\n value: readonly string[];\n options?: ListFormatOptions;\n children?: (formatted: string) => ReactNode;\n}\n\ninterface I18nContextValue<Catalog extends MessageCatalog> {\n locale: string;\n translator: Translator<Catalog>;\n}\n\nexport interface I18nReactBindings<Catalog extends MessageCatalog> {\n Provider: ComponentType<I18nProviderProps>;\n LocaleSwitcher: ComponentType<LocaleSwitcherProps>;\n Translation<Key extends MessageKeys<Catalog>>(\n props: TranslationComponentProps<Catalog, Key>,\n ): ReactNode;\n RichTranslation<Key extends MessageKeys<Catalog>>(\n props: RichTranslationComponentProps<Catalog, Key>,\n ): ReactNode;\n FormattedNumber: ComponentType<FormattedNumberProps>;\n FormattedCurrency: ComponentType<FormattedCurrencyProps>;\n FormattedDate: ComponentType<FormattedDateProps>;\n FormattedRelativeTime: ComponentType<FormattedRelativeTimeProps>;\n FormattedList: ComponentType<FormattedListProps>;\n useLocale(): string;\n useLocaleAttributes(): { lang: string; dir: \"ltr\" | \"rtl\" };\n useTranslation(): Translator<Catalog>;\n useRichTranslation(): ReactRichTranslator<Catalog>;\n useNamespace(namespace: string): NamespaceLoadState;\n useNumberFormat(options?: NumberFormatOptions): Intl.NumberFormat;\n useCurrencyFormat(\n currency: string,\n options?: Omit<NumberFormatOptions, \"style\" | \"currency\">,\n ): Intl.NumberFormat;\n useDateFormat(options?: DateTimeFormatOptions): Intl.DateTimeFormat;\n useRelativeTimeFormat(\n options?: RelativeTimeFormatOptions,\n ): Intl.RelativeTimeFormat;\n useListFormat(options?: ListFormatOptions): Intl.ListFormat;\n}\n\nexport type ReactRichTranslator<Catalog extends MessageCatalog> = <\n Key extends MessageKeys<Catalog>,\n>(\n key: Key,\n ...args: RichTranslationArgs<MessageAtPath<Catalog, Key>, ReactNode>\n) => ReactNode;\n\nexport type NamespaceLoadState =\n | { status: \"loading\" }\n | { status: \"ready\" }\n | { status: \"error\"; error: unknown };\n\nconst rtlScripts = new Set([\n \"adlm\",\n \"aran\",\n \"arab\",\n \"hebr\",\n \"mand\",\n \"mend\",\n \"nkoo\",\n \"phli\",\n \"phlp\",\n \"prti\",\n \"rohg\",\n \"samr\",\n \"syrc\",\n \"thaa\",\n]);\nconst rtlLanguages = new Set([\n \"arc\",\n \"ar\",\n \"ckb\",\n \"dv\",\n \"fa\",\n \"he\",\n \"nqo\",\n \"ps\",\n \"sd\",\n \"syr\",\n \"ug\",\n \"ur\",\n \"yi\",\n]);\n\nconst getLocaleDirection = (\n locale: string,\n configuredDirection?: \"ltr\" | \"rtl\",\n): \"ltr\" | \"rtl\" => {\n if (configuredDirection) {\n return configuredDirection;\n }\n\n const localeInfo =\n typeof Intl.Locale === \"function\"\n ? (new Intl.Locale(locale) as Intl.Locale & {\n textInfo?: { direction?: string };\n })\n : undefined;\n const textInfoDirection = localeInfo?.textInfo?.direction;\n\n if (textInfoDirection === \"rtl\" || textInfoDirection === \"ltr\") {\n return textInfoDirection;\n }\n\n const subtags = locale.split(\"-\");\n const script =\n localeInfo?.script ??\n subtags.slice(1).find((subtag) => /^[A-Za-z]{4}$/.test(subtag));\n\n if (script) {\n return rtlScripts.has(script.toLowerCase()) ? \"rtl\" : \"ltr\";\n }\n\n const language = localeInfo?.language ?? subtags[0] ?? \"\";\n return rtlLanguages.has(language.toLowerCase()) ? \"rtl\" : \"ltr\";\n};\n\ninterface NamespaceLoadSnapshot {\n key: string;\n state: NamespaceLoadState;\n}\n\nexport const createI18nReact = <Catalog extends MessageCatalog>(\n instance: I18nInstance<Catalog>,\n): I18nReactBindings<Catalog> => {\n const Context = createContext<I18nContextValue<Catalog> | null>(null);\n\n const useI18n = (): I18nContextValue<Catalog> => {\n const context = useContext(Context);\n\n if (!context) {\n throw new Error(\n \"Puzzle I18n hooks must be used within the matching I18n Provider.\",\n );\n }\n\n return context;\n };\n\n const Provider = ({ locale, children }: I18nProviderProps) => {\n const translator = useMemo(\n () => instance.createTranslator(locale),\n [instance, locale],\n );\n const value = useMemo(\n () => ({ locale: translator.locale, translator }),\n [translator],\n );\n\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n const LocaleSwitcher = ({\n label = \"Language\",\n onLocaleChange,\n className,\n id,\n name,\n disabled,\n required,\n selectClassName,\n \"aria-describedby\": ariaDescribedBy,\n }: LocaleSwitcherProps) => {\n const { locale } = useI18n();\n const generatedId = useId();\n const selectId = id?.trim() ? id : generatedId;\n const direction = getLocaleDirection(\n locale,\n instance.registry.get(locale)?.direction,\n );\n\n return (\n <label\n className={className}\n dir={direction}\n htmlFor={selectId}\n lang={locale}\n >\n {label}\n <select\n aria-describedby={ariaDescribedBy}\n className={selectClassName}\n dir={direction}\n disabled={disabled}\n id={selectId}\n lang={locale}\n name={name}\n required={required}\n value={locale}\n onChange={(event) => onLocaleChange(event.currentTarget.value)}\n >\n {instance.registry.locales.map((definition) => (\n <option\n key={definition.locale}\n dir={getLocaleDirection(definition.locale, definition.direction)}\n lang={definition.locale}\n value={definition.locale}\n >\n {definition.nativeName ?? definition.name ?? definition.locale}\n </option>\n ))}\n </select>\n </label>\n );\n };\n\n const Translation = <Key extends MessageKeys<Catalog>>({\n id,\n values,\n children,\n }: TranslationComponentProps<Catalog, Key>) => {\n const { translator } = useI18n();\n const translate = translator.t as unknown as (\n key: Key,\n values?: MessageValues,\n ) => string;\n const text = translate(id, values);\n\n return children ? children(text) : text;\n };\n\n const RichTranslation = <Key extends MessageKeys<Catalog>>({\n id,\n values,\n children,\n }: RichTranslationComponentProps<Catalog, Key>) => {\n const { translator } = useI18n();\n const translate = translator.rich as unknown as (\n key: Key,\n values?: RichMessageValues<ReactNode>,\n ) => ReactNode;\n const result = translate(\n id,\n values as RichMessageValues<ReactNode> | undefined,\n );\n\n return children ? children(result) : result;\n };\n\n const FormattedNumber = ({\n value,\n options,\n children,\n }: FormattedNumberProps) => {\n const formatted = useNumberFormat(options).format(value);\n return children ? children(formatted) : formatted;\n };\n\n const FormattedCurrency = ({\n value,\n currency,\n options,\n children,\n }: FormattedCurrencyProps) => {\n const formatted = useCurrencyFormat(currency, options).format(value);\n return children ? children(formatted) : formatted;\n };\n\n const FormattedDate = ({\n value,\n options,\n children,\n }: FormattedDateProps) => {\n const formatted = useDateFormat(options).format(value);\n return children ? children(formatted) : formatted;\n };\n\n const FormattedRelativeTime = ({\n value,\n unit,\n options,\n children,\n }: FormattedRelativeTimeProps) => {\n const formatted = useRelativeTimeFormat(options).format(value, unit);\n return children ? children(formatted) : formatted;\n };\n\n const FormattedList = ({\n value,\n options,\n children,\n }: FormattedListProps) => {\n const formatted = useListFormat(options).format(value);\n return children ? children(formatted) : formatted;\n };\n\n const useNamespace = (namespace: string): NamespaceLoadState => {\n const { locale } = useI18n();\n const key = `${locale}\\u0000${namespace}`;\n const [snapshot, setSnapshot] = useState<NamespaceLoadSnapshot>(() => ({\n key,\n state: instance.isNamespaceLoaded(locale, namespace)\n ? { status: \"ready\" }\n : { status: \"loading\" },\n }));\n\n useEffect(() => {\n if (instance.isNamespaceLoaded(locale, namespace)) {\n setSnapshot({ key, state: { status: \"ready\" } });\n return;\n }\n\n const controller = new AbortController();\n let active = true;\n setSnapshot({ key, state: { status: \"loading\" } });\n\n void instance.loadNamespace(locale, namespace, {\n signal: controller.signal,\n }).then(\n () => {\n if (active) {\n setSnapshot({ key, state: { status: \"ready\" } });\n }\n },\n (error: unknown) => {\n if (active) {\n setSnapshot({ key, state: { status: \"error\", error } });\n }\n },\n );\n\n return () => {\n active = false;\n controller.abort();\n };\n }, [instance, key, locale, namespace]);\n\n if (snapshot.key !== key) {\n return instance.isNamespaceLoaded(locale, namespace)\n ? { status: \"ready\" }\n : { status: \"loading\" };\n }\n\n return snapshot.state;\n };\n\n const useRichTranslation = (): ReactRichTranslator<Catalog> => {\n const translator = useI18n().translator;\n\n return useMemo(\n () =>\n <Key extends MessageKeys<Catalog>>(\n key: Key,\n ...args: RichTranslationArgs<MessageAtPath<Catalog, Key>, ReactNode>\n ): ReactNode => translator.rich<Key, ReactNode>(key, ...args),\n [translator],\n );\n };\n\n const useLocaleAttributes = () => {\n const locale = useI18n().locale;\n\n return useMemo(\n () => ({\n lang: locale,\n dir: getLocaleDirection(\n locale,\n instance.registry.get(locale)?.direction,\n ),\n }),\n [instance, locale],\n );\n };\n\n const useNumberFormat = (options?: NumberFormatOptions) => {\n const locale = useI18n().locale;\n return useMemo(() => new Intl.NumberFormat(locale, options), [locale, options]);\n };\n\n const useCurrencyFormat = (\n currency: string,\n options?: Omit<NumberFormatOptions, \"style\" | \"currency\">,\n ) => {\n const locale = useI18n().locale;\n return useMemo(\n () => new Intl.NumberFormat(locale, { ...options, style: \"currency\", currency }),\n [currency, locale, options],\n );\n };\n\n const useDateFormat = (options?: DateTimeFormatOptions) => {\n const locale = useI18n().locale;\n return useMemo(() => new Intl.DateTimeFormat(locale, options), [locale, options]);\n };\n\n const useRelativeTimeFormat = (\n options?: RelativeTimeFormatOptions,\n ) => {\n const locale = useI18n().locale;\n return useMemo(\n () => new Intl.RelativeTimeFormat(locale, options),\n [locale, options],\n );\n };\n\n const useListFormat = (options?: ListFormatOptions) => {\n const locale = useI18n().locale;\n return useMemo(() => new Intl.ListFormat(locale, options), [locale, options]);\n };\n\n return Object.freeze({\n Provider,\n LocaleSwitcher,\n Translation,\n RichTranslation,\n FormattedNumber,\n FormattedCurrency,\n FormattedDate,\n FormattedRelativeTime,\n FormattedList,\n useLocale: () => useI18n().locale,\n useLocaleAttributes,\n useTranslation: () => useI18n().translator,\n useRichTranslation,\n useNamespace,\n useNumberFormat,\n useCurrencyFormat,\n useDateFormat,\n useRelativeTimeForm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