From 14650017da468c247f19eaa9139f39e05de18d84 Mon Sep 17 00:00:00 2001 From: zsmj Date: Thu, 1 Sep 2022 09:49:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-12612=20fix:=20FineUI=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils/i18n.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/utils/i18n.js b/src/core/utils/i18n.js index 9cec7cc48..72f753015 100644 --- a/src/core/utils/i18n.js +++ b/src/core/utils/i18n.js @@ -1,5 +1,8 @@ !(function () { var i18nStore = {}; + + var i18nFormatters = {}; + BI._.extend(BI, { changeI18n: function (i18n) { if (i18n) { @@ -9,6 +12,7 @@ addI18n: function (i18n) { BI.extend(i18nStore, i18n); }, + i18nText: function (key) { var localeText = i18nStore[key] || (BI.i18n && BI.i18n[key]) || ""; if (!localeText) { @@ -16,10 +20,18 @@ } var len = arguments.length; if (len > 1) { - if (localeText.indexOf("{R1}") > -1) { + if (localeText.indexOf("{R1") > -1) { for (var i = 1; i < len; i++) { - var key = "{R" + i + "}"; - localeText = BI.replaceAll(localeText, key, arguments[i] + ""); + var reg = new RegExp(`{R${i},(.*)}`, "g"); + + var result = reg.exec(localeText); + + if (result) { + var formatName = result[1]; + localeText = BI.replaceAll(localeText, reg, i18nFormatters[formatName](arguments[i])); + } else { + localeText = BI.replaceAll(localeText, `{R${i}}`, arguments[i] + ""); + } } } else { var args = Array.prototype.slice.call(arguments); @@ -30,6 +42,10 @@ } } return localeText; + }, + + addI18nFormatter: function (formatName, fn) { + i18nFormatters[formatName] = fn; } }); })(); From 22feddf125de2d88077432dc50f6eaf87f3456e0 Mon Sep 17 00:00:00 2001 From: zsmj Date: Thu, 1 Sep 2022 15:30:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?KERNEL-12612=20feat:=20FineUI=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E5=8A=9F=E8=83=BD=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils/i18n.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/utils/i18n.js b/src/core/utils/i18n.js index 72f753015..8611ec0a9 100644 --- a/src/core/utils/i18n.js +++ b/src/core/utils/i18n.js @@ -22,13 +22,13 @@ if (len > 1) { if (localeText.indexOf("{R1") > -1) { for (var i = 1; i < len; i++) { - var reg = new RegExp(`{R${i},(.*)}`, "g"); + var reg = new RegExp(`{R${i},(.*?)}`, "g"); var result = reg.exec(localeText); if (result) { var formatName = result[1]; - localeText = BI.replaceAll(localeText, reg, i18nFormatters[formatName](arguments[i])); + localeText = BI.replaceAll(localeText, reg, i18nFormatters[formatName](key, arguments[i])); } else { localeText = BI.replaceAll(localeText, `{R${i}}`, arguments[i] + ""); }