@sheet-i18n/react-client 1.6.0-canary.8 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +41 -62
- package/dist/index.d.ts +41 -62
- package/dist/index.js +19 -11
- package/dist/index.mjs +18 -11
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
2
|
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
7
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
8
|
-
currentLocale?: TSupportedLocales[number];
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
};
|
|
11
|
-
declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): react_jsx_runtime.JSX.Element;
|
|
3
|
+
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
12
5
|
|
|
13
|
-
interface
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
interface MessageDescriptor {
|
|
19
|
-
id?: MessageIds;
|
|
20
|
-
description?: string | object;
|
|
21
|
-
defaultMessage?: any[];
|
|
6
|
+
interface IStorageService<V extends string> {
|
|
7
|
+
getItem(key: string): V;
|
|
8
|
+
setItem(key: string, value: V): boolean;
|
|
9
|
+
removeItem(key: string): boolean;
|
|
10
|
+
clear(): boolean;
|
|
22
11
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
/**
|
|
13
|
+
* locale storage manager
|
|
14
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
15
|
+
*/
|
|
16
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
17
|
+
getLocale(): TSupportedLocales[number];
|
|
18
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
30
19
|
}
|
|
31
|
-
|
|
20
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
21
|
+
private readonly storageService;
|
|
22
|
+
private readonly i18nStore;
|
|
23
|
+
private readonly localeStorageKey;
|
|
24
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
25
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
26
|
+
private initializeCurrentLocale;
|
|
27
|
+
getLocale: () => TSupportedLocales[number];
|
|
28
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
type UseIntlParams<D = MessageDescriptor> = Parameters
|
|
30
|
+
|
|
31
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
35
32
|
type ExtendedUseIntlParams<D = MessageDescriptor> = UseIntlParams<D> extends [infer A, infer B, ...infer Rest] ? A extends Record<string, infer V> ? [Record<string, V | React.ReactNode>, B, ...Rest] : [A, B, ...Rest] : UseIntlParams<D>;
|
|
36
33
|
type $TParams = Partial<ExtendedUseIntlParams>;
|
|
37
34
|
/**
|
|
@@ -54,48 +51,29 @@ type RuleKey = string;
|
|
|
54
51
|
type RuleFn<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe extends TypeSafe, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues = any> = (values: TValues, currentLocaleSet: ReturnType<TI18nStore['getCurrentLocaleSet']>) => TMessageId;
|
|
55
52
|
type Rules<TSupportedLocales extends SupportedLocales = SupportedLocales, TLocaleSet extends LocaleSet = LocaleSet, TTypeSafe extends TypeSafe = TypeSafe, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe> = I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe> = SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe> = SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>> = Record<RuleKey, RuleFn<TSupportedLocales, TLocaleSet, TI18nStore, TTypeSafe, TSheetTitle, TMessageId>>;
|
|
56
53
|
|
|
57
|
-
type
|
|
54
|
+
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>> = {
|
|
58
55
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
59
56
|
} & {
|
|
60
57
|
t: {
|
|
61
58
|
dynamic: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
62
|
-
|
|
59
|
+
promise: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
63
60
|
};
|
|
64
61
|
};
|
|
65
62
|
|
|
66
|
-
type
|
|
63
|
+
type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Partial<Record<TSupportedLocales[number], Record<string, any>>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TRules extends Rules> = {
|
|
67
64
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
68
65
|
} & {
|
|
69
66
|
t: {
|
|
70
67
|
dynamic: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
71
|
-
|
|
68
|
+
rule: <TRuleKey extends keyof TRules, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>>(ruleKey: TRuleKey, values?: Parameters<TRules[TRuleKey]>[0]) => TTypeSafe extends true ? TMessageId : any;
|
|
72
69
|
};
|
|
73
70
|
};
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* locale storage manager
|
|
83
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
84
|
-
*/
|
|
85
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
86
|
-
getLocale(): TSupportedLocales[number];
|
|
87
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
88
|
-
}
|
|
89
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
90
|
-
private readonly storageService;
|
|
91
|
-
private readonly i18nStore;
|
|
92
|
-
private readonly localeStorageKey;
|
|
93
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
94
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
95
|
-
private initializeCurrentLocale;
|
|
96
|
-
getLocale: () => TSupportedLocales[number];
|
|
97
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
98
|
-
}
|
|
72
|
+
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
73
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
74
|
+
currentLocale?: TSupportedLocales[number];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
};
|
|
99
77
|
|
|
100
78
|
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
101
79
|
locale: TSupportedLocales[number] | undefined;
|
|
@@ -107,20 +85,21 @@ interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly strin
|
|
|
107
85
|
fallbackUI?: React.ReactNode;
|
|
108
86
|
children: React.ReactNode;
|
|
109
87
|
}
|
|
110
|
-
declare function StorageBasedIntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, storageManager, fallbackUI, children, }: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
111
88
|
|
|
112
89
|
interface Plugins<TRules extends Rules> {
|
|
113
90
|
rules?: TRules;
|
|
114
91
|
}
|
|
115
|
-
|
|
116
|
-
IntlProvider: (
|
|
117
|
-
|
|
92
|
+
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): {
|
|
93
|
+
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
94
|
+
currentLocale?: string;
|
|
95
|
+
children?: React.ReactNode;
|
|
96
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
97
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
118
98
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
119
99
|
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
120
100
|
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
121
101
|
useLocaleStorage: typeof useLocaleStorage;
|
|
122
102
|
};
|
|
123
|
-
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): CreateI18nContextReturn<TSupportedLocales, TLocaleSet, TRules, TTypeSafe>;
|
|
124
103
|
|
|
125
104
|
declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>> {
|
|
126
105
|
private readonly i18nStore;
|
|
@@ -129,4 +108,4 @@ declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet
|
|
|
129
108
|
}
|
|
130
109
|
declare const ruleFactory: <TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>) => RuleService<TSupportedLocales, TLocaleSet, TTypeSafe, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, SafeMessageId<TSupportedLocales, TLocaleSet, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe>>;
|
|
131
110
|
|
|
132
|
-
export { type IStorageService as Storage, createI18nContext, ruleFactory };
|
|
111
|
+
export { type GetTranslationReturn as GetTranslation, LocaleStorageManager, type IStorageService as Storage, type StorageBasedIntlProviderProps, type UseTranslationReturn as UseTranslation, createI18nContext, ruleFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
2
|
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
7
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
8
|
-
currentLocale?: TSupportedLocales[number];
|
|
9
|
-
children: React.ReactNode;
|
|
10
|
-
};
|
|
11
|
-
declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): react_jsx_runtime.JSX.Element;
|
|
3
|
+
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
12
5
|
|
|
13
|
-
interface
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
interface MessageDescriptor {
|
|
19
|
-
id?: MessageIds;
|
|
20
|
-
description?: string | object;
|
|
21
|
-
defaultMessage?: any[];
|
|
6
|
+
interface IStorageService<V extends string> {
|
|
7
|
+
getItem(key: string): V;
|
|
8
|
+
setItem(key: string, value: V): boolean;
|
|
9
|
+
removeItem(key: string): boolean;
|
|
10
|
+
clear(): boolean;
|
|
22
11
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
/**
|
|
13
|
+
* locale storage manager
|
|
14
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
15
|
+
*/
|
|
16
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
17
|
+
getLocale(): TSupportedLocales[number];
|
|
18
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
30
19
|
}
|
|
31
|
-
|
|
20
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
21
|
+
private readonly storageService;
|
|
22
|
+
private readonly i18nStore;
|
|
23
|
+
private readonly localeStorageKey;
|
|
24
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
25
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
26
|
+
private initializeCurrentLocale;
|
|
27
|
+
getLocale: () => TSupportedLocales[number];
|
|
28
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
type UseIntlParams<D = MessageDescriptor> = Parameters
|
|
30
|
+
|
|
31
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
35
32
|
type ExtendedUseIntlParams<D = MessageDescriptor> = UseIntlParams<D> extends [infer A, infer B, ...infer Rest] ? A extends Record<string, infer V> ? [Record<string, V | React.ReactNode>, B, ...Rest] : [A, B, ...Rest] : UseIntlParams<D>;
|
|
36
33
|
type $TParams = Partial<ExtendedUseIntlParams>;
|
|
37
34
|
/**
|
|
@@ -54,48 +51,29 @@ type RuleKey = string;
|
|
|
54
51
|
type RuleFn<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe extends TypeSafe, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues = any> = (values: TValues, currentLocaleSet: ReturnType<TI18nStore['getCurrentLocaleSet']>) => TMessageId;
|
|
55
52
|
type Rules<TSupportedLocales extends SupportedLocales = SupportedLocales, TLocaleSet extends LocaleSet = LocaleSet, TTypeSafe extends TypeSafe = TypeSafe, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe> = I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe> = SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe> = SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>> = Record<RuleKey, RuleFn<TSupportedLocales, TLocaleSet, TI18nStore, TTypeSafe, TSheetTitle, TMessageId>>;
|
|
56
53
|
|
|
57
|
-
type
|
|
54
|
+
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>> = {
|
|
58
55
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
59
56
|
} & {
|
|
60
57
|
t: {
|
|
61
58
|
dynamic: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
62
|
-
|
|
59
|
+
promise: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
63
60
|
};
|
|
64
61
|
};
|
|
65
62
|
|
|
66
|
-
type
|
|
63
|
+
type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Partial<Record<TSupportedLocales[number], Record<string, any>>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TRules extends Rules> = {
|
|
67
64
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
68
65
|
} & {
|
|
69
66
|
t: {
|
|
70
67
|
dynamic: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: string, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? string : any;
|
|
71
|
-
|
|
68
|
+
rule: <TRuleKey extends keyof TRules, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>>(ruleKey: TRuleKey, values?: Parameters<TRules[TRuleKey]>[0]) => TTypeSafe extends true ? TMessageId : any;
|
|
72
69
|
};
|
|
73
70
|
};
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* locale storage manager
|
|
83
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
84
|
-
*/
|
|
85
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
86
|
-
getLocale(): TSupportedLocales[number];
|
|
87
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
88
|
-
}
|
|
89
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
90
|
-
private readonly storageService;
|
|
91
|
-
private readonly i18nStore;
|
|
92
|
-
private readonly localeStorageKey;
|
|
93
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
94
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
95
|
-
private initializeCurrentLocale;
|
|
96
|
-
getLocale: () => TSupportedLocales[number];
|
|
97
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
98
|
-
}
|
|
72
|
+
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
73
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
74
|
+
currentLocale?: TSupportedLocales[number];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
};
|
|
99
77
|
|
|
100
78
|
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
101
79
|
locale: TSupportedLocales[number] | undefined;
|
|
@@ -107,20 +85,21 @@ interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly strin
|
|
|
107
85
|
fallbackUI?: React.ReactNode;
|
|
108
86
|
children: React.ReactNode;
|
|
109
87
|
}
|
|
110
|
-
declare function StorageBasedIntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, storageManager, fallbackUI, children, }: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
111
88
|
|
|
112
89
|
interface Plugins<TRules extends Rules> {
|
|
113
90
|
rules?: TRules;
|
|
114
91
|
}
|
|
115
|
-
|
|
116
|
-
IntlProvider: (
|
|
117
|
-
|
|
92
|
+
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): {
|
|
93
|
+
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
94
|
+
currentLocale?: string;
|
|
95
|
+
children?: React.ReactNode;
|
|
96
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
97
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
118
98
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
119
99
|
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
120
100
|
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
121
101
|
useLocaleStorage: typeof useLocaleStorage;
|
|
122
102
|
};
|
|
123
|
-
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): CreateI18nContextReturn<TSupportedLocales, TLocaleSet, TRules, TTypeSafe>;
|
|
124
103
|
|
|
125
104
|
declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>> {
|
|
126
105
|
private readonly i18nStore;
|
|
@@ -129,4 +108,4 @@ declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet
|
|
|
129
108
|
}
|
|
130
109
|
declare const ruleFactory: <TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>) => RuleService<TSupportedLocales, TLocaleSet, TTypeSafe, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, SafeMessageId<TSupportedLocales, TLocaleSet, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe>>;
|
|
131
110
|
|
|
132
|
-
export { type IStorageService as Storage, createI18nContext, ruleFactory };
|
|
111
|
+
export { type GetTranslationReturn as GetTranslation, LocaleStorageManager, type IStorageService as Storage, type StorageBasedIntlProviderProps, type UseTranslationReturn as UseTranslation, createI18nContext, ruleFactory };
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
// src/index.ts
|
|
39
39
|
var src_exports = {};
|
|
40
40
|
__export(src_exports, {
|
|
41
|
+
LocaleStorageManager: () => LocaleStorageManager,
|
|
41
42
|
createI18nContext: () => createI18nContext,
|
|
42
43
|
ruleFactory: () => ruleFactory
|
|
43
44
|
});
|
|
@@ -287,33 +288,39 @@ function getTranslation({
|
|
|
287
288
|
sheetTitle,
|
|
288
289
|
i18nStore
|
|
289
290
|
}) {
|
|
290
|
-
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
291
|
-
sheetTitle,
|
|
292
|
-
i18nStore,
|
|
293
|
-
"server"
|
|
294
|
-
);
|
|
295
|
-
const translationService = new TranslationService(intlInstance);
|
|
296
291
|
const t = (id, values, opts, _descriptor) => {
|
|
292
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
293
|
+
sheetTitle,
|
|
294
|
+
i18nStore,
|
|
295
|
+
"server"
|
|
296
|
+
);
|
|
297
|
+
const translationService = new TranslationService(intlInstance);
|
|
297
298
|
return translationService.translate(id, values, opts, _descriptor);
|
|
298
299
|
};
|
|
299
300
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
301
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
302
|
+
sheetTitle,
|
|
303
|
+
i18nStore,
|
|
304
|
+
"server"
|
|
305
|
+
);
|
|
306
|
+
const translationService = new TranslationService(intlInstance);
|
|
300
307
|
return translationService.translate(id, values, opts, _descriptor);
|
|
301
308
|
};
|
|
302
309
|
t.promise = (id, values, opts, _descriptor) => {
|
|
303
310
|
const intlInitPromise = new Promise((resolve) => {
|
|
304
311
|
setTimeout(() => {
|
|
305
|
-
const
|
|
312
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
306
313
|
sheetTitle,
|
|
307
314
|
i18nStore,
|
|
308
315
|
"server"
|
|
309
316
|
);
|
|
310
|
-
resolve(
|
|
317
|
+
resolve(intlInstance);
|
|
311
318
|
}, 1);
|
|
312
319
|
});
|
|
313
320
|
return new Promise((resolve) => {
|
|
314
|
-
intlInitPromise.then((
|
|
315
|
-
const
|
|
316
|
-
resolve(
|
|
321
|
+
intlInitPromise.then((intlInstance) => {
|
|
322
|
+
const translationService = new TranslationService(intlInstance);
|
|
323
|
+
resolve(translationService.translate(id, values, opts, _descriptor));
|
|
317
324
|
});
|
|
318
325
|
});
|
|
319
326
|
};
|
|
@@ -562,6 +569,7 @@ var ruleFactory = (i18nStore) => {
|
|
|
562
569
|
};
|
|
563
570
|
// Annotate the CommonJS export names for ESM import in node:
|
|
564
571
|
0 && (module.exports = {
|
|
572
|
+
LocaleStorageManager,
|
|
565
573
|
createI18nContext,
|
|
566
574
|
ruleFactory
|
|
567
575
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -263,33 +263,39 @@ function getTranslation({
|
|
|
263
263
|
sheetTitle,
|
|
264
264
|
i18nStore
|
|
265
265
|
}) {
|
|
266
|
-
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
267
|
-
sheetTitle,
|
|
268
|
-
i18nStore,
|
|
269
|
-
"server"
|
|
270
|
-
);
|
|
271
|
-
const translationService = new TranslationService(intlInstance);
|
|
272
266
|
const t = (id, values, opts, _descriptor) => {
|
|
267
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
268
|
+
sheetTitle,
|
|
269
|
+
i18nStore,
|
|
270
|
+
"server"
|
|
271
|
+
);
|
|
272
|
+
const translationService = new TranslationService(intlInstance);
|
|
273
273
|
return translationService.translate(id, values, opts, _descriptor);
|
|
274
274
|
};
|
|
275
275
|
t.dynamic = (id, values, opts, _descriptor) => {
|
|
276
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
277
|
+
sheetTitle,
|
|
278
|
+
i18nStore,
|
|
279
|
+
"server"
|
|
280
|
+
);
|
|
281
|
+
const translationService = new TranslationService(intlInstance);
|
|
276
282
|
return translationService.translate(id, values, opts, _descriptor);
|
|
277
283
|
};
|
|
278
284
|
t.promise = (id, values, opts, _descriptor) => {
|
|
279
285
|
const intlInitPromise = new Promise((resolve) => {
|
|
280
286
|
setTimeout(() => {
|
|
281
|
-
const
|
|
287
|
+
const intlInstance = intlInstanceCache.getCachedIntlInstance(
|
|
282
288
|
sheetTitle,
|
|
283
289
|
i18nStore,
|
|
284
290
|
"server"
|
|
285
291
|
);
|
|
286
|
-
resolve(
|
|
292
|
+
resolve(intlInstance);
|
|
287
293
|
}, 1);
|
|
288
294
|
});
|
|
289
295
|
return new Promise((resolve) => {
|
|
290
|
-
intlInitPromise.then((
|
|
291
|
-
const
|
|
292
|
-
resolve(
|
|
296
|
+
intlInitPromise.then((intlInstance) => {
|
|
297
|
+
const translationService = new TranslationService(intlInstance);
|
|
298
|
+
resolve(translationService.translate(id, values, opts, _descriptor));
|
|
293
299
|
});
|
|
294
300
|
});
|
|
295
301
|
};
|
|
@@ -537,6 +543,7 @@ var ruleFactory = (i18nStore) => {
|
|
|
537
543
|
return new RuleService(i18nStore);
|
|
538
544
|
};
|
|
539
545
|
export {
|
|
546
|
+
LocaleStorageManager,
|
|
540
547
|
createI18nContext,
|
|
541
548
|
ruleFactory
|
|
542
549
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheet-i18n/react-client",
|
|
3
|
-
"version": "1.6.0
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "a client package for react modules used by sheet-i18n",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sheet-i18n/errors": "1.8.1",
|
|
29
28
|
"@sheet-i18n/shared-utils": "1.8.2",
|
|
30
|
-
"@sheet-i18n/
|
|
29
|
+
"@sheet-i18n/errors": "1.8.1",
|
|
30
|
+
"@sheet-i18n/react-core": "1.6.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/react": "^19.0.2",
|