@sheet-i18n/react-client 1.5.0-canary.1 → 1.5.0-canary.2
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -10
- package/dist/index.mjs +17 -11
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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,10 +432,14 @@ var LocaleStorageManager = class {
|
|
|
433
432
|
};
|
|
434
433
|
this.getLocale = () => {
|
|
435
434
|
const stored = this.storageService.getItem(this.localeStorageKey);
|
|
436
|
-
|
|
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);
|
|
442
|
+
this.i18nStore.setCurrentLocale(locale);
|
|
440
443
|
this.observerManager.notify(locale);
|
|
441
444
|
};
|
|
442
445
|
this.initializeCurrentLocale();
|
|
@@ -453,23 +456,26 @@ var getLocaleStorageManager = (i18nStore, storage) => {
|
|
|
453
456
|
|
|
454
457
|
// src/hooks/useLocaleStorage.ts
|
|
455
458
|
var import_react3 = require("react");
|
|
456
|
-
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
|
+
const listenerIdRef = (0, import_react3.useRef)(
|
|
463
|
+
`LOCALE_STORAGE_LISTENER_${Math.random().toString(36).substring(2, 11)}`
|
|
464
|
+
);
|
|
460
465
|
(0, import_react3.useEffect)(() => {
|
|
461
466
|
var _a2;
|
|
467
|
+
const listenerId = listenerIdRef.current;
|
|
462
468
|
(_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
|
|
463
|
-
listenerId
|
|
469
|
+
listenerId,
|
|
464
470
|
listener: (newLocale) => {
|
|
465
471
|
setLocale(newLocale);
|
|
466
472
|
}
|
|
467
473
|
});
|
|
468
474
|
return () => {
|
|
469
475
|
var _a3;
|
|
470
|
-
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(
|
|
476
|
+
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(listenerId);
|
|
471
477
|
};
|
|
472
|
-
}, []);
|
|
478
|
+
}, [localeStorageManager]);
|
|
473
479
|
return { locale };
|
|
474
480
|
}
|
|
475
481
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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,10 +409,14 @@ var LocaleStorageManager = class {
|
|
|
410
409
|
};
|
|
411
410
|
this.getLocale = () => {
|
|
412
411
|
const stored = this.storageService.getItem(this.localeStorageKey);
|
|
413
|
-
|
|
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);
|
|
419
|
+
this.i18nStore.setCurrentLocale(locale);
|
|
417
420
|
this.observerManager.notify(locale);
|
|
418
421
|
};
|
|
419
422
|
this.initializeCurrentLocale();
|
|
@@ -429,24 +432,27 @@ var getLocaleStorageManager = (i18nStore, storage) => {
|
|
|
429
432
|
};
|
|
430
433
|
|
|
431
434
|
// src/hooks/useLocaleStorage.ts
|
|
432
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
433
|
-
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
435
|
+
import { useEffect as useEffect2, useState as useState2, useRef } from "react";
|
|
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
|
+
const listenerIdRef = useRef(
|
|
440
|
+
`LOCALE_STORAGE_LISTENER_${Math.random().toString(36).substring(2, 11)}`
|
|
441
|
+
);
|
|
437
442
|
useEffect2(() => {
|
|
438
443
|
var _a2;
|
|
444
|
+
const listenerId = listenerIdRef.current;
|
|
439
445
|
(_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
|
|
440
|
-
listenerId
|
|
446
|
+
listenerId,
|
|
441
447
|
listener: (newLocale) => {
|
|
442
448
|
setLocale(newLocale);
|
|
443
449
|
}
|
|
444
450
|
});
|
|
445
451
|
return () => {
|
|
446
452
|
var _a3;
|
|
447
|
-
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(
|
|
453
|
+
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(listenerId);
|
|
448
454
|
};
|
|
449
|
-
}, []);
|
|
455
|
+
}, [localeStorageManager]);
|
|
450
456
|
return { locale };
|
|
451
457
|
}
|
|
452
458
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheet-i18n/react-client",
|
|
3
|
-
"version": "1.5.0-canary.
|
|
3
|
+
"version": "1.5.0-canary.2",
|
|
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,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sheet-i18n/shared-utils": "1.8.0-canary.0",
|
|
29
28
|
"@sheet-i18n/errors": "1.8.0-canary.0",
|
|
29
|
+
"@sheet-i18n/shared-utils": "1.8.0-canary.0",
|
|
30
30
|
"@sheet-i18n/react-core": "1.5.0-canary.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|