i18-fe-automator
Version:
前端代码提取中文并替换成$t函数
32 lines (31 loc) • 949 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.baiduAITranslate = void 0;
const got = require('got');
async function baiduAITranslate(word, originLang, targetLang, option) {
const baseUrl = `https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=${option.access_token}`;
const params = {
from: originLang,
to: targetLang.split('-')[0],
q: word,
};
return new Promise((resolve, reject) => {
got
.post(baseUrl, {
json: params,
})
.then(({ body }) => {
const res = JSON.parse(body);
if (res && res.result && res.result.trans_result) {
resolve(res.result.trans_result);
}
else {
reject(body);
}
})
.catch((e) => {
reject(e);
});
});
}
exports.baiduAITranslate = baiduAITranslate;