Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tant-intl

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tant-intl - npm Package Compare versions

Comparing version 3.0.6 to 3.0.7

86

es/index.js

@@ -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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc