@shuo-li/i18n 1.0.0 → 1.0.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/{cacheEvents-kOPDM3Ed.d.cts → cacheEvents-CAjfH0vs.d.cts} +2 -0
- package/dist/{cacheEvents-kOPDM3Ed.d.ts → cacheEvents-CAjfH0vs.d.ts} +2 -0
- package/dist/{chunk-ONDHZEK4.js → chunk-BE3XDO7H.js} +27 -23
- package/dist/{chunk-JDOLFHBS.cjs → chunk-VKQL65NM.cjs} +27 -23
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/mp/index.cjs +3 -3
- package/dist/mp/index.d.cts +2 -2
- package/dist/mp/index.d.ts +2 -2
- package/dist/mp/index.js +1 -1
- package/dist/native/index.cjs +3 -3
- package/dist/native/index.d.cts +2 -2
- package/dist/native/index.d.ts +2 -2
- package/dist/native/index.js +1 -1
- package/dist/workers/preload-worker.cjs +9 -6
- package/dist/workers/preload-worker.js +9 -6
- package/package.json +1 -1
|
@@ -85,6 +85,8 @@ interface WorkerTask {
|
|
|
85
85
|
/** 全量拉取时为 0;SSE 增量拉取时为本地已有版本号 */
|
|
86
86
|
version?: number;
|
|
87
87
|
trigger?: 'init-full' | 'sse';
|
|
88
|
+
/** 经 buildParams 映射后的实际请求参数;未提供时 Worker 使用内部字段名 */
|
|
89
|
+
params?: Record<string, unknown>;
|
|
88
90
|
}
|
|
89
91
|
interface WorkerModuleLoadedMessage {
|
|
90
92
|
type: 'moduleLoaded';
|
|
@@ -85,6 +85,8 @@ interface WorkerTask {
|
|
|
85
85
|
/** 全量拉取时为 0;SSE 增量拉取时为本地已有版本号 */
|
|
86
86
|
version?: number;
|
|
87
87
|
trigger?: 'init-full' | 'sse';
|
|
88
|
+
/** 经 buildParams 映射后的实际请求参数;未提供时 Worker 使用内部字段名 */
|
|
89
|
+
params?: Record<string, unknown>;
|
|
88
90
|
}
|
|
89
91
|
interface WorkerModuleLoadedMessage {
|
|
90
92
|
type: 'moduleLoaded';
|
|
@@ -123,9 +123,6 @@ var SSEClient = class {
|
|
|
123
123
|
function buildKey(moduleCode, langCode, store) {
|
|
124
124
|
return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
|
|
125
125
|
}
|
|
126
|
-
function buildUnloginKey(langCode) {
|
|
127
|
-
return `UNLOGIN_${langCode}`;
|
|
128
|
-
}
|
|
129
126
|
function flatToNested(flat) {
|
|
130
127
|
const result = {};
|
|
131
128
|
for (const [key, value] of Object.entries(flat)) {
|
|
@@ -303,12 +300,17 @@ async function initI18n(options) {
|
|
|
303
300
|
if (currentPromise) closeSSE();
|
|
304
301
|
currentSig = sig;
|
|
305
302
|
initOptions = options;
|
|
306
|
-
|
|
303
|
+
const p = _initI18n(options).then(() => {
|
|
304
|
+
if (!options.apiContext.isLoggedIn()) {
|
|
305
|
+
currentPromise = null;
|
|
306
|
+
}
|
|
307
|
+
}).catch((err) => {
|
|
307
308
|
currentSig = null;
|
|
308
309
|
currentPromise = null;
|
|
309
310
|
throw err;
|
|
310
311
|
});
|
|
311
|
-
|
|
312
|
+
currentPromise = p;
|
|
313
|
+
return p;
|
|
312
314
|
}
|
|
313
315
|
async function ensureModules(moduleCodes) {
|
|
314
316
|
const toLoad = moduleCodes.filter((m) => {
|
|
@@ -364,8 +366,8 @@ async function _initI18n(options) {
|
|
|
364
366
|
resolvedStores = options.stores;
|
|
365
367
|
resolvedLanguages = options.languages ?? [options.language];
|
|
366
368
|
resolvedModules = options.modules ?? [];
|
|
367
|
-
await checkCacheVersion(storage, options);
|
|
368
369
|
await storage.ensureSchemaVersion(resolvedStores);
|
|
370
|
+
await checkCacheVersion(storage, options);
|
|
369
371
|
for (const lang of resolvedLanguages) {
|
|
370
372
|
for (const m of resolvedModules) {
|
|
371
373
|
i18n.addResourceBundle(lang, m, getStaticLocale(m, lang), true, false);
|
|
@@ -404,28 +406,30 @@ async function checkCacheVersion(storage, options) {
|
|
|
404
406
|
async function doUnloginPull(storage, options) {
|
|
405
407
|
const { apiContext } = options;
|
|
406
408
|
if (!apiContext.unloginPull) return;
|
|
407
|
-
const
|
|
409
|
+
const baseStore = resolvedStores[0];
|
|
408
410
|
try {
|
|
409
411
|
const blocks = await doFetch(apiContext.unloginPull, options);
|
|
410
412
|
for (const block of blocks) {
|
|
411
413
|
for (const mod of block.modules ?? []) {
|
|
412
|
-
|
|
413
|
-
await storage.
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
415
|
+
const existing = await storage.getRecord(baseStore.name, key);
|
|
416
|
+
const parsed = parseI18nValues(mod.i18nValues ?? []);
|
|
417
|
+
const resources = deepMerge(
|
|
418
|
+
existing?.resources ?? {},
|
|
419
|
+
flatToNested(parsed)
|
|
420
|
+
);
|
|
421
|
+
await storage.putRecord(baseStore.name, {
|
|
422
|
+
key,
|
|
423
|
+
moduleCode: mod.moduleCode,
|
|
416
424
|
langCode: block.langCode,
|
|
417
425
|
version: mod.version ?? 0,
|
|
418
|
-
resources
|
|
426
|
+
resources
|
|
419
427
|
});
|
|
420
428
|
}
|
|
421
429
|
}
|
|
422
430
|
} catch {
|
|
423
431
|
}
|
|
424
|
-
|
|
425
|
-
const dbUnlogin = await storage.getRecord(unloginStoreName, buildUnloginKey(currentLang));
|
|
426
|
-
if (dbUnlogin?.resources) {
|
|
427
|
-
i18n.addResourceBundle(currentLang, "UNLOGIN", dbUnlogin.resources, true, true);
|
|
428
|
-
}
|
|
432
|
+
await injectCurrentLanguageModules(currentLang);
|
|
429
433
|
await i18n.changeLanguage(currentLang);
|
|
430
434
|
emitI18nResourcesUpdated();
|
|
431
435
|
}
|
|
@@ -436,12 +440,11 @@ async function startWorkerFull(options) {
|
|
|
436
440
|
for (const store of resolvedStores) {
|
|
437
441
|
for (const lang of resolvedLanguages) {
|
|
438
442
|
for (const module of sortedModules()) {
|
|
443
|
+
const internal = { storeName: store.name, langCode: lang, moduleCode: module, version: 0 };
|
|
439
444
|
tasks.push({
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
version: 0,
|
|
444
|
-
trigger: "init-full"
|
|
445
|
+
...internal,
|
|
446
|
+
trigger: "init-full",
|
|
447
|
+
params: pull.buildParams ? pull.buildParams(internal) : void 0
|
|
445
448
|
});
|
|
446
449
|
}
|
|
447
450
|
}
|
|
@@ -632,7 +635,8 @@ async function doFetch(config, options, internalParams) {
|
|
|
632
635
|
body: JSON.stringify(params)
|
|
633
636
|
});
|
|
634
637
|
} else {
|
|
635
|
-
|
|
638
|
+
const qs = toQueryString(params);
|
|
639
|
+
res = await fetchFn(qs ? `${url}?${qs}` : url, { headers });
|
|
636
640
|
}
|
|
637
641
|
if (!res.ok) throw new Error(`[i18n] fetch failed: ${res.status} ${url}`);
|
|
638
642
|
const raw = await res.json();
|
|
@@ -123,9 +123,6 @@ var SSEClient = class {
|
|
|
123
123
|
function buildKey(moduleCode, langCode, store) {
|
|
124
124
|
return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
|
|
125
125
|
}
|
|
126
|
-
function buildUnloginKey(langCode) {
|
|
127
|
-
return `UNLOGIN_${langCode}`;
|
|
128
|
-
}
|
|
129
126
|
function flatToNested(flat) {
|
|
130
127
|
const result = {};
|
|
131
128
|
for (const [key, value] of Object.entries(flat)) {
|
|
@@ -303,12 +300,17 @@ async function initI18n(options) {
|
|
|
303
300
|
if (currentPromise) closeSSE();
|
|
304
301
|
currentSig = sig;
|
|
305
302
|
initOptions = options;
|
|
306
|
-
|
|
303
|
+
const p = _initI18n(options).then(() => {
|
|
304
|
+
if (!options.apiContext.isLoggedIn()) {
|
|
305
|
+
currentPromise = null;
|
|
306
|
+
}
|
|
307
|
+
}).catch((err) => {
|
|
307
308
|
currentSig = null;
|
|
308
309
|
currentPromise = null;
|
|
309
310
|
throw err;
|
|
310
311
|
});
|
|
311
|
-
|
|
312
|
+
currentPromise = p;
|
|
313
|
+
return p;
|
|
312
314
|
}
|
|
313
315
|
async function ensureModules(moduleCodes) {
|
|
314
316
|
const toLoad = moduleCodes.filter((m) => {
|
|
@@ -364,8 +366,8 @@ async function _initI18n(options) {
|
|
|
364
366
|
resolvedStores = options.stores;
|
|
365
367
|
resolvedLanguages = _nullishCoalesce(options.languages, () => ( [options.language]));
|
|
366
368
|
resolvedModules = _nullishCoalesce(options.modules, () => ( []));
|
|
367
|
-
await checkCacheVersion(storage, options);
|
|
368
369
|
await storage.ensureSchemaVersion(resolvedStores);
|
|
370
|
+
await checkCacheVersion(storage, options);
|
|
369
371
|
for (const lang of resolvedLanguages) {
|
|
370
372
|
for (const m of resolvedModules) {
|
|
371
373
|
_i18next2.default.addResourceBundle(lang, m, getStaticLocale(m, lang), true, false);
|
|
@@ -404,28 +406,30 @@ async function checkCacheVersion(storage, options) {
|
|
|
404
406
|
async function doUnloginPull(storage, options) {
|
|
405
407
|
const { apiContext } = options;
|
|
406
408
|
if (!apiContext.unloginPull) return;
|
|
407
|
-
const
|
|
409
|
+
const baseStore = resolvedStores[0];
|
|
408
410
|
try {
|
|
409
411
|
const blocks = await doFetch(apiContext.unloginPull, options);
|
|
410
412
|
for (const block of blocks) {
|
|
411
413
|
for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
|
|
412
|
-
|
|
413
|
-
await storage.
|
|
414
|
-
|
|
415
|
-
|
|
414
|
+
const key = buildKey(mod.moduleCode, block.langCode, baseStore);
|
|
415
|
+
const existing = await storage.getRecord(baseStore.name, key);
|
|
416
|
+
const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
|
|
417
|
+
const resources = deepMerge(
|
|
418
|
+
_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
|
|
419
|
+
flatToNested(parsed)
|
|
420
|
+
);
|
|
421
|
+
await storage.putRecord(baseStore.name, {
|
|
422
|
+
key,
|
|
423
|
+
moduleCode: mod.moduleCode,
|
|
416
424
|
langCode: block.langCode,
|
|
417
425
|
version: _nullishCoalesce(mod.version, () => ( 0)),
|
|
418
|
-
resources
|
|
426
|
+
resources
|
|
419
427
|
});
|
|
420
428
|
}
|
|
421
429
|
}
|
|
422
430
|
} catch (e4) {
|
|
423
431
|
}
|
|
424
|
-
|
|
425
|
-
const dbUnlogin = await storage.getRecord(unloginStoreName, buildUnloginKey(currentLang));
|
|
426
|
-
if (_optionalChain([dbUnlogin, 'optionalAccess', _21 => _21.resources])) {
|
|
427
|
-
_i18next2.default.addResourceBundle(currentLang, "UNLOGIN", dbUnlogin.resources, true, true);
|
|
428
|
-
}
|
|
432
|
+
await injectCurrentLanguageModules(currentLang);
|
|
429
433
|
await _i18next2.default.changeLanguage(currentLang);
|
|
430
434
|
emitI18nResourcesUpdated();
|
|
431
435
|
}
|
|
@@ -436,12 +440,11 @@ async function startWorkerFull(options) {
|
|
|
436
440
|
for (const store of resolvedStores) {
|
|
437
441
|
for (const lang of resolvedLanguages) {
|
|
438
442
|
for (const module of sortedModules()) {
|
|
443
|
+
const internal = { storeName: store.name, langCode: lang, moduleCode: module, version: 0 };
|
|
439
444
|
tasks.push({
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
version: 0,
|
|
444
|
-
trigger: "init-full"
|
|
445
|
+
...internal,
|
|
446
|
+
trigger: "init-full",
|
|
447
|
+
params: pull.buildParams ? pull.buildParams(internal) : void 0
|
|
445
448
|
});
|
|
446
449
|
}
|
|
447
450
|
}
|
|
@@ -632,7 +635,8 @@ async function doFetch(config, options, internalParams) {
|
|
|
632
635
|
body: JSON.stringify(params)
|
|
633
636
|
});
|
|
634
637
|
} else {
|
|
635
|
-
|
|
638
|
+
const qs = toQueryString(params);
|
|
639
|
+
res = await fetchFn(qs ? `${url}?${qs}` : url, { headers });
|
|
636
640
|
}
|
|
637
641
|
if (!res.ok) throw new Error(`[i18n] fetch failed: ${res.status} ${url}`);
|
|
638
642
|
const raw = await res.json();
|
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('./chunk-AJJKJPNB.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkVKQL65NMcjs = require('./chunk-VKQL65NM.cjs');
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
|
|
@@ -203,7 +203,7 @@ if (!_i18next2.default.isInitialized) {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
206
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkVKQL65NMcjs.createI18nManager.call(void 0, {
|
|
207
207
|
storage: new IndexedDBAdapter(),
|
|
208
208
|
workerWritesDB: true,
|
|
209
209
|
createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
|
|
@@ -220,4 +220,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
220
220
|
|
|
221
221
|
|
|
222
222
|
|
|
223
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
223
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkVKQL65NMcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkVKQL65NMcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CAjfH0vs.cjs';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-CAjfH0vs.cjs';
|
|
3
3
|
export { u as useDict } from './hooks-ClO29Chr.cjs';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CAjfH0vs.js';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, W as WorkerLike, h as emitI18nResourcesUpdated } from './cacheEvents-CAjfH0vs.js';
|
|
3
3
|
export { u as useDict } from './hooks-ClO29Chr.js';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/index.js
CHANGED
package/dist/mp/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkVKQL65NMcjs = require('../chunk-VKQL65NM.cjs');
|
|
6
6
|
|
|
7
7
|
// src/storage/wx-sqlite.ts
|
|
8
8
|
var DB_NAME = "i18n_cache";
|
|
@@ -215,7 +215,7 @@ function wxFetch(input, init) {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// src/mp/index.ts
|
|
218
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
218
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkVKQL65NMcjs.createI18nManager.call(void 0, {
|
|
219
219
|
storage: new WxSQLiteAdapter(),
|
|
220
220
|
createWorker: () => new WxWorkerAdapter(wx.createWorker("workers/preload-worker-mp.js")),
|
|
221
221
|
fetchFn: wxFetch
|
|
@@ -228,4 +228,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
228
228
|
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
231
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkVKQL65NMcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkVKQL65NMcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
|
package/dist/mp/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CAjfH0vs.cjs';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CAjfH0vs.cjs';
|
|
3
3
|
|
|
4
4
|
declare const initI18n: typeof initI18n$1;
|
|
5
5
|
declare const closeSSE: typeof closeSSE$1;
|
package/dist/mp/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CAjfH0vs.js';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CAjfH0vs.js';
|
|
3
3
|
|
|
4
4
|
declare const initI18n: typeof initI18n$1;
|
|
5
5
|
declare const closeSSE: typeof closeSSE$1;
|
package/dist/mp/index.js
CHANGED
package/dist/native/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('../chunk-AJJKJPNB.cjs');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkVKQL65NMcjs = require('../chunk-VKQL65NM.cjs');
|
|
11
11
|
|
|
12
12
|
// src/native/index.ts
|
|
13
13
|
var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
|
|
@@ -155,7 +155,7 @@ if (!_i18next2.default.isInitialized) {
|
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
158
|
+
var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkVKQL65NMcjs.createI18nManager.call(void 0, {
|
|
159
159
|
storage: new SQLiteAdapter(),
|
|
160
160
|
// Hermes Worker(RN 0.71+),API 与 Web Worker 一致
|
|
161
161
|
createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
|
|
@@ -172,4 +172,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
|
|
|
172
172
|
|
|
173
173
|
|
|
174
174
|
|
|
175
|
-
exports.I18N_RESOURCES_UPDATED_EVENT =
|
|
175
|
+
exports.I18N_RESOURCES_UPDATED_EVENT = _chunkVKQL65NMcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkVKQL65NMcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
|
package/dist/native/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CAjfH0vs.cjs';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CAjfH0vs.cjs';
|
|
3
3
|
export { u as useDict } from '../hooks-ClO29Chr.cjs';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/native/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-
|
|
2
|
-
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-
|
|
1
|
+
import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-CAjfH0vs.js';
|
|
2
|
+
export { I as I18N_RESOURCES_UPDATED_EVENT, b as I18nInitOptions, P as PullLangBlock, R as ResourceRecord, S as SSEMessage, d as StandardPullParams, f as StoreConfig, h as emitI18nResourcesUpdated } from '../cacheEvents-CAjfH0vs.js';
|
|
3
3
|
export { u as useDict } from '../hooks-ClO29Chr.js';
|
|
4
4
|
export { useTranslation } from 'react-i18next';
|
|
5
5
|
|
package/dist/native/index.js
CHANGED
|
@@ -80,11 +80,13 @@ function idbPut(database, storeName, value) {
|
|
|
80
80
|
}
|
|
81
81
|
async function processTask(task, payload) {
|
|
82
82
|
const { baseURL, headers, pullPath, pullMethod, stores } = payload;
|
|
83
|
-
const params = {};
|
|
84
|
-
if (task.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const params = _nullishCoalesce(task.params, () => ( {}));
|
|
84
|
+
if (!task.params) {
|
|
85
|
+
if (task.storeName) params["storeName"] = task.storeName;
|
|
86
|
+
if (task.langCode) params["langCode"] = task.langCode;
|
|
87
|
+
if (task.moduleCode) params["moduleCode"] = task.moduleCode;
|
|
88
|
+
if (task.version != null) params["version"] = task.version;
|
|
89
|
+
}
|
|
88
90
|
const url = baseURL + pullPath;
|
|
89
91
|
let res;
|
|
90
92
|
if (pullMethod === "POST") {
|
|
@@ -94,7 +96,8 @@ async function processTask(task, payload) {
|
|
|
94
96
|
body: JSON.stringify(params)
|
|
95
97
|
});
|
|
96
98
|
} else {
|
|
97
|
-
|
|
99
|
+
const qs = toQueryString(params);
|
|
100
|
+
res = await fetch(qs ? `${url}?${qs}` : url, { headers });
|
|
98
101
|
}
|
|
99
102
|
if (!res.ok) throw new Error(`[i18n worker] fetch failed: ${res.status}`);
|
|
100
103
|
const blocks = await res.json();
|
|
@@ -80,11 +80,13 @@ function idbPut(database, storeName, value) {
|
|
|
80
80
|
}
|
|
81
81
|
async function processTask(task, payload) {
|
|
82
82
|
const { baseURL, headers, pullPath, pullMethod, stores } = payload;
|
|
83
|
-
const params = {};
|
|
84
|
-
if (task.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const params = task.params ?? {};
|
|
84
|
+
if (!task.params) {
|
|
85
|
+
if (task.storeName) params["storeName"] = task.storeName;
|
|
86
|
+
if (task.langCode) params["langCode"] = task.langCode;
|
|
87
|
+
if (task.moduleCode) params["moduleCode"] = task.moduleCode;
|
|
88
|
+
if (task.version != null) params["version"] = task.version;
|
|
89
|
+
}
|
|
88
90
|
const url = baseURL + pullPath;
|
|
89
91
|
let res;
|
|
90
92
|
if (pullMethod === "POST") {
|
|
@@ -94,7 +96,8 @@ async function processTask(task, payload) {
|
|
|
94
96
|
body: JSON.stringify(params)
|
|
95
97
|
});
|
|
96
98
|
} else {
|
|
97
|
-
|
|
99
|
+
const qs = toQueryString(params);
|
|
100
|
+
res = await fetch(qs ? `${url}?${qs}` : url, { headers });
|
|
98
101
|
}
|
|
99
102
|
if (!res.ok) throw new Error(`[i18n worker] fetch failed: ${res.status}`);
|
|
100
103
|
const blocks = await res.json();
|