@shuo-li/i18n 1.0.9 → 1.1.0

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.
@@ -39,16 +39,13 @@ interface I18nInitOptions {
39
39
  sse?: SSEConfig;
40
40
  };
41
41
  }
42
- interface I18nValue {
43
- termCode?: string;
44
- langValue?: string;
45
- }
46
42
  interface PullLangBlock {
47
43
  langCode: string;
48
44
  modules: Array<{
49
45
  moduleCode: string;
50
46
  version: number;
51
- i18nValues: I18nValue[];
47
+ /** transform 函数返回的最终资源对象,直接写入 DB 和 i18next */
48
+ resources: Record<string, unknown>;
52
49
  }>;
53
50
  }
54
51
  interface SSEMessage {
@@ -39,16 +39,13 @@ interface I18nInitOptions {
39
39
  sse?: SSEConfig;
40
40
  };
41
41
  }
42
- interface I18nValue {
43
- termCode?: string;
44
- langValue?: string;
45
- }
46
42
  interface PullLangBlock {
47
43
  langCode: string;
48
44
  modules: Array<{
49
45
  moduleCode: string;
50
46
  version: number;
51
- i18nValues: I18nValue[];
47
+ /** transform 函数返回的最终资源对象,直接写入 DB 和 i18next */
48
+ resources: Record<string, unknown>;
52
49
  }>;
53
50
  }
54
51
  interface SSEMessage {
@@ -5,6 +5,52 @@ function emitI18nResourcesUpdated() {
5
5
  window.dispatchEvent(new CustomEvent(I18N_RESOURCES_UPDATED_EVENT));
6
6
  }
7
7
 
8
+ // src/core/utils.ts
9
+ function buildKey(moduleCode, langCode, store) {
10
+ return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
11
+ }
12
+ function flatToNested(flat) {
13
+ const result = {};
14
+ for (const [key, value] of Object.entries(flat)) {
15
+ const parts = key.split(".");
16
+ let cur = result;
17
+ for (let i = 0; i < parts.length - 1; i++) {
18
+ const part = parts[i];
19
+ if (typeof cur[part] !== "object" || cur[part] === null) {
20
+ cur[part] = {};
21
+ }
22
+ cur = cur[part];
23
+ }
24
+ cur[parts[parts.length - 1]] = value;
25
+ }
26
+ return result;
27
+ }
28
+ function deepMerge(target, source) {
29
+ const result = { ...target };
30
+ for (const [key, sv] of Object.entries(source)) {
31
+ const tv = result[key];
32
+ if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
33
+ result[key] = deepMerge(tv, sv);
34
+ } else {
35
+ result[key] = sv;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ function toDefaultParams(p) {
41
+ const result = {};
42
+ if (p?.storeName) result["storeName"] = p.storeName;
43
+ if (p?.langCode) result["langCode"] = p.langCode;
44
+ if (p?.moduleCode) result["moduleCode"] = p.moduleCode;
45
+ if (p?.version != null) result["version"] = String(p.version);
46
+ return result;
47
+ }
48
+ function toQueryString(params) {
49
+ return new URLSearchParams(
50
+ Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
51
+ ).toString();
52
+ }
53
+
8
54
  // src/core/manager.ts
9
55
  import i18n from "i18next";
10
56
 
@@ -169,61 +215,6 @@ var WorkerManager = class {
169
215
  }
170
216
  };
171
217
 
172
- // src/core/utils.ts
173
- function buildKey(moduleCode, langCode, store) {
174
- return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
175
- }
176
- function flatToNested(flat) {
177
- const result = {};
178
- for (const [key, value] of Object.entries(flat)) {
179
- const parts = key.split(".");
180
- let cur = result;
181
- for (let i = 0; i < parts.length - 1; i++) {
182
- const part = parts[i];
183
- if (typeof cur[part] !== "object" || cur[part] === null) {
184
- cur[part] = {};
185
- }
186
- cur = cur[part];
187
- }
188
- cur[parts[parts.length - 1]] = value;
189
- }
190
- return result;
191
- }
192
- function deepMerge(target, source) {
193
- const result = { ...target };
194
- for (const [key, sv] of Object.entries(source)) {
195
- const tv = result[key];
196
- if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
197
- result[key] = deepMerge(tv, sv);
198
- } else {
199
- result[key] = sv;
200
- }
201
- }
202
- return result;
203
- }
204
- function parseI18nValues(values) {
205
- const result = {};
206
- for (const { termCode, langValue } of values) {
207
- if (termCode && langValue !== void 0) {
208
- result[termCode] = langValue ?? "";
209
- }
210
- }
211
- return result;
212
- }
213
- function toDefaultParams(p) {
214
- const result = {};
215
- if (p?.storeName) result["storeName"] = p.storeName;
216
- if (p?.langCode) result["langCode"] = p.langCode;
217
- if (p?.moduleCode) result["moduleCode"] = p.moduleCode;
218
- if (p?.version != null) result["version"] = String(p.version);
219
- return result;
220
- }
221
- function toQueryString(params) {
222
- return new URLSearchParams(
223
- Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
224
- ).toString();
225
- }
226
-
227
218
  // src/core/manager.ts
228
219
  var PRIORITY_MODULES = ["ENUMS", "CUSTOMER"];
229
220
  var currentLang = "zh_CN";
@@ -316,7 +307,7 @@ async function getResource(moduleCode, langCode) {
316
307
  if (result.status === "rejected") continue;
317
308
  const record = result.value;
318
309
  if (!record?.resources) continue;
319
- merged = i === 0 ? deepMerge(merged, record.resources) : deepMerge(merged, flatToNested(record.resources));
310
+ merged = deepMerge(merged, record.resources);
320
311
  }
321
312
  return merged;
322
313
  }
