Comparing version 3.0.6 to 3.0.7
@@ -6,57 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIntlMessage = exports.getLocale = exports.setLocale = exports.formatMessage = void 0; | ||
exports.formatMessage = exports.getIntlMessage = exports.getLocale = exports.setLocale = void 0; | ||
const react_1 = __importDefault(require("react")); | ||
const superagent_1 = __importDefault(require("superagent")); | ||
const intl_messageformat_1 = __importDefault(require("intl-messageformat")); | ||
/** | ||
* 获取链接字符串 | ||
*/ | ||
const getIntlStr = (str, varObj = {}) => { | ||
const commStrs = str.split(/\{[^\{\}]*?\}/); // 将不是变量的部分抽离出来 | ||
const varStrs = []; | ||
str.replace(/\{[^\{\}]*?\}/g, (s) => { | ||
let newS = s.substring(1, s.length - 1); | ||
if (newS) { | ||
if (varObj[newS] == null) { | ||
newS = `{${newS}}`; | ||
} | ||
else { | ||
newS = varObj[newS]; | ||
} | ||
} | ||
varStrs.push(newS); | ||
return ''; | ||
}); | ||
const strs = []; | ||
for (let i = 0; i < commStrs.length; i += 1) { | ||
strs[i * 2] = commStrs[i] || ''; | ||
strs[(i * 2) + 1] = varStrs[i] || ''; | ||
} | ||
return strs; | ||
}; | ||
/** | ||
* 国际化渲染函数 | ||
* @param infoObj | ||
* @param varObj | ||
* @returns | ||
*/ | ||
const formatMessage = (infoObj, varObj) => { | ||
const { id } = infoObj; | ||
const { intl } = window; | ||
if (!intl) { | ||
console.error('本地词汇库为空,请检查!'); | ||
return id; | ||
} | ||
if (!intl[id]) { | ||
console.error(`词汇${id}不存在,请检查!`); | ||
return id; | ||
} | ||
const value = intl ? intl[id] : id; | ||
const strs = getIntlStr(value, varObj); | ||
if (Object.values(varObj || {}).find(item => typeof item === 'object')) { // 对象的属性值为对象时就认为是react对象 | ||
return react_1.default.createElement(react_1.default.Fragment, null, strs); | ||
} | ||
return strs.join(''); | ||
}; | ||
exports.formatMessage = formatMessage; | ||
/** | ||
* 修改语言类型 | ||
@@ -77,3 +27,4 @@ * @param lan | ||
const getLocale = () => { | ||
return window.localStorage.getItem('umi_locale') || 'zh-CN'; | ||
const lan = window.localStorage.getItem('umi_locale') || navigator.language || 'zh'; | ||
return lan.includes('en') ? 'en-US' : lan.includes('ja') ? 'ja-JP' : 'zh-CN'; | ||
}; | ||
@@ -85,3 +36,3 @@ exports.getLocale = getLocale; | ||
const getIntlMessage = async (tags = []) => { | ||
const lan = window.localStorage.getItem('umi_locale') || 'zh-CN'; | ||
const lan = (0, exports.getLocale)(); | ||
const intl = window.intl; | ||
@@ -105,1 +56,28 @@ if (!tags || tags.length === 0) { | ||
exports.getIntlMessage = getIntlMessage; | ||
const lan = (0, exports.getLocale)(); | ||
/** | ||
* 国际化渲染函数 | ||
* @param infoObj | ||
* @param varObj | ||
* @returns | ||
*/ | ||
const formatMessage = (infoObj, varObj) => { | ||
const { id } = infoObj; | ||
const { intl } = window; | ||
if (!intl) { | ||
console.error('本地词汇库为空,请检查!'); | ||
return id; | ||
} | ||
if (intl[id] === null || intl[id] === undefined || intl[id] === NaN) { | ||
console.error(`词汇${id}不存在,请检查!`); | ||
return id; | ||
} | ||
const value = intl ? intl[id] : id; | ||
const intlObj = new intl_messageformat_1.default(value, lan); | ||
const arr = intlObj.formatToParts(varObj).map(v => v.value); | ||
if (arr.find(item => typeof item === 'object')) { // 对象的属性值为对象时就认为是react对象 | ||
return react_1.default.createElement(react_1.default.Fragment, null, arr); | ||
} | ||
return arr.join(''); | ||
}; | ||
exports.formatMessage = formatMessage; |
@@ -51,58 +51,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIntlMessage = exports.getLocale = exports.setLocale = exports.formatMessage = void 0; | ||
exports.formatMessage = exports.getIntlMessage = exports.getLocale = exports.setLocale = void 0; | ||
var react_1 = __importDefault(require("react")); | ||
var superagent_1 = __importDefault(require("superagent")); | ||
var intl_messageformat_1 = __importDefault(require("intl-messageformat")); | ||
/** | ||
* 获取链接字符串 | ||
*/ | ||
var getIntlStr = function (str, varObj) { | ||
if (varObj === void 0) { varObj = {}; } | ||
var commStrs = str.split(/\{[^\{\}]*?\}/); // 将不是变量的部分抽离出来 | ||
var varStrs = []; | ||
str.replace(/\{[^\{\}]*?\}/g, function (s) { | ||
var newS = s.substring(1, s.length - 1); | ||
if (newS) { | ||
if (varObj[newS] == null) { | ||
newS = "{".concat(newS, "}"); | ||
} | ||
else { | ||
newS = varObj[newS]; | ||
} | ||
} | ||
varStrs.push(newS); | ||
return ''; | ||
}); | ||
var strs = []; | ||
for (var i = 0; i < commStrs.length; i += 1) { | ||
strs[i * 2] = commStrs[i] || ''; | ||
strs[(i * 2) + 1] = varStrs[i] || ''; | ||
} | ||
return strs; | ||
}; | ||
/** | ||
* 国际化渲染函数 | ||
* @param infoObj | ||
* @param varObj | ||
* @returns | ||
*/ | ||
var formatMessage = function (infoObj, varObj) { | ||
var id = infoObj.id; | ||
var intl = window.intl; | ||
if (!intl) { | ||
console.error('本地词汇库为空,请检查!'); | ||
return id; | ||
} | ||
if (!intl[id]) { | ||
console.error("\u8BCD\u6C47".concat(id, "\u4E0D\u5B58\u5728\uFF0C\u8BF7\u68C0\u67E5\uFF01")); | ||
return id; | ||
} | ||
var value = intl ? intl[id] : id; | ||
var strs = getIntlStr(value, varObj); | ||
if (Object.values(varObj || {}).find(function (item) { return typeof item === 'object'; })) { // 对象的属性值为对象时就认为是react对象 | ||
return react_1.default.createElement(react_1.default.Fragment, null, strs); | ||
} | ||
return strs.join(''); | ||
}; | ||
exports.formatMessage = formatMessage; | ||
/** | ||
* 修改语言类型 | ||
@@ -123,3 +72,4 @@ * @param lan | ||
var getLocale = function () { | ||
return window.localStorage.getItem('umi_locale') || 'zh-CN'; | ||
var lan = window.localStorage.getItem('umi_locale') || navigator.language || 'zh'; | ||
return lan.includes('en') ? 'en-US' : lan.includes('ja') ? 'ja-JP' : 'zh-CN'; | ||
}; | ||
@@ -137,3 +87,3 @@ exports.getLocale = getLocale; | ||
case 0: | ||
lan = window.localStorage.getItem('umi_locale') || 'zh-CN'; | ||
lan = (0, exports.getLocale)(); | ||
intl = window.intl; | ||
@@ -167,1 +117,28 @@ if (!(!tags || tags.length === 0)) return [3 /*break*/, 2]; | ||
exports.getIntlMessage = getIntlMessage; | ||
var lan = (0, exports.getLocale)(); | ||
/** | ||
* 国际化渲染函数 | ||
* @param infoObj | ||
* @param varObj | ||
* @returns | ||
*/ | ||
var formatMessage = function (infoObj, varObj) { | ||
var id = infoObj.id; | ||
var intl = window.intl; | ||
if (!intl) { | ||
console.error('本地词汇库为空,请检查!'); | ||
return id; | ||
} | ||
if (intl[id] === null || intl[id] === undefined || intl[id] === NaN) { | ||
console.error("\u8BCD\u6C47".concat(id, "\u4E0D\u5B58\u5728\uFF0C\u8BF7\u68C0\u67E5\uFF01")); | ||
return id; | ||
} | ||
var value = intl ? intl[id] : id; | ||
var intlObj = new intl_messageformat_1.default(value, lan); | ||
var arr = intlObj.formatToParts(varObj).map(function (v) { return v.value; }); | ||
if (arr.find(function (item) { return typeof item === 'object'; })) { // 对象的属性值为对象时就认为是react对象 | ||
return react_1.default.createElement(react_1.default.Fragment, null, arr); | ||
} | ||
return arr.join(''); | ||
}; | ||
exports.formatMessage = formatMessage; |
{ | ||
"name": "tant-intl", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"description": "依托于飞书表格做文案管理的多语言组件", | ||
@@ -42,5 +42,7 @@ "main": "es/index.js", | ||
"feishu-excel": "^1.0.4", | ||
"intl-messageformat": "^9.11.4", | ||
"react": "^17.0.2", | ||
"react-intl": "^5.24.6", | ||
"superagent": "^7.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
21036
6
415
+ Addedintl-messageformat@^9.11.4
+ Addedreact-intl@^5.24.6
+ Added@formatjs/ecma402-abstract@1.11.4(transitive)
+ Added@formatjs/fast-memoize@1.2.1(transitive)
+ Added@formatjs/icu-messageformat-parser@2.1.0(transitive)
+ Added@formatjs/icu-skeleton-parser@1.3.6(transitive)
+ Added@formatjs/intl@2.2.1(transitive)
+ Added@formatjs/intl-displaynames@5.4.3(transitive)
+ Added@formatjs/intl-listformat@6.5.3(transitive)
+ Added@formatjs/intl-localematcher@0.2.25(transitive)
+ Added@types/hoist-non-react-statics@3.3.5(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.12(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedhas-proto@1.1.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhoist-non-react-statics@3.3.2(transitive)
+ Addedintl-messageformat@9.13.0(transitive)
+ Addedreact-intl@5.25.1(transitive)
+ Addedreact-is@16.13.1(transitive)
+ Addedtslib@2.8.1(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)