Browse Source

Pull request #3035: KERNEL-12612 fix: FineUI国际化功能增强

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit '22feddf125de2d88077432dc50f6eaf87f3456e0':
  KERNEL-12612 feat: FineUI国际化功能增强
  KERNEL-12612 fix: FineUI国际化功能增强
es6
Dailer 2 years ago
parent
commit
e627edaf5a
  1. 22
      src/core/utils/i18n.js

22
src/core/utils/i18n.js

@ -1,5 +1,8 @@
!(function () { !(function () {
var i18nStore = {}; var i18nStore = {};
var i18nFormatters = {};
BI._.extend(BI, { BI._.extend(BI, {
changeI18n: function (i18n) { changeI18n: function (i18n) {
if (i18n) { if (i18n) {
@ -9,6 +12,7 @@
addI18n: function (i18n) { addI18n: function (i18n) {
BI.extend(i18nStore, i18n); BI.extend(i18nStore, i18n);
}, },
i18nText: function (key) { i18nText: function (key) {
var localeText = i18nStore[key] || (BI.i18n && BI.i18n[key]) || ""; var localeText = i18nStore[key] || (BI.i18n && BI.i18n[key]) || "";
if (!localeText) { if (!localeText) {
@ -16,10 +20,18 @@
} }
var len = arguments.length; var len = arguments.length;
if (len > 1) { if (len > 1) {
if (localeText.indexOf("{R1}") > -1) { if (localeText.indexOf("{R1") > -1) {
for (var i = 1; i < len; i++) { for (var i = 1; i < len; i++) {
var key = "{R" + i + "}"; var reg = new RegExp(`{R${i},(.*?)}`, "g");
localeText = BI.replaceAll(localeText, key, arguments[i] + "");
var result = reg.exec(localeText);
if (result) {
var formatName = result[1];
localeText = BI.replaceAll(localeText, reg, i18nFormatters[formatName](key, arguments[i]));
} else {
localeText = BI.replaceAll(localeText, `{R${i}}`, arguments[i] + "");
}
} }
} else { } else {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
@ -30,6 +42,10 @@
} }
} }
return localeText; return localeText;
},
addI18nFormatter: function (formatName, fn) {
i18nFormatters[formatName] = fn;
} }
}); });
})(); })();

Loading…
Cancel
Save