@@ -398,9 +389,8 @@ async function doUnloginPull(storage, options) {
398
389
  let blocks;
399
390
  try {
400
391
  blocks = await doFetch(apiContext.unloginPull, options);
401
- } catch {
402
- await injectCurrentLanguageModules(currentLang);
403
- await i18n.changeLanguage(currentLang);
392
+ } catch (err) {
393
+ console.error("[i18n] unloginPull \u8BF7\u6C42\u5931\u8D25\uFF0C\u964D\u7EA7\u9759\u6001\u515C\u5E95", err);
404
394
  emitI18nResourcesUpdated();
405
395
  return;
406
396
  }
@@ -408,10 +398,9 @@ async function doUnloginPull(storage, options) {
408
398
  for (const mod of block.modules ?? []) {
409
399
  const key = buildKey(mod.moduleCode, block.langCode, baseStore);
410
400
  const existing = await storage.getRecord(baseStore.name, key);
411
- const parsed = parseI18nValues(mod.i18nValues ?? []);
412
401
  const resources = deepMerge(
413
402
  existing?.resources ?? {},
414
- flatToNested(parsed)
403
+ mod.resources
415
404
  );
416
405
  await storage.putRecord(baseStore.name, {
417
406
  key,
@@ -459,7 +448,13 @@ function runWorker(options, tasks, pull) {
459
448
  },
460
449
  {
461
450
  onRawData: async (task, raw) => {
462
- const blocks = pull.transform ? pull.transform(raw) : raw;
451
+ let blocks;
452
+ try {
453
+ blocks = pull.transform ? pull.transform(raw) : raw;
454
+ } catch (err) {
455
+ console.error("[i18n] pull transform \u5931\u8D25", task, err);
456
+ return;
457
+ }
463
458
  const store = resolvedStores.find((s) => s.name === task.storeName);
464
459
  if (!store) return;
465
460
  const storeIndex = resolvedStores.indexOf(store);
@@ -468,11 +463,7 @@ function runWorker(options, tasks, pull) {
468
463
  const key = buildKey(mod.moduleCode, block.langCode, store);
469
464
  const existing = await storage.getRecord(store.name, key);
470
465
  if (existing && mod.version <= existing.version) continue;
471
- const parsed = parseI18nValues(mod.i18nValues ?? []);
472
- const resources = storeIndex === 0 ? deepMerge(
473
- existing?.resources ?? {},
474
- flatToNested(parsed)
475
- ) : { ...existing?.resources ?? {}, ...parsed };
466
+ const resources = storeIndex === 0 ? deepMerge(existing?.resources ?? {}, mod.resources) : { ...existing?.resources ?? {}, ...mod.resources };
476
467
  await storage.putRecord(store.name, {
477
468
  key,
478
469
  moduleCode: mod.moduleCode,
@@ -618,16 +609,7 @@ async function pullAndStore(task, fromVersion, options) {
618
609
  const key = buildKey(mod.moduleCode, block.langCode, store);
619
610
  const existing = await storage.getRecord(store.name, key);
620
611
  if (mod.version <= (existing?.version ?? 0)) continue;
621
- let resources;
622
- const parsed = parseI18nValues(mod.i18nValues ?? []);
623
- if (storeIndex === 0) {
624
- resources = deepMerge(
625
- existing?.resources ?? {},
626
- flatToNested(parsed)
627
- );
628
- } else {
629
- resources = { ...existing?.resources ?? {}, ...parsed };
630
- }
612
+ const resources = storeIndex === 0 ? deepMerge(existing?.resources ?? {}, mod.resources) : { ...existing?.resources ?? {}, ...mod.resources };
631
613
  const version = Math.max(mod.version, task.targetVersion);
632
614
  await storage.putRecord(store.name, {
633
615
  key,
@@ -683,5 +665,7 @@ async function getStoredVersion(store, moduleCode, langCode) {
683
665
  export {
684
666
  I18N_RESOURCES_UPDATED_EVENT,
685
667
  emitI18nResourcesUpdated,
668
+ flatToNested,
669
+ deepMerge,
686
670
  createI18nManager
687
671
  };
@@ -5,6 +5,52 @@ function emitI18nResourcesUpdated() {
5
5
  window.dispatchEvent(new CustomEvent(I18N_RESOURCES_UPDATED_EVENT));
6
6
  }
7
7
 
8
+ // src/core/utils.ts
9
+ function buildKey(moduleCode, langCode, store) {
10
+ return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
11
+ }
12
+ function flatToNested(flat) {
13
+ const result = {};
14
+ for (const [key, value] of Object.entries(flat)) {
15
+ const parts = key.split(".");
16
+ let cur = result;
17
+ for (let i = 0; i < parts.length - 1; i++) {
18
+ const part = parts[i];
19
+ if (typeof cur[part] !== "object" || cur[part] === null) {
20
+ cur[part] = {};
21
+ }
22
+ cur = cur[part];
23
+ }
24
+ cur[parts[parts.length - 1]] = value;
25
+ }
26
+ return result;
27
+ }
28
+ function deepMerge(target, source) {
29
+ const result = { ...target };
30
+ for (const [key, sv] of Object.entries(source)) {
31
+ const tv = result[key];
32
+ if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
33
+ result[key] = deepMerge(tv, sv);
34
+ } else {
35
+ result[key] = sv;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ function toDefaultParams(p) {
41
+ const result = {};
42
+ if (_optionalChain([p, 'optionalAccess', _2 => _2.storeName])) result["storeName"] = p.storeName;
43
+ if (_optionalChain([p, 'optionalAccess', _3 => _3.langCode])) result["langCode"] = p.langCode;
44
+ if (_optionalChain([p, 'optionalAccess', _4 => _4.moduleCode])) result["moduleCode"] = p.moduleCode;
45
+ if (_optionalChain([p, 'optionalAccess', _5 => _5.version]) != null) result["version"] = String(p.version);
46
+ return result;
47
+ }
48
+ function toQueryString(params) {
49
+ return new URLSearchParams(
50
+ Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
51
+ ).toString();
52
+ }
53
+
8
54
  // src/core/manager.ts
9
55
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
10
56
 
@@ -33,7 +79,7 @@ var SSEClient = class {
33
79
  clearTimeout(this.reconnectTimer);
34
80
  this.reconnectTimer = null;
35
81
  }
36
- _optionalChain([this, 'access', _2 => _2.abortController, 'optionalAccess', _3 => _3.abort, 'call', _4 => _4()]);
82
+ _optionalChain([this, 'access', _6 => _6.abortController, 'optionalAccess', _7 => _7.abort, 'call', _8 => _8()]);
37
83
  this.abortController = null;
38
84
  }
39
85
  async connect() {
@@ -103,7 +149,7 @@ var SSEClient = class {
103
149
  if (!data) return;
104
150
  try {
105
151
  const parsed = JSON.parse(data);
106
- _optionalChain([this, 'access', _5 => _5.onMessage, 'optionalCall', _6 => _6(parsed)]);
152
+ _optionalChain([this, 'access', _9 => _9.onMessage, 'optionalCall', _10 => _10(parsed)]);
107
153
  } catch (e2) {
108
154
  }
109
155
  }
@@ -143,16 +189,16 @@ var WorkerManager = class {
143
189
  this.pendingCallbacks.add(p);
144
190
  p.finally(() => this.pendingCallbacks.delete(p));
145
191
  } else if (msg.type === "moduleError") {
146
- _optionalChain([callbacks, 'access', _7 => _7.onModuleError, 'optionalCall', _8 => _8(msg)]);
192
+ _optionalChain([callbacks, 'access', _11 => _11.onModuleError, 'optionalCall', _12 => _12(msg)]);
147
193
  } else if (msg.type === "done" || msg.type === "error") {
148
- if (msg.type === "error") _optionalChain([callbacks, 'access', _9 => _9.onError, 'optionalCall', _10 => _10()]);
194
+ if (msg.type === "error") _optionalChain([callbacks, 'access', _13 => _13.onError, 'optionalCall', _14 => _14()]);
149
195
  this.finalize(callbacks);
150
196
  }
151
197
  });
152
198
  worker.postMessage({ type: "start", payload });
153
199
  }
154
200
  terminate() {
155
- _optionalChain([this, 'access', _11 => _11.worker, 'optionalAccess', _12 => _12.terminate, 'call', _13 => _13()]);
201
+ _optionalChain([this, 'access', _15 => _15.worker, 'optionalAccess', _16 => _16.terminate, 'call', _17 => _17()]);
156
202
  this.worker = null;
157
203
  }
158
204
  isRunning() {
@@ -169,61 +215,6 @@ var WorkerManager = class {
169
215
  }
170
216
  };
171
217
 
172
- // src/core/utils.ts
173
- function buildKey(moduleCode, langCode, store) {
174
- return store.cacheGroupKey ? `${moduleCode}_${langCode}_${store.cacheGroupKey}` : `${moduleCode}_${langCode}`;
175
- }
176
- function flatToNested(flat) {
177
- const result = {};
178
- for (const [key, value] of Object.entries(flat)) {
179
- const parts = key.split(".");
180
- let cur = result;
181
- for (let i = 0; i < parts.length - 1; i++) {
182
- const part = parts[i];
183
- if (typeof cur[part] !== "object" || cur[part] === null) {
184
- cur[part] = {};
185
- }
186
- cur = cur[part];
187
- }
188
- cur[parts[parts.length - 1]] = value;
189
- }
190
- return result;
191
- }
192
- function deepMerge(target, source) {
193
- const result = { ...target };
194
- for (const [key, sv] of Object.entries(source)) {
195
- const tv = result[key];
196
- if (sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv)) {
197
- result[key] = deepMerge(tv, sv);
198
- } else {
199
- result[key] = sv;
200
- }
201
- }
202
- return result;
203
- }
204
- function parseI18nValues(values) {
205
- const result = {};
206
- for (const { termCode, langValue } of values) {
207
- if (termCode && langValue !== void 0) {
208
- result[termCode] = _nullishCoalesce(langValue, () => ( ""));
209
- }
210
- }
211
- return result;
212
- }
213
- function toDefaultParams(p) {
214
- const result = {};
215
- if (_optionalChain([p, 'optionalAccess', _14 => _14.storeName])) result["storeName"] = p.storeName;
216
- if (_optionalChain([p, 'optionalAccess', _15 => _15.langCode])) result["langCode"] = p.langCode;
217
- if (_optionalChain([p, 'optionalAccess', _16 => _16.moduleCode])) result["moduleCode"] = p.moduleCode;
218
- if (_optionalChain([p, 'optionalAccess', _17 => _17.version]) != null) result["version"] = String(p.version);
219
- return result;
220
- }
221
- function toQueryString(params) {
222
- return new URLSearchParams(
223
- Object.entries(params).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])
224
- ).toString();
225
- }
226
-
227
218
  // src/core/manager.ts
228
219
  var PRIORITY_MODULES = ["ENUMS", "CUSTOMER"];
229
220
  var currentLang = "zh_CN";
@@ -316,7 +307,7 @@ async function getResource(moduleCode, langCode) {
316
307
  if (result.status === "rejected") continue;
317
308
  const record = result.value;
318
309
  if (!_optionalChain([record, 'optionalAccess', _18 => _18.resources])) continue;
319
- merged = i === 0 ? deepMerge(merged, record.resources) : deepMerge(merged, flatToNested(record.resources));
310
+ merged = deepMerge(merged, record.resources);
320
311
  }
321
312
  return merged;
322
313
  }
@@ -398,9 +389,8 @@ async function doUnloginPull(storage, options) {
398
389
  let blocks;
399
390
  try {
400
391
  blocks = await doFetch(apiContext.unloginPull, options);
401
- } catch (e4) {
402
- await injectCurrentLanguageModules(currentLang);
403
- await _i18next2.default.changeLanguage(currentLang);
392
+ } catch (err) {
393
+ console.error("[i18n] unloginPull \u8BF7\u6C42\u5931\u8D25\uFF0C\u964D\u7EA7\u9759\u6001\u515C\u5E95", err);
404
394
  emitI18nResourcesUpdated();
405
395
  return;
406
396
  }
@@ -408,10 +398,9 @@ async function doUnloginPull(storage, options) {
408
398
  for (const mod of _nullishCoalesce(block.modules, () => ( []))) {
409
399
  const key = buildKey(mod.moduleCode, block.langCode, baseStore);
410
400
  const existing = await storage.getRecord(baseStore.name, key);
411
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
412
401
  const resources = deepMerge(
413
402
  _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _21 => _21.resources]), () => ( {})),
414
- flatToNested(parsed)
403
+ mod.resources
415
404
  );
416
405
  await storage.putRecord(baseStore.name, {
417
406
  key,
@@ -459,7 +448,13 @@ function runWorker(options, tasks, pull) {
459
448
  },
460
449
  {
461
450
  onRawData: async (task, raw) => {
462
- const blocks = pull.transform ? pull.transform(raw) : raw;
451
+ let blocks;
452
+ try {
453
+ blocks = pull.transform ? pull.transform(raw) : raw;
454
+ } catch (err) {
455
+ console.error("[i18n] pull transform \u5931\u8D25", task, err);
456
+ return;
457
+ }
463
458
  const store = resolvedStores.find((s) => s.name === task.storeName);
464
459
  if (!store) return;
465
460
  const storeIndex = resolvedStores.indexOf(store);
@@ -468,11 +463,7 @@ function runWorker(options, tasks, pull) {
468
463
  const key = buildKey(mod.moduleCode, block.langCode, store);
469
464
  const existing = await storage.getRecord(store.name, key);
470
465
  if (existing && mod.version <= existing.version) continue;
471
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
472
- const resources = storeIndex === 0 ? deepMerge(
473
- _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _22 => _22.resources]), () => ( {})),
474
- flatToNested(parsed)
475
- ) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})), ...parsed };
466
+ const resources = storeIndex === 0 ? deepMerge(_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _22 => _22.resources]), () => ( {})), mod.resources) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _23 => _23.resources]), () => ( {})), ...mod.resources };
476
467
  await storage.putRecord(store.name, {
477
468
  key,
478
469
  moduleCode: mod.moduleCode,
@@ -582,7 +573,7 @@ async function flushPendingSSESyncs(options) {
582
573
  task.moduleCode,
583
574
  task.langCode
584
575
  );
585
- } catch (e5) {
576
+ } catch (e4) {
586
577
  localVersion = 0;
587
578
  }
588
579
  if (task.targetVersion <= localVersion) continue;
@@ -593,7 +584,7 @@ async function flushPendingSSESyncs(options) {
593
584
  await _i18next2.default.changeLanguage(currentLang);
594
585
  emitI18nResourcesUpdated();
595
586
  }
596
- } catch (e6) {
587
+ } catch (e5) {
597
588
  }
