@sheet-i18n/react-client 1.5.0-canary.2 → 1.5.0-canary.4
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.js +28 -12
- package/dist/index.mjs +29 -13
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -227,23 +227,41 @@ var TranslationService = class {
|
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
229
|
findTargetTranslation(id, $tParams) {
|
|
230
|
-
var _a, _b, _c, _d, _e;
|
|
230
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
231
|
+
console.log(
|
|
232
|
+
"1) \u2705 intlInstance in findTargetTranslation",
|
|
233
|
+
this == null ? void 0 : this.intlInstance
|
|
234
|
+
);
|
|
231
235
|
const targetTranslation = (_b = (_a = this == null ? void 0 : this.intlInstance) == null ? void 0 : _a.messages) == null ? void 0 : _b[id];
|
|
232
236
|
if (import_shared_utils3.validator.isNullish(targetTranslation)) {
|
|
233
237
|
return id;
|
|
234
238
|
}
|
|
239
|
+
console.log(
|
|
240
|
+
"2) \u2705 targetTranslation in findTargetTranslation",
|
|
241
|
+
targetTranslation
|
|
242
|
+
);
|
|
235
243
|
if (typeof targetTranslation === "string" && targetTranslation.trim() === "") {
|
|
236
244
|
return "";
|
|
237
245
|
}
|
|
246
|
+
console.log("3) \u2705 $tParams in findTargetTranslation", $tParams);
|
|
238
247
|
if (!$tParams || !($tParams == null ? void 0 : $tParams.descriptor)) {
|
|
239
248
|
return "";
|
|
240
249
|
}
|
|
241
|
-
|
|
242
|
-
|
|
250
|
+
console.log(
|
|
251
|
+
"4) \u2705 $tParams.descriptor in findTargetTranslation",
|
|
252
|
+
(_d = (_c = this.intlInstance) == null ? void 0 : _c.$t) == null ? void 0 : _d.call(
|
|
253
|
+
_c,
|
|
254
|
+
$tParams.descriptor,
|
|
255
|
+
$tParams.values,
|
|
256
|
+
$tParams.opts
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
return (_g = (_f = (_e = this.intlInstance) == null ? void 0 : _e.$t) == null ? void 0 : _f.call(
|
|
260
|
+
_e,
|
|
243
261
|
$tParams.descriptor,
|
|
244
262
|
$tParams.values,
|
|
245
263
|
$tParams.opts
|
|
246
|
-
)) != null ?
|
|
264
|
+
)) != null ? _g : "";
|
|
247
265
|
}
|
|
248
266
|
};
|
|
249
267
|
|
|
@@ -439,7 +457,6 @@ var LocaleStorageManager = class {
|
|
|
439
457
|
};
|
|
440
458
|
this.setLocale = (locale) => {
|
|
441
459
|
this.storageService.setItem(this.localeStorageKey, locale);
|
|
442
|
-
this.i18nStore.setCurrentLocale(locale);
|
|
443
460
|
this.observerManager.notify(locale);
|
|
444
461
|
};
|
|
445
462
|
this.initializeCurrentLocale();
|
|
@@ -456,26 +473,25 @@ var getLocaleStorageManager = (i18nStore, storage) => {
|
|
|
456
473
|
|
|
457
474
|
// src/hooks/useLocaleStorage.ts
|
|
458
475
|
var import_react3 = require("react");
|
|
476
|
+
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
459
477
|
function useLocaleStorage(localeStorageManager) {
|
|
460
478
|
var _a;
|
|
461
479
|
const [locale, setLocale] = (0, import_react3.useState)((_a = localeStorageManager == null ? void 0 : localeStorageManager.getLocale) == null ? void 0 : _a.call(localeStorageManager));
|
|
462
|
-
|
|
463
|
-
`LOCALE_STORAGE_LISTENER_${Math.random().toString(36).substring(2, 11)}`
|
|
464
|
-
);
|
|
480
|
+
console.log("\u2705 locale in useLocaleStorage", locale);
|
|
465
481
|
(0, import_react3.useEffect)(() => {
|
|
466
482
|
var _a2;
|
|
467
|
-
const listenerId = listenerIdRef.current;
|
|
468
483
|
(_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
|
|
469
|
-
listenerId,
|
|
484
|
+
listenerId: LISTENER_ID,
|
|
470
485
|
listener: (newLocale) => {
|
|
486
|
+
console.log("\u2705 did you update the locale?", newLocale);
|
|
471
487
|
setLocale(newLocale);
|
|
472
488
|
}
|
|
473
489
|
});
|
|
474
490
|
return () => {
|
|
475
491
|
var _a3;
|
|
476
|
-
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(
|
|
492
|
+
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
|
|
477
493
|
};
|
|
478
|
-
}, [
|
|
494
|
+
}, []);
|
|
479
495
|
return { locale };
|
|
480
496
|
}
|
|
481
497
|
|
package/dist/index.mjs
CHANGED
|
@@ -204,23 +204,41 @@ var TranslationService = class {
|
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
findTargetTranslation(id, $tParams) {
|
|
207
|
-
var _a, _b, _c, _d, _e;
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
208
|
+
console.log(
|
|
209
|
+
"1) \u2705 intlInstance in findTargetTranslation",
|
|
210
|
+
this == null ? void 0 : this.intlInstance
|
|
211
|
+
);
|
|
208
212
|
const targetTranslation = (_b = (_a = this == null ? void 0 : this.intlInstance) == null ? void 0 : _a.messages) == null ? void 0 : _b[id];
|
|
209
213
|
if (validator3.isNullish(targetTranslation)) {
|
|
210
214
|
return id;
|
|
211
215
|
}
|
|
216
|
+
console.log(
|
|
217
|
+
"2) \u2705 targetTranslation in findTargetTranslation",
|
|
218
|
+
targetTranslation
|
|
219
|
+
);
|
|
212
220
|
if (typeof targetTranslation === "string" && targetTranslation.trim() === "") {
|
|
213
221
|
return "";
|
|
214
222
|
}
|
|
223
|
+
console.log("3) \u2705 $tParams in findTargetTranslation", $tParams);
|
|
215
224
|
if (!$tParams || !($tParams == null ? void 0 : $tParams.descriptor)) {
|
|
216
225
|
return "";
|
|
217
226
|
}
|
|
218
|
-
|
|
219
|
-
|
|
227
|
+
console.log(
|
|
228
|
+
"4) \u2705 $tParams.descriptor in findTargetTranslation",
|
|
229
|
+
(_d = (_c = this.intlInstance) == null ? void 0 : _c.$t) == null ? void 0 : _d.call(
|
|
230
|
+
_c,
|
|
231
|
+
$tParams.descriptor,
|
|
232
|
+
$tParams.values,
|
|
233
|
+
$tParams.opts
|
|
234
|
+
)
|
|
235
|
+
);
|
|
236
|
+
return (_g = (_f = (_e = this.intlInstance) == null ? void 0 : _e.$t) == null ? void 0 : _f.call(
|
|
237
|
+
_e,
|
|
220
238
|
$tParams.descriptor,
|
|
221
239
|
$tParams.values,
|
|
222
240
|
$tParams.opts
|
|
223
|
-
)) != null ?
|
|
241
|
+
)) != null ? _g : "";
|
|
224
242
|
}
|
|
225
243
|
};
|
|
226
244
|
|
|
@@ -416,7 +434,6 @@ var LocaleStorageManager = class {
|
|
|
416
434
|
};
|
|
417
435
|
this.setLocale = (locale) => {
|
|
418
436
|
this.storageService.setItem(this.localeStorageKey, locale);
|
|
419
|
-
this.i18nStore.setCurrentLocale(locale);
|
|
420
437
|
this.observerManager.notify(locale);
|
|
421
438
|
};
|
|
422
439
|
this.initializeCurrentLocale();
|
|
@@ -432,27 +449,26 @@ var getLocaleStorageManager = (i18nStore, storage) => {
|
|
|
432
449
|
};
|
|
433
450
|
|
|
434
451
|
// src/hooks/useLocaleStorage.ts
|
|
435
|
-
import { useEffect as useEffect2, useState as useState2
|
|
452
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
453
|
+
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
436
454
|
function useLocaleStorage(localeStorageManager) {
|
|
437
455
|
var _a;
|
|
438
456
|
const [locale, setLocale] = useState2((_a = localeStorageManager == null ? void 0 : localeStorageManager.getLocale) == null ? void 0 : _a.call(localeStorageManager));
|
|
439
|
-
|
|
440
|
-
`LOCALE_STORAGE_LISTENER_${Math.random().toString(36).substring(2, 11)}`
|
|
441
|
-
);
|
|
457
|
+
console.log("\u2705 locale in useLocaleStorage", locale);
|
|
442
458
|
useEffect2(() => {
|
|
443
459
|
var _a2;
|
|
444
|
-
const listenerId = listenerIdRef.current;
|
|
445
460
|
(_a2 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a2.addListener({
|
|
446
|
-
listenerId,
|
|
461
|
+
listenerId: LISTENER_ID,
|
|
447
462
|
listener: (newLocale) => {
|
|
463
|
+
console.log("\u2705 did you update the locale?", newLocale);
|
|
448
464
|
setLocale(newLocale);
|
|
449
465
|
}
|
|
450
466
|
});
|
|
451
467
|
return () => {
|
|
452
468
|
var _a3;
|
|
453
|
-
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(
|
|
469
|
+
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
|
|
454
470
|
};
|
|
455
|
-
}, [
|
|
471
|
+
}, []);
|
|
456
472
|
return { locale };
|
|
457
473
|
}
|
|
458
474
|
|
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.4",
|
|
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/errors": "1.8.0-canary.0",
|
|
29
28
|
"@sheet-i18n/shared-utils": "1.8.0-canary.0",
|
|
29
|
+
"@sheet-i18n/errors": "1.8.0-canary.0",
|
|
30
30
|
"@sheet-i18n/react-core": "1.5.0-canary.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|