From 30404397ac79d0009ca82217aee961ac13e7b99e Mon Sep 17 00:00:00 2001 From: wynterding Date: Mon, 7 Apr 2025 20:47:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:appendmode=20=E4=BC=9A=E5=AF=B9?= =?UTF-8?q?=E9=82=A3=E4=BA=9B=E5=B7=B2=E7=BB=8F=E7=BF=BB=E8=AF=91=E4=BA=86?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E5=81=9A=20append,=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=BF=BB=E8=AF=91=E7=9A=84=E5=86=85=E5=AE=B9=E5=88=99?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E5=BC=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/easy-i18n.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/easy-i18n.js b/src/easy-i18n.js index 7625b4b..5f9ab6d 100644 --- a/src/easy-i18n.js +++ b/src/easy-i18n.js @@ -88,6 +88,16 @@ class EasyI18n { return res; } + pickTranslatedData(data) { + const res = {}; + Object.keys(data).forEach(key => { + if (!this.hasChinese(data[key])) { + res[key] = data[key]; + } + }); + return res; + } + async postResolve() { const { options } = this; this.existedData = this.sortKey(this.existedData); @@ -101,7 +111,8 @@ class EasyI18n { this.debugLog('current data:\n%s\n', JSON.stringify(this.currentData, null, 2)); const outputData = this.sortKey({ ...this.currentData, - ...(options.appendMode ? this.existedData : {}), + // append mode will keep existed translated data + ...(options.appendMode ? this.pickTranslatedData(this.existedData) : {}), }); const newKeys = _.difference(Object.keys(this.currentData), Object.keys(this.existedData)); this.debugLog('new keys:\n%s\n', JSON.stringify(newKeys, null, 2)); From f791dc91b1f373991e331115c4e28542b0b35830 Mon Sep 17 00:00:00 2001 From: wynterding Date: Mon, 7 Apr 2025 20:49:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E9=92=88=E5=AF=B9=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E4=BB=BB=E5=8A=A1=E4=B8=AD=20require=20cache?= =?UTF-8?q?=20=E5=81=9A=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/easy-i18n.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/easy-i18n.js b/src/easy-i18n.js index 5f9ab6d..0fdf468 100644 --- a/src/easy-i18n.js +++ b/src/easy-i18n.js @@ -155,6 +155,7 @@ class EasyI18n { initData() { const { distFile } = this.options; try { + delete require.cache[distFile]; const data = require(distFile); this.existedData = data.default || data; } catch (e) {