598
589
  }
599
590
  } finally {
@@ -618,16 +609,7 @@ async function pullAndStore(task, fromVersion, options) {
618
609
  const key = buildKey(mod.moduleCode, block.langCode, store);
619
610
  const existing = await storage.getRecord(store.name, key);
620
611
  if (mod.version <= (_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _27 => _27.version]), () => ( 0)))) continue;
621
- let resources;
622
- const parsed = parseI18nValues(_nullishCoalesce(mod.i18nValues, () => ( [])));
623
- if (storeIndex === 0) {
624
- resources = deepMerge(
625
- _nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})),
626
- flatToNested(parsed)
627
- );
628
- } else {
629
- resources = { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...parsed };
630
- }
612
+ const resources = storeIndex === 0 ? deepMerge(_nullishCoalesce(_optionalChain([existing, 'optionalAccess', _28 => _28.resources]), () => ( {})), mod.resources) : { ..._nullishCoalesce(_optionalChain([existing, 'optionalAccess', _29 => _29.resources]), () => ( {})), ...mod.resources };
631
613
  const version = Math.max(mod.version, task.targetVersion);
632
614
  await storage.putRecord(store.name, {
633
615
  key,
@@ -684,4 +666,6 @@ async function getStoredVersion(store, moduleCode, langCode) {
684
666
 
685
667
 
686
668
 
687
- exports.I18N_RESOURCES_UPDATED_EVENT = I18N_RESOURCES_UPDATED_EVENT; exports.emitI18nResourcesUpdated = emitI18nResourcesUpdated; exports.createI18nManager = createI18nManager;
669
+
670
+
671
+ exports.I18N_RESOURCES_UPDATED_EVENT = I18N_RESOURCES_UPDATED_EVENT; exports.emitI18nResourcesUpdated = emitI18nResourcesUpdated; exports.flatToNested = flatToNested; exports.deepMerge = deepMerge; exports.createI18nManager = createI18nManager;
package/dist/index.cjs CHANGED
@@ -7,7 +7,9 @@ var _chunkAJJKJPNBcjs = require('./chunk-AJJKJPNB.cjs');
7
7
 
8
8
 
9
9
 
10
- var _chunkDSK7CM4Gcjs = require('./chunk-DSK7CM4G.cjs');
10
+
11
+
12
+ var _chunkT7476FJ4cjs = require('./chunk-T7476FJ4.cjs');
11
13
 
12
14
  // src/index.ts
13
15
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
@@ -180,7 +182,7 @@ if (!_i18next2.default.isInitialized) {
180
182
  }
181
183
  });
182
184
  }
