@sheet-i18n/react 1.7.8 → 1.7.9
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 +5 -0
- package/dist/index.d.mts +13 -12
- package/dist/index.d.ts +13 -12
- package/dist/index.js +40 -10
- package/dist/index.mjs +46 -16
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ export const i18nStore = new I18nStore({
|
|
|
71
71
|
// jp: () => import('./jp.json'),
|
|
72
72
|
// cn: () => import('./cn.json'),
|
|
73
73
|
// },
|
|
74
|
+
// preload: ['ko', 'en'],
|
|
74
75
|
});
|
|
75
76
|
```
|
|
76
77
|
|
|
@@ -139,6 +140,7 @@ Import it from `@sheet-i18n/core`, then pass the created store to `createI18nCon
|
|
|
139
140
|
| `defaultLocale` | string | ✅ | Default locale to use when no match is found. Must be included in `supportedLocales`. |
|
|
140
141
|
| localeSet | Record<string, object> | | _(Static Loading Option)_ Preload all translation data for each locale in memory. Keys must match `supportedLocales`. |
|
|
141
142
|
| dynamicLoaders | Record<string, () => Promise<any>> | | _(Recommended for large locale sets)_ Dynamically load translation data on demand, reducing initial bundle size. |
|
|
143
|
+
| preload | string[] | | Locales to preload eagerly. This option is available only when `dynamicLoaders` is defined. |
|
|
142
144
|
| typeSafe | boolean | | Enable strict key checking and autocompletion (default: `false`). |
|
|
143
145
|
| |
|
|
144
146
|
|
|
@@ -190,10 +192,12 @@ export const i18nStore = new I18nStore({
|
|
|
190
192
|
fr: () => import('./fr.json'),
|
|
191
193
|
ko: () => import('./ko.json'),
|
|
192
194
|
},
|
|
195
|
+
preload: ['en'],
|
|
193
196
|
});
|
|
194
197
|
```
|
|
195
198
|
|
|
196
199
|
💡 When both `localeSet` and `dynamicLoaders` are defined, sheet-i18n **automatically merges** both sources — static data loads immediately, while dynamic data supplements on-demand.
|
|
200
|
+
`preload` can be used only together with `dynamicLoaders`, and its values must be locale keys that exist in `dynamicLoaders`.
|
|
197
201
|
|
|
198
202
|
---
|
|
199
203
|
|
|
@@ -225,6 +229,7 @@ export const i18nStore = new I18nStore({
|
|
|
225
229
|
// jp: () => import('./jp.json'),
|
|
226
230
|
// cn: () => import('./cn.json'),
|
|
227
231
|
// },
|
|
232
|
+
// preload: ['ko'],
|
|
228
233
|
});
|
|
229
234
|
```
|
|
230
235
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _sheet_i18n_shared_service from '@sheet-i18n/shared-service';
|
|
2
2
|
import { LocaleStorageManager, IStorageService } from '@sheet-i18n/shared-service';
|
|
3
3
|
export { LocaleStorageManager, IStorageService as Storage, ruleFactory } from '@sheet-i18n/shared-service';
|
|
4
|
+
import { SupportedLocales, LocaleSet, DynamicLoaderMap, TypeSafe, SafeSheetTitle, SafeMessageId } from '@sheet-i18n/typescript';
|
|
4
5
|
import { I18nStore } from '@sheet-i18n/core';
|
|
5
6
|
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
6
|
-
import { SupportedLocales, LocaleSet, TypeSafe, SafeSheetTitle, SafeMessageId } from '@sheet-i18n/typescript';
|
|
7
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
8
|
|
|
9
9
|
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
@@ -15,13 +15,13 @@ type RuleKey = string;
|
|
|
15
15
|
* Used internally by RuleService / ruleFactory so that createRule infers the
|
|
16
16
|
* correct value and message-id types from the store's locale data.
|
|
17
17
|
*/
|
|
18
|
-
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;
|
|
18
|
+
type RuleFn<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales>, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, 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;
|
|
19
19
|
/**
|
|
20
20
|
* Extended rules map with full generic chain.
|
|
21
21
|
* Consumers can annotate their rules objects with the simpler `Rules` from
|
|
22
22
|
* @sheet-i18n/typescript; this extended version is used for inference only.
|
|
23
23
|
*/
|
|
24
|
-
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>>;
|
|
24
|
+
type Rules<TSupportedLocales extends SupportedLocales = SupportedLocales, TLocaleSet extends LocaleSet = LocaleSet, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends TypeSafe = TypeSafe, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe> = I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, 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, TDynamicLoaders, TI18nStore, TTypeSafe, TSheetTitle, TMessageId>>;
|
|
25
25
|
/**
|
|
26
26
|
* Plugin container for createI18nContext.
|
|
27
27
|
* Constrains TRules against React's own extended Rules (not the simplified
|
|
@@ -50,32 +50,33 @@ type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
54
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
53
|
+
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false> = {
|
|
54
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
55
55
|
currentLocale?: TSupportedLocales[number];
|
|
56
|
+
fallbackUI?: React.ReactNode;
|
|
56
57
|
children: React.ReactNode | ((currentLocale?: TSupportedLocales[number]) => React.ReactNode);
|
|
57
58
|
};
|
|
58
59
|
|
|
59
|
-
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>): {
|
|
60
|
+
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>): {
|
|
60
61
|
locale: TSupportedLocales[number] | undefined;
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
64
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
65
|
-
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
64
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false> {
|
|
65
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
66
|
+
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
66
67
|
fallbackUI?: React.ReactNode;
|
|
67
68
|
children: React.ReactNode | ((currentLocale?: TSupportedLocales[number]) => React.ReactNode);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
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>): {
|
|
71
|
+
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>, plugins?: Plugins<TRules>): {
|
|
71
72
|
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
72
73
|
currentLocale?: string;
|
|
73
74
|
children?: React.ReactNode;
|
|
74
75
|
}) => react_jsx_runtime.JSX.Element;
|
|
75
|
-
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
76
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
76
77
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
77
78
|
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
78
|
-
getLocaleStorageManager: (storageService?: IStorageService<string>) => _sheet_i18n_shared_service.LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
79
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => _sheet_i18n_shared_service.LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
79
80
|
useLocaleStorage: typeof useLocaleStorage;
|
|
80
81
|
};
|
|
81
82
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _sheet_i18n_shared_service from '@sheet-i18n/shared-service';
|
|
2
2
|
import { LocaleStorageManager, IStorageService } from '@sheet-i18n/shared-service';
|
|
3
3
|
export { LocaleStorageManager, IStorageService as Storage, ruleFactory } from '@sheet-i18n/shared-service';
|
|
4
|
+
import { SupportedLocales, LocaleSet, DynamicLoaderMap, TypeSafe, SafeSheetTitle, SafeMessageId } from '@sheet-i18n/typescript';
|
|
4
5
|
import { I18nStore } from '@sheet-i18n/core';
|
|
5
6
|
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
6
|
-
import { SupportedLocales, LocaleSet, TypeSafe, SafeSheetTitle, SafeMessageId } from '@sheet-i18n/typescript';
|
|
7
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
8
|
|
|
9
9
|
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
@@ -15,13 +15,13 @@ type RuleKey = string;
|
|
|
15
15
|
* Used internally by RuleService / ruleFactory so that createRule infers the
|
|
16
16
|
* correct value and message-id types from the store's locale data.
|
|
17
17
|
*/
|
|
18
|
-
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;
|
|
18
|
+
type RuleFn<TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales>, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, 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;
|
|
19
19
|
/**
|
|
20
20
|
* Extended rules map with full generic chain.
|
|
21
21
|
* Consumers can annotate their rules objects with the simpler `Rules` from
|
|
22
22
|
* @sheet-i18n/typescript; this extended version is used for inference only.
|
|
23
23
|
*/
|
|
24
|
-
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>>;
|
|
24
|
+
type Rules<TSupportedLocales extends SupportedLocales = SupportedLocales, TLocaleSet extends LocaleSet = LocaleSet, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends TypeSafe = TypeSafe, TI18nStore extends I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe> = I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, 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, TDynamicLoaders, TI18nStore, TTypeSafe, TSheetTitle, TMessageId>>;
|
|
25
25
|
/**
|
|
26
26
|
* Plugin container for createI18nContext.
|
|
27
27
|
* Constrains TRules against React's own extended Rules (not the simplified
|
|
@@ -50,32 +50,33 @@ type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
54
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
53
|
+
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false> = {
|
|
54
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
55
55
|
currentLocale?: TSupportedLocales[number];
|
|
56
|
+
fallbackUI?: React.ReactNode;
|
|
56
57
|
children: React.ReactNode | ((currentLocale?: TSupportedLocales[number]) => React.ReactNode);
|
|
57
58
|
};
|
|
58
59
|
|
|
59
|
-
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>): {
|
|
60
|
+
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>): {
|
|
60
61
|
locale: TSupportedLocales[number] | undefined;
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
64
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
65
|
-
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
64
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales> = DynamicLoaderMap<TSupportedLocales>, TTypeSafe extends boolean = false> {
|
|
65
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
66
|
+
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
66
67
|
fallbackUI?: React.ReactNode;
|
|
67
68
|
children: React.ReactNode | ((currentLocale?: TSupportedLocales[number]) => React.ReactNode);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
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>): {
|
|
71
|
+
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TDynamicLoaders extends DynamicLoaderMap<TSupportedLocales>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>, plugins?: Plugins<TRules>): {
|
|
71
72
|
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
72
73
|
currentLocale?: string;
|
|
73
74
|
children?: React.ReactNode;
|
|
74
75
|
}) => react_jsx_runtime.JSX.Element;
|
|
75
|
-
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
76
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
76
77
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
77
78
|
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
78
|
-
getLocaleStorageManager: (storageService?: IStorageService<string>) => _sheet_i18n_shared_service.LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
79
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => _sheet_i18n_shared_service.LocaleStorageManager<TSupportedLocales, TLocaleSet, TDynamicLoaders, TTypeSafe>;
|
|
79
80
|
useLocaleStorage: typeof useLocaleStorage;
|
|
80
81
|
};
|
|
81
82
|
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ __export(src_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(src_exports);
|
|
45
45
|
|
|
46
46
|
// src/createI18nContext.tsx
|
|
47
|
-
var
|
|
47
|
+
var import_shared_utils4 = require("@sheet-i18n/shared-utils");
|
|
48
48
|
var import_core = require("@sheet-i18n/core");
|
|
49
49
|
var import_shared_service2 = require("@sheet-i18n/shared-service");
|
|
50
50
|
|
|
@@ -151,6 +151,25 @@ ${err}`);
|
|
|
151
151
|
setIsLoading(false);
|
|
152
152
|
});
|
|
153
153
|
}, [currentLocale]);
|
|
154
|
+
(0, import_react.useEffect)(() => {
|
|
155
|
+
const currentLocaleSet = i18nStore == null ? void 0 : i18nStore.localeSet;
|
|
156
|
+
const dynamicLoaders = i18nStore == null ? void 0 : i18nStore.dynamicLoaders;
|
|
157
|
+
const preload = i18nStore == null ? void 0 : i18nStore.preload;
|
|
158
|
+
if (!dynamicLoaders || !preload) return;
|
|
159
|
+
preload.forEach((locale) => {
|
|
160
|
+
if (locale === currentLocale) return;
|
|
161
|
+
const isDataLoaded = Boolean(currentLocaleSet == null ? void 0 : currentLocaleSet[locale]);
|
|
162
|
+
if (isDataLoaded) return;
|
|
163
|
+
const dynamicLoader = dynamicLoaders[locale];
|
|
164
|
+
if (!dynamicLoader) return;
|
|
165
|
+
dynamicLoader().then((res) => {
|
|
166
|
+
const { default: localeData } = res;
|
|
167
|
+
i18nStore == null ? void 0 : i18nStore.mergeLocaleSet(locale, localeData);
|
|
168
|
+
intlInstanceCache.resetTotalCache();
|
|
169
|
+
}).catch(() => {
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}, []);
|
|
154
173
|
return {
|
|
155
174
|
isLoading
|
|
156
175
|
};
|
|
@@ -161,8 +180,10 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
161
180
|
function IntlProvider({
|
|
162
181
|
i18nStore,
|
|
163
182
|
currentLocale,
|
|
183
|
+
fallbackUI = null,
|
|
164
184
|
children: childrenFromProps
|
|
165
185
|
}) {
|
|
186
|
+
var _a;
|
|
166
187
|
const { locale } = useIntlLocale({ i18nStore, currentLocale });
|
|
167
188
|
const onIntlError = (err) => {
|
|
168
189
|
const typeSafe = i18nStore.typeSafe;
|
|
@@ -171,14 +192,16 @@ function IntlProvider({
|
|
|
171
192
|
}
|
|
172
193
|
};
|
|
173
194
|
const { isLoading } = useDynamicLocale({ i18nStore });
|
|
174
|
-
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
195
|
+
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
196
|
+
(_a = locale != null ? locale : i18nStore.currentLocale) != null ? _a : i18nStore.defaultLocale
|
|
197
|
+
) : childrenFromProps;
|
|
175
198
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
176
199
|
import_react_intl2.IntlProvider,
|
|
177
200
|
{
|
|
178
201
|
locale,
|
|
179
202
|
messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
|
|
180
203
|
onError: onIntlError,
|
|
181
|
-
children: !isLoading
|
|
204
|
+
children: !isLoading ? children : fallbackUI != null ? fallbackUI : children
|
|
182
205
|
},
|
|
183
206
|
`sheet-i18n-locale-${locale}`
|
|
184
207
|
);
|
|
@@ -360,7 +383,6 @@ function useLocaleStorage(localeStorageManager) {
|
|
|
360
383
|
}
|
|
361
384
|
|
|
362
385
|
// src/Provider/StorageBasedIntlProvider.tsx
|
|
363
|
-
var import_shared_utils4 = require("@sheet-i18n/shared-utils");
|
|
364
386
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
365
387
|
function StorageBasedIntlProvider({
|
|
366
388
|
i18nStore,
|
|
@@ -368,18 +390,26 @@ function StorageBasedIntlProvider({
|
|
|
368
390
|
fallbackUI = null,
|
|
369
391
|
children: childrenFromProps
|
|
370
392
|
}) {
|
|
393
|
+
var _a;
|
|
371
394
|
const { locale } = useLocaleStorage(storageManager);
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
395
|
+
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
396
|
+
(_a = locale != null ? locale : i18nStore.currentLocale) != null ? _a : i18nStore.defaultLocale
|
|
397
|
+
) : childrenFromProps;
|
|
398
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
399
|
+
IntlProvider,
|
|
400
|
+
{
|
|
401
|
+
currentLocale: locale,
|
|
402
|
+
fallbackUI,
|
|
403
|
+
i18nStore,
|
|
404
|
+
children
|
|
405
|
+
}
|
|
406
|
+
);
|
|
377
407
|
}
|
|
378
408
|
|
|
379
409
|
// src/createI18nContext.tsx
|
|
380
410
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
381
411
|
function createI18nContext(i18nStore, plugins) {
|
|
382
|
-
if (
|
|
412
|
+
if (import_shared_utils4.validator.isNullish(i18nStore)) {
|
|
383
413
|
throw new import_shared_service2.InvalidI18nContextStateError(
|
|
384
414
|
"\u26A0\uFE0F no i18nStore provided. To use createI18nContext, you must provide an i18nStore as a parameter"
|
|
385
415
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
21
|
// src/createI18nContext.tsx
|
|
22
|
-
import { validator as
|
|
22
|
+
import { validator as validator4 } from "@sheet-i18n/shared-utils";
|
|
23
23
|
import { I18nStore } from "@sheet-i18n/core";
|
|
24
24
|
import {
|
|
25
25
|
InvalidI18nContextStateError,
|
|
@@ -29,11 +29,11 @@ import {
|
|
|
29
29
|
|
|
30
30
|
// src/Provider/IntlProvider.tsx
|
|
31
31
|
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
|
32
|
-
import { useEffect } from "react";
|
|
32
|
+
import { useEffect as useEffect2 } from "react";
|
|
33
33
|
|
|
34
34
|
// src/hooks/useDynamicLocale.ts
|
|
35
35
|
import { validator as validator2 } from "@sheet-i18n/shared-utils";
|
|
36
|
-
import { useLayoutEffect, useState } from "react";
|
|
36
|
+
import { useEffect, useLayoutEffect, useState } from "react";
|
|
37
37
|
|
|
38
38
|
// src/Service/IntlInstanceCache.ts
|
|
39
39
|
import { createIntl, createIntlCache, useIntl } from "react-intl";
|
|
@@ -130,6 +130,25 @@ ${err}`);
|
|
|
130
130
|
setIsLoading(false);
|
|
131
131
|
});
|
|
132
132
|
}, [currentLocale]);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
const currentLocaleSet = i18nStore == null ? void 0 : i18nStore.localeSet;
|
|
135
|
+
const dynamicLoaders = i18nStore == null ? void 0 : i18nStore.dynamicLoaders;
|
|
136
|
+
const preload = i18nStore == null ? void 0 : i18nStore.preload;
|
|
137
|
+
if (!dynamicLoaders || !preload) return;
|
|
138
|
+
preload.forEach((locale) => {
|
|
139
|
+
if (locale === currentLocale) return;
|
|
140
|
+
const isDataLoaded = Boolean(currentLocaleSet == null ? void 0 : currentLocaleSet[locale]);
|
|
141
|
+
if (isDataLoaded) return;
|
|
142
|
+
const dynamicLoader = dynamicLoaders[locale];
|
|
143
|
+
if (!dynamicLoader) return;
|
|
144
|
+
dynamicLoader().then((res) => {
|
|
145
|
+
const { default: localeData } = res;
|
|
146
|
+
i18nStore == null ? void 0 : i18nStore.mergeLocaleSet(locale, localeData);
|
|
147
|
+
intlInstanceCache.resetTotalCache();
|
|
148
|
+
}).catch(() => {
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}, []);
|
|
133
152
|
return {
|
|
134
153
|
isLoading
|
|
135
154
|
};
|
|
@@ -140,8 +159,10 @@ import { jsx } from "react/jsx-runtime";
|
|
|
140
159
|
function IntlProvider({
|
|
141
160
|
i18nStore,
|
|
142
161
|
currentLocale,
|
|
162
|
+
fallbackUI = null,
|
|
143
163
|
children: childrenFromProps
|
|
144
164
|
}) {
|
|
165
|
+
var _a;
|
|
145
166
|
const { locale } = useIntlLocale({ i18nStore, currentLocale });
|
|
146
167
|
const onIntlError = (err) => {
|
|
147
168
|
const typeSafe = i18nStore.typeSafe;
|
|
@@ -150,14 +171,16 @@ function IntlProvider({
|
|
|
150
171
|
}
|
|
151
172
|
};
|
|
152
173
|
const { isLoading } = useDynamicLocale({ i18nStore });
|
|
153
|
-
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
174
|
+
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
175
|
+
(_a = locale != null ? locale : i18nStore.currentLocale) != null ? _a : i18nStore.defaultLocale
|
|
176
|
+
) : childrenFromProps;
|
|
154
177
|
return /* @__PURE__ */ jsx(
|
|
155
178
|
ReactIntlProvider,
|
|
156
179
|
{
|
|
157
180
|
locale,
|
|
158
181
|
messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
|
|
159
182
|
onError: onIntlError,
|
|
160
|
-
children: !isLoading
|
|
183
|
+
children: !isLoading ? children : fallbackUI != null ? fallbackUI : children
|
|
161
184
|
},
|
|
162
185
|
`sheet-i18n-locale-${locale}`
|
|
163
186
|
);
|
|
@@ -168,7 +191,7 @@ function useIntlLocale({
|
|
|
168
191
|
}) {
|
|
169
192
|
const locale = currentLocale || detectClientLanguage(i18nStore) || i18nStore.defaultLocale;
|
|
170
193
|
i18nStore.setCurrentLocale(locale);
|
|
171
|
-
|
|
194
|
+
useEffect2(() => {
|
|
172
195
|
i18nStore.setCurrentLocale(locale);
|
|
173
196
|
}, [locale]);
|
|
174
197
|
return {
|
|
@@ -314,15 +337,15 @@ function getTranslation({
|
|
|
314
337
|
}
|
|
315
338
|
|
|
316
339
|
// src/hooks/useLocaleStorage.ts
|
|
317
|
-
import { useEffect as
|
|
340
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
318
341
|
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
319
342
|
function useLocaleStorage(localeStorageManager) {
|
|
320
343
|
const [locale, setLocale] = useState2();
|
|
321
|
-
|
|
344
|
+
useEffect3(() => {
|
|
322
345
|
const storedLocale = localeStorageManager.currentLocale;
|
|
323
346
|
setLocale(storedLocale);
|
|
324
347
|
}, []);
|
|
325
|
-
|
|
348
|
+
useEffect3(() => {
|
|
326
349
|
var _a;
|
|
327
350
|
(_a = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a.addListener({
|
|
328
351
|
listenerId: LISTENER_ID,
|
|
@@ -339,7 +362,6 @@ function useLocaleStorage(localeStorageManager) {
|
|
|
339
362
|
}
|
|
340
363
|
|
|
341
364
|
// src/Provider/StorageBasedIntlProvider.tsx
|
|
342
|
-
import { validator as validator4 } from "@sheet-i18n/shared-utils";
|
|
343
365
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
344
366
|
function StorageBasedIntlProvider({
|
|
345
367
|
i18nStore,
|
|
@@ -347,18 +369,26 @@ function StorageBasedIntlProvider({
|
|
|
347
369
|
fallbackUI = null,
|
|
348
370
|
children: childrenFromProps
|
|
349
371
|
}) {
|
|
372
|
+
var _a;
|
|
350
373
|
const { locale } = useLocaleStorage(storageManager);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
374
|
+
const children = typeof childrenFromProps === "function" ? childrenFromProps(
|
|
375
|
+
(_a = locale != null ? locale : i18nStore.currentLocale) != null ? _a : i18nStore.defaultLocale
|
|
376
|
+
) : childrenFromProps;
|
|
377
|
+
return /* @__PURE__ */ jsx2(
|
|
378
|
+
IntlProvider,
|
|
379
|
+
{
|
|
380
|
+
currentLocale: locale,
|
|
381
|
+
fallbackUI,
|
|
382
|
+
i18nStore,
|
|
383
|
+
children
|
|
384
|
+
}
|
|
385
|
+
);
|
|
356
386
|
}
|
|
357
387
|
|
|
358
388
|
// src/createI18nContext.tsx
|
|
359
389
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
360
390
|
function createI18nContext(i18nStore, plugins) {
|
|
361
|
-
if (
|
|
391
|
+
if (validator4.isNullish(i18nStore)) {
|
|
362
392
|
throw new InvalidI18nContextStateError(
|
|
363
393
|
"\u26A0\uFE0F no i18nStore provided. To use createI18nContext, you must provide an i18nStore as a parameter"
|
|
364
394
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheet-i18n/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.9",
|
|
4
4
|
"description": "i18n client logic based on react",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -33,15 +33,16 @@
|
|
|
33
33
|
"@types/react": "^19.0.2",
|
|
34
34
|
"@types/react-dom": "^19.0.2",
|
|
35
35
|
"react": "^19.0.0",
|
|
36
|
-
"@sheet-i18n/typescript-config": "1.8.
|
|
36
|
+
"@sheet-i18n/typescript-config": "1.8.6",
|
|
37
|
+
"@sheet-i18n/typescript": "0.4.4"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"react-intl": "^7.0.4",
|
|
40
|
-
"@sheet-i18n/core": "1.7.
|
|
41
|
-
"@sheet-i18n/
|
|
42
|
-
"@sheet-i18n/
|
|
43
|
-
"@sheet-i18n/
|
|
44
|
-
"@sheet-i18n/
|
|
41
|
+
"@sheet-i18n/core": "1.7.4",
|
|
42
|
+
"@sheet-i18n/errors": "1.8.6",
|
|
43
|
+
"@sheet-i18n/shared-utils": "1.8.7",
|
|
44
|
+
"@sheet-i18n/shared-service": "0.2.4",
|
|
45
|
+
"@sheet-i18n/typescript": "0.4.4"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"react": "^18 || ^19 || ^20 || ^21",
|