@sheet-i18n/react-client 1.5.0-canary.0 → 1.5.0-canary.10

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 CHANGED
@@ -1,7 +1,32 @@
1
- import { MessageDescriptor, IntlShape } from 'react-intl';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
3
1
  import { I18nStore } from '@sheet-i18n/react-core';
4
2
  import { ObserverManager } from '@sheet-i18n/shared-utils';
3
+ import { MessageDescriptor, IntlShape } from 'react-intl';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
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;
11
+ }
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;
19
+ }
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;
29
+ }
5
30
 
6
31
  type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
7
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>;
@@ -40,42 +65,26 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
40
65
  children: React.ReactNode;
41
66
  };
42
67
 
43
- interface IStorageService<V extends string> {
44
- getItem(key: string): V;
45
- setItem(key: string, value: V): boolean;
46
- removeItem(key: string): boolean;
47
- clear(): boolean;
48
- }
49
- /**
50
- * locale storage manager
51
- * implements ILocaleStorageManager (injected StorageService)
52
- */
53
- interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
54
- getLocale(): TSupportedLocales[number];
55
- setLocale(locale: TSupportedLocales[number]): void;
56
- }
57
- declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
58
- private readonly storageService;
59
- private readonly i18nStore;
60
- private readonly localeStorageKey;
61
- observerManager: ObserverManager<TSupportedLocales[number]>;
62
- constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
63
- private initializeCurrentLocale;
64
- getLocale: () => TSupportedLocales[number];
65
- setLocale: (locale: TSupportedLocales[number]) => void;
66
- }
68
+ 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>): {
69
+ locale: TSupportedLocales[number];
70
+ };
67
71
 
68
- 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>): TSupportedLocales[number];
72
+ interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
73
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
74
+ storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
75
+ children: React.ReactNode;
76
+ }
69
77
 
70
78
  declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>): {
71
79
  IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
72
80
  currentLocale?: string;
73
81
  children?: React.ReactNode;
74
82
  }) => react_jsx_runtime.JSX.Element;
83
+ StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
75
84
  useTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
76
85
  getTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
77
- getLocaleStorageManager: (storage?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
86
+ getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
78
87
  useLocaleStorage: typeof useLocaleStorage;
79
88
  };
80
89
 
81
- export { createI18nContext };
90
+ export { type IStorageService, createI18nContext };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,32 @@
1
- import { MessageDescriptor, IntlShape } from 'react-intl';
2
- import * as react_jsx_runtime from 'react/jsx-runtime';
3
1
  import { I18nStore } from '@sheet-i18n/react-core';
4
2
  import { ObserverManager } from '@sheet-i18n/shared-utils';
3
+ import { MessageDescriptor, IntlShape } from 'react-intl';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
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;
11
+ }
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;
19
+ }
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;
29
+ }
5
30
 
6
31
  type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
7
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>;
@@ -40,42 +65,26 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
40
65
  children: React.ReactNode;
41
66
  };
42
67
 
43
- interface IStorageService<V extends string> {
44
- getItem(key: string): V;
45
- setItem(key: string, value: V): boolean;
46
- removeItem(key: string): boolean;
47
- clear(): boolean;
48
- }
49
- /**
50
- * locale storage manager
51
- * implements ILocaleStorageManager (injected StorageService)
52
- */
53
- interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
54
- getLocale(): TSupportedLocales[number];
55
- setLocale(locale: TSupportedLocales[number]): void;
56
- }
57
- declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
58
- private readonly storageService;
59
- private readonly i18nStore;
60
- private readonly localeStorageKey;
61
- observerManager: ObserverManager<TSupportedLocales[number]>;
62
- constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
63
- private initializeCurrentLocale;
64
- getLocale: () => TSupportedLocales[number];
65
- setLocale: (locale: TSupportedLocales[number]) => void;
66
- }
68
+ 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>): {
69
+ locale: TSupportedLocales[number];
70
+ };
67
71
 
68
- 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>): TSupportedLocales[number];
72
+ interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
73
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
74
+ storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
75
+ children: React.ReactNode;
76
+ }
69
77
 
70
78
  declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>): {
71
79
  IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
72
80
  currentLocale?: string;
73
81
  children?: React.ReactNode;
74
82
  }) => react_jsx_runtime.JSX.Element;
83
+ StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
75
84
  useTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
76
85
  getTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
77
- getLocaleStorageManager: (storage?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
86
+ getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
78
87
  useLocaleStorage: typeof useLocaleStorage;
79
88
  };
80
89
 
81
- export { createI18nContext };
90
+ export { type IStorageService, createI18nContext };
package/dist/index.js CHANGED
@@ -46,11 +46,11 @@ module.exports = __toCommonJS(src_exports);
46
46
  var import_shared_utils5 = require("@sheet-i18n/shared-utils");
47
47
  var import_react_core = require("@sheet-i18n/react-core");
48
48
 
49
- // src/IntlProvider.tsx
49
+ // src/Provider/IntlProvider.tsx
50
50
  var import_react_intl2 = require("react-intl");
51
51
  var import_react2 = require("react");
52
52
 
53
- // src/useDynamicLocale.ts
53
+ // src/hooks/useDynamicLocale.ts
54
54
  var import_shared_utils2 = require("@sheet-i18n/shared-utils");
55
55
  var import_react = require("react");
56
56
 
@@ -122,7 +122,7 @@ var IntlInstanceCache = class _IntlInstanceCache {
122
122
  };
123
123
  var intlInstanceCache = IntlInstanceCache.init();
124
124
 
125
- // src/useDynamicLocale.ts
125
+ // src/hooks/useDynamicLocale.ts
126
126
  function useDynamicLocale(useDynamicLocaleProps) {
127
127
  const { i18nStore } = useDynamicLocaleProps != null ? useDynamicLocaleProps : {};
128
128
  const currentLocale = i18nStore == null ? void 0 : i18nStore.getCurrentLocale();
@@ -154,7 +154,7 @@ ${err}`);
154
154
  };
155
155
  }
156
156
 
157
- // src/IntlProvider.tsx
157
+ // src/Provider/IntlProvider.tsx
158
158
  var import_jsx_runtime = require("react/jsx-runtime");
159
159
  function IntlProvider({
160
160
  i18nStore,
@@ -176,7 +176,8 @@ function IntlProvider({
176
176
  messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
177
177
  onError: onIntlError,
178
178
  children: !isLoading && children
179
- }
179
+ },
180
+ `sheet-i18n-locale-${locale}`
180
181
  );
181
182
  }
182
183
  function useIntlLocale({
@@ -247,7 +248,7 @@ var TranslationService = class {
247
248
  }
248
249
  };
249
250
 
250
- // src/useTranslation.ts
251
+ // src/hooks/useTranslation.ts
251
252
  function useTranslation({
252
253
  sheetTitle,
253
254
  i18nStore
@@ -274,7 +275,7 @@ var InvalidI18nContextStateError = class extends import_errors.CustomError {
274
275
  var IsNotInstanceOfI18nStoreError = class extends import_errors.CustomError {
275
276
  };
276
277
 
277
- // src/getTranslation.ts
278
+ // src/hooks/getTranslation.ts
278
279
  function getTranslation({
279
280
  sheetTitle,
280
281
  i18nStore
@@ -318,9 +319,9 @@ function getTranslation({
318
319
  return { t };
319
320
  }
320
321
 
321
- // src/Service/LocalStorageService.ts
322
+ // src/Service/StorageService.ts
322
323
  var import_shared_utils4 = require("@sheet-i18n/shared-utils");
323
- var LocalStorageService = class {
324
+ var StorageService = class {
324
325
  constructor(storage) {
325
326
  this.storage = null;
326
327
  this.isClientSide = typeof window !== "undefined";
@@ -418,11 +419,10 @@ var LocaleStorageManager = class {
418
419
  this.observerManager = new import_shared_utils4.ObserverManager();
419
420
  this.initializeCurrentLocale = () => {
420
421
  var _a, _b;
421
- if (this.storageService && this.i18nStore.currentLocale) {
422
- this.storageService.setItem(
423
- this.localeStorageKey,
424
- this.i18nStore.currentLocale
425
- );
422
+ const storedLocale = this.storageService.getItem(this.localeStorageKey);
423
+ if (!storedLocale || storedLocale === "") {
424
+ const defaultLocale = this.i18nStore.currentLocale || this.i18nStore.defaultLocale;
425
+ this.storageService.setItem(this.localeStorageKey, defaultLocale);
426
426
  }
427
427
  (_b = (_a = this.i18nStore) == null ? void 0 : _a.observerManager) == null ? void 0 : _b.addListener({
428
428
  listenerId: this.localeStorageKey,
@@ -433,7 +433,10 @@ var LocaleStorageManager = class {
433
433
  };
434
434
  this.getLocale = () => {
435
435
  const stored = this.storageService.getItem(this.localeStorageKey);
436
- return stored != null ? stored : "";
436
+ if (!stored || stored === "") {
437
+ return this.i18nStore.defaultLocale;
438
+ }
439
+ return stored;
437
440
  };
438
441
  this.setLocale = (locale) => {
439
442
  this.storageService.setItem(this.localeStorageKey, locale);
@@ -442,8 +445,16 @@ var LocaleStorageManager = class {
442
445
  this.initializeCurrentLocale();
443
446
  }
444
447
  };
448
+ var getLocaleStorageManager = (i18nStore, storage) => {
449
+ const localeStorageService = new StorageService(storage);
450
+ const localeStorageManager = new LocaleStorageManager(
451
+ localeStorageService,
452
+ i18nStore
453
+ );
454
+ return localeStorageManager;
455
+ };
445
456
 
446
- // src/useLocaleStorage.ts
457
+ // src/hooks/useLocaleStorage.ts
447
458
  var import_react3 = require("react");
448
459
  var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
449
460
  function useLocaleStorage(localeStorageManager) {
@@ -462,11 +473,22 @@ function useLocaleStorage(localeStorageManager) {
462
473
  (_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
463
474
  };
464
475
  }, []);
465
- return locale;
476
+ return { locale };
466
477
  }
467
478
 
468
- // src/createI18nContext.tsx
479
+ // src/Provider/StorageBasedIntlProvider.tsx
469
480
  var import_jsx_runtime2 = require("react/jsx-runtime");
481
+ function StorageBasedIntlProvider({
482
+ i18nStore,
483
+ storageManager,
484
+ children
485
+ }) {
486
+ const { locale } = useLocaleStorage(storageManager);
487
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IntlProvider, { currentLocale: locale, i18nStore, children });
488
+ }
489
+
490
+ // src/createI18nContext.tsx
491
+ var import_jsx_runtime3 = require("react/jsx-runtime");
470
492
  function createI18nContext(i18nStore) {
471
493
  if (import_shared_utils5.validator.isNullish(i18nStore)) {
472
494
  throw new InvalidI18nContextStateError(
@@ -481,7 +503,7 @@ function createI18nContext(i18nStore) {
481
503
  const IntlProviderImpl = ({
482
504
  currentLocale,
483
505
  children
484
- }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
506
+ }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
485
507
  IntlProvider,
486
508
  {
487
509
  currentLocale,
@@ -489,21 +511,28 @@ function createI18nContext(i18nStore) {
489
511
  children
490
512
  }
491
513
  );
514
+ const StorageBasedIntlProviderImpl = ({
515
+ storageManager,
516
+ children
517
+ }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
518
+ StorageBasedIntlProvider,
519
+ {
520
+ i18nStore,
521
+ storageManager,
522
+ children
523
+ }
524
+ );
492
525
  const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
493
526
  const getTranslationImpl = (sheetTitle) => getTranslation({ sheetTitle, i18nStore });
494
- const getLocaleStorageManager = (storage) => {
495
- const localStorageService = new LocalStorageService(storage);
496
- const localeStorageManager = new LocaleStorageManager(
497
- localStorageService,
498
- i18nStore
499
- );
500
- return localeStorageManager;
527
+ const getLocaleStorageManagerImpl = (storageService) => {
528
+ return getLocaleStorageManager(i18nStore, storageService);
501
529
  };
502
530
  return {
503
531
  IntlProvider: IntlProviderImpl,
532
+ StorageBasedIntlProvider: StorageBasedIntlProviderImpl,
504
533
  useTranslation: useTranslationImpl,
505
534
  getTranslation: getTranslationImpl,
506
- getLocaleStorageManager,
535
+ getLocaleStorageManager: getLocaleStorageManagerImpl,
507
536
  useLocaleStorage
508
537
  };
509
538
  }
package/dist/index.mjs CHANGED
@@ -23,11 +23,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
23
  import { validator as validator4 } from "@sheet-i18n/shared-utils";
24
24
  import { I18nStore } from "@sheet-i18n/react-core";
25
25
 
26
- // src/IntlProvider.tsx
26
+ // src/Provider/IntlProvider.tsx
27
27
  import { IntlProvider as ReactIntlProvider } from "react-intl";
28
28
  import { useEffect } from "react";
29
29
 
30
- // src/useDynamicLocale.ts
30
+ // src/hooks/useDynamicLocale.ts
31
31
  import { validator as validator2 } from "@sheet-i18n/shared-utils";
32
32
  import { useLayoutEffect, useState } from "react";
33
33
 
@@ -99,7 +99,7 @@ var IntlInstanceCache = class _IntlInstanceCache {
99
99
  };
100
100
  var intlInstanceCache = IntlInstanceCache.init();
101
101
 
102
- // src/useDynamicLocale.ts
102
+ // src/hooks/useDynamicLocale.ts
103
103
  function useDynamicLocale(useDynamicLocaleProps) {
104
104
  const { i18nStore } = useDynamicLocaleProps != null ? useDynamicLocaleProps : {};
105
105
  const currentLocale = i18nStore == null ? void 0 : i18nStore.getCurrentLocale();
@@ -131,7 +131,7 @@ ${err}`);
131
131
  };
