@sheet-i18n/react-client 1.5.0-canary.1 → 1.5.0-canary.3

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
@@ -87,4 +87,4 @@ declare function createI18nContext<TSupportedLocales extends readonly string[],
87
87
  useLocaleStorage: typeof useLocaleStorage;
88
88
  };
89
89
 
90
- export { createI18nContext };
90
+ export { type IStorageService, createI18nContext };
package/dist/index.d.ts CHANGED
@@ -87,4 +87,4 @@ declare function createI18nContext<TSupportedLocales extends readonly string[],
87
87
  useLocaleStorage: typeof useLocaleStorage;
88
88
  };
89
89
 
90
- export { createI18nContext };
90
+ export { type IStorageService, createI18nContext };
package/dist/index.js CHANGED
@@ -418,11 +418,10 @@ var LocaleStorageManager = class {
418
418
  this.observerManager = new import_shared_utils4.ObserverManager();
419
419
  this.initializeCurrentLocale = () => {
420
420
  var _a, _b;
421
- if (this.storageService && this.i18nStore.currentLocale) {
422
- this.storageService.setItem(
423
- this.localeStorageKey,
424
- this.i18nStore.currentLocale
425
- );
421
+ const storedLocale = this.storageService.getItem(this.localeStorageKey);
422
+ if (!storedLocale || storedLocale === "") {
423
+ const defaultLocale = this.i18nStore.currentLocale || this.i18nStore.defaultLocale;
424
+ this.storageService.setItem(this.localeStorageKey, defaultLocale);
426
425
  }
427
426
  (_b = (_a = this.i18nStore) == null ? void 0 : _a.observerManager) == null ? void 0 : _b.addListener({
428
427
  listenerId: this.localeStorageKey,
@@ -433,7 +432,10 @@ var LocaleStorageManager = class {
433
432
  };
434
433
  this.getLocale = () => {
435
434
  const stored = this.storageService.getItem(this.localeStorageKey);
436
- return stored != null ? stored : "";
435
+ if (!stored || stored === "") {
436
+ return this.i18nStore.defaultLocale;
437
+ }
438
+ return stored;
437
439
  };
438
440
  this.setLocale = (locale) => {
439
441
  this.storageService.setItem(this.localeStorageKey, locale);
@@ -457,11 +459,13 @@ var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
457
459
  function useLocaleStorage(localeStorageManager) {
458
460
  var _a;
459
461
  const [locale, setLocale] = (0, import_react3.useState)((_a = localeStorageManager == null ? void 0 : localeStorageManager.getLocale) == null ? void 0 : _a.call(localeStorageManager));
462
+ console.log("\u2705 locale in useLocaleStorage", locale);
460
463
  (0, import_react3.useEffect)(() => {
461
464
  var _a2;
462
465
  (_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
463
466
  listenerId: LISTENER_ID,
464
467
  listener: (newLocale) => {
468
+ console.log("\u2705 did you update the locale?", newLocale);
465
469
  setLocale(newLocale);
466
470
  }
467
471
  });
package/dist/index.mjs CHANGED
@@ -395,11 +395,10 @@ var LocaleStorageManager = class {
395
395
  this.observerManager = new ObserverManager();
396
396
  this.initializeCurrentLocale = () => {
397
397
  var _a, _b;
398
- if (this.storageService && this.i18nStore.currentLocale) {
399
- this.storageService.setItem(
400
- this.localeStorageKey,
401
- this.i18nStore.currentLocale
402
- );
398
+ const storedLocale = this.storageService.getItem(this.localeStorageKey);
399
+ if (!storedLocale || storedLocale === "") {
400
+ const defaultLocale = this.i18nStore.currentLocale || this.i18nStore.defaultLocale;
401
+ this.storageService.setItem(this.localeStorageKey, defaultLocale);
403
402
  }
404
403
  (_b = (_a = this.i18nStore) == null ? void 0 : _a.observerManager) == null ? void 0 : _b.addListener({
405
404
  listenerId: this.localeStorageKey,
@@ -410,7 +409,10 @@ var LocaleStorageManager = class {
410
409
  };
411
410
  this.getLocale = () => {
412
411
  const stored = this.storageService.getItem(this.localeStorageKey);
413
- return stored != null ? stored : "";
412
+ if (!stored || stored === "") {
413
+ return this.i18nStore.defaultLocale;
414
+ }
415
+ return stored;
414
416
  };
415
417
  this.setLocale = (locale) => {
416
418
  this.storageService.setItem(this.localeStorageKey, locale);
@@ -434,11 +436,13 @@ var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
434
436
  function useLocaleStorage(localeStorageManager) {
435
437
  var _a;
436
438
  const [locale, setLocale] = useState2((_a = localeStorageManager == null ? void 0 : localeStorageManager.getLocale) == null ? void 0 : _a.call(localeStorageManager));
439
+ console.log("\u2705 locale in useLocaleStorage", locale);
437
440
  useEffect2(() => {
438
441
  var _a2;
439
442
  (_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
440
443
  listenerId: LISTENER_ID,
441
444
  listener: (newLocale) => {
445
+ console.log("\u2705 did you update the locale?", newLocale);
442
446
  setLocale(newLocale);
443
447
  }
444
448
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheet-i18n/react-client",
3
- "version": "1.5.0-canary.1",
3
+ "version": "1.5.0-canary.3",
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",