183
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkDSK7CM4Gcjs.createI18nManager.call(void 0, {
185
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
184
186
  storage: new IndexedDBAdapter(),
185
187
  createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
186
188
  new Worker(new URL("./workers/preload-worker.js", import.meta.url), { type: "module" })
@@ -196,4 +198,6 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
196
198
 
197
199
 
198
200
 
199
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunkDSK7CM4Gcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkDSK7CM4Gcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
201
+
202
+
203
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.deepMerge = _chunkT7476FJ4cjs.deepMerge; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.flatToNested = _chunkT7476FJ4cjs.flatToNested; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,22 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CSwgzbob.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-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-DAFvp5or.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-DAFvp5or.cjs';
3
3
  export { u as useDict } from './hooks-ClO29Chr.cjs';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
6
+ /**
7
+ * dot-notation 平铺 key → 嵌套对象
8
+ * "a.b.c" → { a: { b: { c: value } } }
9
+ */
10
+ declare function flatToNested(flat: Record<string, unknown>): Record<string, unknown>;
11
+ /**
12
+ * 深度合并,source 叶节点覆盖 target,数组直接覆盖
13
+ */
14
+ declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
15
+
6
16
  declare const initI18n: typeof initI18n$1;
7
17
  declare const closeSSE: typeof closeSSE$1;
8
18
  declare const ensureModules: typeof ensureModules$1;
9
19
  declare const getResource: typeof getResource$1;
10
20
  declare const getAllRecordsByModule: typeof getAllRecordsByModule$1;
11
21
 
12
- export { closeSSE, ensureModules, getAllRecordsByModule, getResource, initI18n };
22
+ export { closeSSE, deepMerge, ensureModules, flatToNested, getAllRecordsByModule, getResource, initI18n };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
- import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-CSwgzbob.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-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from './cacheEvents-DAFvp5or.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-DAFvp5or.js';
3
3
  export { u as useDict } from './hooks-ClO29Chr.js';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
6
+ /**
7
+ * dot-notation 平铺 key → 嵌套对象
8
+ * "a.b.c" → { a: { b: { c: value } } }
9
+ */
10
+ declare function flatToNested(flat: Record<string, unknown>): Record<string, unknown>;
11
+ /**
12
+ * 深度合并,source 叶节点覆盖 target,数组直接覆盖
13
+ */
14
+ declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
15
+
6
16
  declare const initI18n: typeof initI18n$1;
7
17
  declare const closeSSE: typeof closeSSE$1;
8
18
  declare const ensureModules: typeof ensureModules$1;
9
19
  declare const getResource: typeof getResource$1;
10
20
  declare const getAllRecordsByModule: typeof getAllRecordsByModule$1;
11
21
 
12
- export { closeSSE, ensureModules, getAllRecordsByModule, getResource, initI18n };
22
+ export { closeSSE, deepMerge, ensureModules, flatToNested, getAllRecordsByModule, getResource, initI18n };
package/dist/index.js CHANGED
@@ -6,8 +6,10 @@ import {
6
6
  import {
7
7
  I18N_RESOURCES_UPDATED_EVENT,
8
8
  createI18nManager,
9
- emitI18nResourcesUpdated
10
- } from "./chunk-3ALMQ7Q5.js";
9
+ deepMerge,
10
+ emitI18nResourcesUpdated,
11
+ flatToNested
12
+ } from "./chunk-LZQP6OHB.js";
11
13
 
12
14
  // src/index.ts
13
15
  import i18n from "i18next";
@@ -189,8 +191,10 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
189
191
  export {
190
192
  I18N_RESOURCES_UPDATED_EVENT,
191
193
  closeSSE,
194
+ deepMerge,
192
195
  emitI18nResourcesUpdated,
193
196
  ensureModules,
197
+ flatToNested,
194
198
  getAllRecordsByModule,
195
199
  getResource,
196
200
  initI18n,
package/dist/mp/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkDSK7CM4Gcjs = require('../chunk-DSK7CM4G.cjs');
5
+ var _chunkT7476FJ4cjs = require('../chunk-T7476FJ4.cjs');
6
6
 
7
7
  // src/storage/wx-sqlite.ts
8
8
  var DB_NAME = "i18n_cache";
@@ -181,7 +181,7 @@ function wxFetch(input, init) {
181
181
  }
182
182
 
183
183
  // src/mp/index.ts
184
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkDSK7CM4Gcjs.createI18nManager.call(void 0, {
184
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
185
185
  storage: new WxSQLiteAdapter(),
186
186
  createWorker: () => new WxWorkerAdapter(wx.createWorker("workers/preload-worker-mp.js")),
187
187
  fetchFn: wxFetch
@@ -194,4 +194,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
194
194
 
195
195
 
196
196
 
197
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunkDSK7CM4Gcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkDSK7CM4Gcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
197
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n;
@@ -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-CSwgzbob.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-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.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-DAFvp5or.cjs';
3
3
 
4
4
  declare const initI18n: typeof initI18n$1;
5
5
  declare const closeSSE: typeof closeSSE$1;
@@ -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-CSwgzbob.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-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.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-DAFvp5or.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
@@ -2,7 +2,7 @@ import {
2
2
  I18N_RESOURCES_UPDATED_EVENT,
3
3
  createI18nManager,
4
4
  emitI18nResourcesUpdated
5
- } from "../chunk-3ALMQ7Q5.js";
5
+ } from "../chunk-LZQP6OHB.js";
6
6
 
7
7
  // src/storage/wx-sqlite.ts
8
8
  var DB_NAME = "i18n_cache";
@@ -7,7 +7,7 @@ var _chunkAJJKJPNBcjs = require('../chunk-AJJKJPNB.cjs');
7
7
 
8
8
 
9
9
 
10
- var _chunkDSK7CM4Gcjs = require('../chunk-DSK7CM4G.cjs');
10
+ var _chunkT7476FJ4cjs = require('../chunk-T7476FJ4.cjs');
11
11
 
12
12
  // src/native/index.ts
13
13
  var _i18next = require('i18next'); var _i18next2 = _interopRequireDefault(_i18next);
@@ -121,7 +121,7 @@ if (!_i18next2.default.isInitialized) {
121
121
  }
122
122
  });
123
123
  }
124
- var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkDSK7CM4Gcjs.createI18nManager.call(void 0, {
124
+ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } = _chunkT7476FJ4cjs.createI18nManager.call(void 0, {
125
125
  storage: new SQLiteAdapter(),
126
126
  // Hermes Worker(RN 0.71+),API 与 Web Worker 一致
127
127
  createWorker: () => new (0, _chunkAJJKJPNBcjs.WebWorkerAdapter)(
@@ -138,4 +138,4 @@ var { initI18n, closeSSE, ensureModules, getResource, getAllRecordsByModule } =
138
138
 
139
139
 
140
140
 
141
- exports.I18N_RESOURCES_UPDATED_EVENT = _chunkDSK7CM4Gcjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkDSK7CM4Gcjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
141
+ exports.I18N_RESOURCES_UPDATED_EVENT = _chunkT7476FJ4cjs.I18N_RESOURCES_UPDATED_EVENT; exports.closeSSE = closeSSE; exports.emitI18nResourcesUpdated = _chunkT7476FJ4cjs.emitI18nResourcesUpdated; exports.ensureModules = ensureModules; exports.getAllRecordsByModule = getAllRecordsByModule; exports.getResource = getResource; exports.initI18n = initI18n; exports.useDict = _chunkAJJKJPNBcjs.useDict; exports.useTranslation = _chunkAJJKJPNBcjs.useTranslation;
@@ -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-CSwgzbob.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-CSwgzbob.cjs';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.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-DAFvp5or.cjs';
3
3
  export { u as useDict } from '../hooks-ClO29Chr.cjs';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
@@ -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-CSwgzbob.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-CSwgzbob.js';
1
+ import { c as closeSSE$1, e as ensureModules$1, g as getAllRecordsByModule$1, a as getResource$1, i as initI18n$1 } from '../cacheEvents-DAFvp5or.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-DAFvp5or.js';
3
3
  export { u as useDict } from '../hooks-ClO29Chr.js';
4
4
  export { useTranslation } from 'react-i18next';
5
5
 
@@ -7,7 +7,7 @@ import {
7
7
  I18N_RESOURCES_UPDATED_EVENT,
8
8
  createI18nManager,
9
9
  emitI18nResourcesUpdated
10
- } from "../chunk-3ALMQ7Q5.js";
10
+ } from "../chunk-LZQP6OHB.js";
11
11
 
12
12
  // src/native/index.ts
13
13
  import i18n from "i18next";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuo-li/i18n",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Cross-platform i18n library for Web, React Native and WeChat MiniProgram",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",