132
132
  }
133
133
 
134
- // src/IntlProvider.tsx
134
+ // src/Provider/IntlProvider.tsx
135
135
  import { jsx } from "react/jsx-runtime";
136
136
  function IntlProvider({
137
137
  i18nStore,
@@ -153,7 +153,8 @@ function IntlProvider({
153
153
  messages: i18nStore == null ? void 0 : i18nStore.localeSet[locale],
154
154
  onError: onIntlError,
155
155
  children: !isLoading && children
156
- }
156
+ },
157
+ `sheet-i18n-locale-${locale}`
157
158
  );
158
159
  }
159
160
  function useIntlLocale({
@@ -224,7 +225,7 @@ var TranslationService = class {
224
225
  }
225
226
  };
226
227
 
227
- // src/useTranslation.ts
228
+ // src/hooks/useTranslation.ts
228
229
  function useTranslation({
229
230
  sheetTitle,
230
231
  i18nStore
@@ -251,7 +252,7 @@ var InvalidI18nContextStateError = class extends CustomError {
251
252
  var IsNotInstanceOfI18nStoreError = class extends CustomError {
252
253
  };
253
254
 
254
- // src/getTranslation.ts
255
+ // src/hooks/getTranslation.ts
255
256
  function getTranslation({
256
257
  sheetTitle,
257
258
  i18nStore
@@ -295,9 +296,9 @@ function getTranslation({
295
296
  return { t };
296
297
  }
297
298
 
298
- // src/Service/LocalStorageService.ts
299
+ // src/Service/StorageService.ts
299
300
  import { ObserverManager } from "@sheet-i18n/shared-utils";
300
- var LocalStorageService = class {
301
+ var StorageService = class {
301
302
  constructor(storage) {
302
303
  this.storage = null;
303
304
  this.isClientSide = typeof window !== "undefined";
@@ -395,11 +396,10 @@ var LocaleStorageManager = class {
395
396
  this.observerManager = new ObserverManager();
396
397
  this.initializeCurrentLocale = () => {
397
398
  var _a, _b;
398
- if (this.storageService && this.i18nStore.currentLocale) {
399
- this.storageService.setItem(
400
- this.localeStorageKey,
401
- this.i18nStore.currentLocale
402
- );
399
+ const storedLocale = this.storageService.getItem(this.localeStorageKey);
400
+ if (!storedLocale || storedLocale === "") {
401
+ const defaultLocale = this.i18nStore.currentLocale || this.i18nStore.defaultLocale;
402
+ this.storageService.setItem(this.localeStorageKey, defaultLocale);
403
403
  }
404
404
  (_b = (_a = this.i18nStore) == null ? void 0 : _a.observerManager) == null ? void 0 : _b.addListener({
405
405
  listenerId: this.localeStorageKey,
@@ -410,7 +410,10 @@ var LocaleStorageManager = class {
410
410
  };
411
411
  this.getLocale = () => {
412
412
  const stored = this.storageService.getItem(this.localeStorageKey);
413
- return stored != null ? stored : "";
413
+ if (!stored || stored === "") {
414
+ return this.i18nStore.defaultLocale;
415
+ }
416
+ return stored;
414
417
  };
415
418
  this.setLocale = (locale) => {
416
419
  this.storageService.setItem(this.localeStorageKey, locale);
@@ -419,8 +422,16 @@ var LocaleStorageManager = class {
419
422
  this.initializeCurrentLocale();
420
423
  }
421
424
  };
425
+ var getLocaleStorageManager = (i18nStore, storage) => {
426
+ const localeStorageService = new StorageService(storage);
427
+ const localeStorageManager = new LocaleStorageManager(
428
+ localeStorageService,
429
+ i18nStore
430
+ );
431
+ return localeStorageManager;
432
+ };
422
433
 
423
- // src/useLocaleStorage.ts
434
+ // src/hooks/useLocaleStorage.ts
424
435
  import { useEffect as useEffect2, useState as useState2 } from "react";
425
436
  var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
426
437
  function useLocaleStorage(localeStorageManager) {
@@ -439,11 +450,22 @@ function useLocaleStorage(localeStorageManager) {
439
450
  (_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
440
451
  };
441
452
  }, []);
442
- return locale;
453
+ return { locale };
443
454
  }
444
455
 
445
- // src/createI18nContext.tsx
456
+ // src/Provider/StorageBasedIntlProvider.tsx
446
457
  import { jsx as jsx2 } from "react/jsx-runtime";
458
+ function StorageBasedIntlProvider({
459
+ i18nStore,
460
+ storageManager,
461
+ children
462
+ }) {
463
+ const { locale } = useLocaleStorage(storageManager);
464
+ return /* @__PURE__ */ jsx2(IntlProvider, { currentLocale: locale, i18nStore, children });
465
+ }
466
+
467
+ // src/createI18nContext.tsx
468
+ import { jsx as jsx3 } from "react/jsx-runtime";
447
469
  function createI18nContext(i18nStore) {
448
470
  if (validator4.isNullish(i18nStore)) {
449
471
  throw new InvalidI18nContextStateError(
@@ -458,7 +480,7 @@ function createI18nContext(i18nStore) {
458
480
  const IntlProviderImpl = ({
459
481
  currentLocale,
460
482
  children
461
- }) => /* @__PURE__ */ jsx2(
483
+ }) => /* @__PURE__ */ jsx3(
462
484
  IntlProvider,
463
485
  {
464
486
  currentLocale,
@@ -466,21 +488,28 @@ function createI18nContext(i18nStore) {
466
488
  children
467
489
  }
468
490
  );
491
+ const StorageBasedIntlProviderImpl = ({
492
+ storageManager,
493
+ children
494
+ }) => /* @__PURE__ */ jsx3(
495
+ StorageBasedIntlProvider,
496
+ {
497
+ i18nStore,
498
+ storageManager,
499
+ children
500
+ }
501
+ );
469
502
  const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
470
503
  const getTranslationImpl = (sheetTitle) => getTranslation({ sheetTitle, i18nStore });
471
- const getLocaleStorageManager = (storage) => {
472
- const localStorageService = new LocalStorageService(storage);
473
- const localeStorageManager = new LocaleStorageManager(
474
- localStorageService,
475
- i18nStore
476
- );
477
- return localeStorageManager;
504
+ const getLocaleStorageManagerImpl = (storageService) => {
505
+ return getLocaleStorageManager(i18nStore, storageService);
478
506
  };
479
507
  return {
480
508
  IntlProvider: IntlProviderImpl,
509
+ StorageBasedIntlProvider: StorageBasedIntlProviderImpl,
481
510
  useTranslation: useTranslationImpl,
482
511
  getTranslation: getTranslationImpl,
483
- getLocaleStorageManager,
512
+ getLocaleStorageManager: getLocaleStorageManagerImpl,
484
513
  useLocaleStorage
485
514
  };
486
515
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheet-i18n/react-client",
3
- "version": "1.5.0-canary.0",
3
+ "version": "1.5.0-canary.10",
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,16 +25,16 @@
25
25
  },
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "@sheet-i18n/shared-utils": "1.8.0-canary.0",
29
- "@sheet-i18n/errors": "1.8.0-canary.0",
30
- "@sheet-i18n/react-core": "1.5.0-canary.0"
28
+ "@sheet-i18n/shared-utils": "1.8.0-canary.4",
29
+ "@sheet-i18n/react-core": "1.5.0-canary.4",
30
+ "@sheet-i18n/errors": "1.8.0-canary.4"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^19.0.2",
34
34
  "@types/react-dom": "^19.0.2",
35
35
  "react": "^18.2.0",
36
36
  "react-intl": "^7.0.4",
37
- "@sheet-i18n/typescript-config": "1.8.0-canary.0"
37
+ "@sheet-i18n/typescript-config": "1.8.0-canary.4"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^18 || ^19 || ^20 || ^21",